I have been meaning to get better at python. I really like it but i find that it’s so long between each time I use it that i essentially have to re-learn it over and over again. This hasn’t really been a roadblock for me because python is super easy, but i’ve decided I want it to be a regular tool in my toolbox.
That being said, I’ve decided to do all the Cryptopals challenges in python!
I have been meaning to do these for quite some time, however, life just kept getting in the way. I still have limited time, but I’m dedicating a few hours a week to working on them.
I’m not trying to write the most elegant or “pythonic” code. My intentions while doing these challenges is to write code that is easy for me to reason about. It’s likely going to be verbose as well since i like to log things often at various steps so the way my code is written will typically reflect that.
Challenge 1-1 Convert hex to base64
- Link: Cryptopals 1-1
- Resources: Base64 - Implementations_and_history
- Execution:
python convert.py
The string:
|
|
Should produce:
|
|
So go ahead and make that happen. You’ll need to use this code for the rest of the exercises.
Cryptopals Rule
Always operate on raw bytes, never on encoded strings. Only use hex and base64 for pretty-printing.
Solution
Challenge 1-1 doesn’t really need much explanation. We’re just base 64 encoding a string and comparing it’s value against the expected value.
Full code:
|
|
Which yields the following output:
|
|