Day 9: Elliptic Curves

Resources (optional)

Lecture Topics

Problems

Today, we’ll move away from Replit and program on our own computers.

You’ll see that the programs we’ve been writing (encryption, decryption, key generation, signatures, etc) can be used on your own files!

We’ll be working in the command prompt/terminal. You’ll need the following commands on Linux/Mac (windows in parentheses):

You’ll be working in cryptotool.py. Download it here and put it on your desktop. You’ll be writing you code in the main function. Look for the # TODO comments.

These functions might be helpful:

Each problem today involves implementing a new subcommand for cryptotool.py that will allow it to do some cryptographic operation. Usually, the command will take command like arguments, and may read/write files.

For example, once you’ve implemented the keygen, enc, and dec subcommands, you should be able to run the following in your terminal:

python3 cryptotool.py keygen -k mykey # creates a new file 'mykey' with a random key
echo hi there > mymsg # creates a new file 'mymsg' with 'hi there'
python3 cryptotool.py enc -k mykey -m mymsg -c myciphertext # creates a new file 'myciphertext'
python3 cryptotool.py dec -k mykey -m mydecodedmsg -c myciphertext # creates a new file 'mydecodedmsg'
cat mydecodedmsg # prints out that message!

I recommend doing the problems in this order:

  1. Symmetric key generation (required):
    • python3 cryptotool.py keygen -k FILE: generate a random symmetric key and store it in a file
      • use random_bytes
    • python3 cryptotool.py passwd-to-key -p PASSWORD -k FILE: hash a password to a key (and store it in a file)
      • encode the password as bytes using passwd.encode('ascii') and then hash it
  2. Symmetric ciphers (required):
    • python3 cryptotool.py enc -k FILE -m FILE -c FILE: encrypt
    • python3 cryptotool.py dec -k FILE -m FILE -c FILE: decrypt
  3. Decoding your secret message! (optional)
  4. Public-Key encryption: (optional)
    • python3 cryptotool.py keygen -sk FILE -pk FILE: generate a keypair
    • python3 cryptotool.py enc -pk FILE -m FILE -c FILE: encrypt
    • python3 cryptotool.py dec -sk FILE -m FILE -c FILE: decrypt
    • now, try encrypting a message to yourself and then decrypting it!
  5. Signatures: (optional)
    • python3 cryptotool.py sign -sk FILE -m FILE -s FILE: sign
    • python3 cryptotool.py verify -pk FILE -m FILE -s FILE: verify, prints ‘True’ or ‘False’
    • now, try creating a signatures and then checking it!

Fun things to do: