Last active
August 29, 2015 14:13
-
-
Save unix-beard/bd57485bdfd08c17ec5e to your computer and use it in GitHub Desktop.
Convert hex to base64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
######################################################## | |
# the matasano crypto challenges | |
# http://cryptopals.com/sets/1/challenges/1/ | |
######################################################## | |
from base64 import b64encode | |
from itertools import zip_longest | |
s = b'49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d' | |
# Will produce 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t' | |
print(b64encode(bytes(''.join([chr(int(chr(el[0]) + chr(el[1]), base=16)) for el in zip_longest(s[::2], s[1::2])]), 'utf-8')).decode('utf-8')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment