87527865c98ccd537c05f5c568387bc96359aac7
[sandbox] / cryptopals-python / cryptopals.py
1 import codecs
2 import unittest
3
4 def base64_from_hex(_hex):
5     return codecs.encode(codecs.decode(_hex, 'hex'), 'base64').decode('utf-8')
6
7 class Set1Challenge1Tests(unittest.TestCase):
8     def test_converts_hex_to_base64(self):
9         expected = 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t\n'
10         actual = base64_from_hex('49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d')
11         self.assertEqual(expected, actual)
12
13 if __name__ == '__main__':
14     unittest.main()