The first challenge is making a code which can encode hex string into base64 string.

Here is base64 encoding method.

One block of base64 encoding is 3bytes.

Only thing we need to do is dividing 3bytes into four blocks of six bits and convert each of them using the Base64 index table shown below.

If we need to pad some bits to make a block of six bits, bit '0' is padded.

If we need to pad some blocks of six bits, simply one or two '=' is padded to base64 string.

Below tables are showing the padding method.

I think I don't need to make my own b64 encode/decode function because I can use python2's base64 module!

Instead, here is how to use the module.

>>> import base64 as b
>>> b.b64encode('49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'.decode('hex'))
'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t'
>>> b.b64decode('SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t').encode('hex')
'49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'


#### 'The Cryptopals Crypto Challenges' 카테고리의 다른 글

Single-byte XOR cipher  (9) 2018.10.14 2018.10.13 2018.10.12