These are my solutions to the Cryptopals Challenges.
This is a set of 48 practical programming problems that give you a hands-on crash course in understanding (and breaking) cryptographic ciphers. The problems are fun to do, and (most importantly) do-able. An excellent introduction can be found in Maciej Ceglowski's blog post.
The exercises are bundled in 8 sets:
- Basics (1-8)
- Block crypto (9-16)
- Block and stream crypto (17-24)
- Stream crypto and randomness (25-32)
- Diffie-Hellmann and friends (33-40)
- RSA and DSA (41-48)
- Hashes (49-56)
- Abstract Algebra (57-66)
Python 3.10 or later.
Run pip install -r requirements.txt
or do a conda install of packages listed in requirements.txt.
Many solutions have doctests. To run them all, run
python -m doctest challenge_*.py --verbose
I ran all code through ruff
and black
. I generally also used typehints. Mypy didn't complain.
The typehints may sometimes be a bit unwieldy since I often couldn't decide if I wanted bytes or string
or integers as arguments, which would then lead to "Oh, what the heck, let's support them all."