



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Today ...
A simple example is rot
Usually, the subsitution is given by a key
Creating a Substitution Cipher
Write a substitution encrypt(message, key) function
def substitution_encrypt(message, alpha, key): cipher = "" for ch in message: if ch in alpha: cipher += key[alpha.find(ch)] else: cipher += ch return cipher
Q: Can we use this same function to decrypt?
A more common approach is to use passwords to generate keys
The basic idea:
Combining a password and alphabet
Typically consider all printable characters ...
def generate_alpha(): alpha = "" for x in range(32, 127): # printable from 32 to 126 alpha += chr(x) return alpha