s = "test message"
s[0]
s.find("s")
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
code_alpha = "QWERTYUIOPASDFGHJKLZXCVBNM"
alphabet.find("C")
code_alpha[2]
len(alphabet)
[n^2 for n in range(10)]
def sub_encipher(plaintext):
return [code_alpha[alphabet.find(c)] for c in plaintext]
"".join(sub_encipher("HELLOTHEBESTTHINGINTHEWORLD"))
def sub_decipher(ciphertext):
return [alphabet[code_alpha.find(c)]\
for c in ciphertext]
"".join(sub_decipher('ITSSGZITWTLZZIOFUOFZITVGKSR'))
Challenge: make a cipher that shifts each letter by 3 places in the alphabet, wrapping around at the end of the element
def shift3_encipher(plaintext):
return [alphabet[(alphabet.find(c)+3) % 26]\
for c in plaintext]
shift3_encipher("HELLOZ")
def shift_encipher(plaintext, key):
return [alphabet[(alphabet.find(c)+key) % 26]\
for c in plaintext]
"".join(shift_encipher("HELLOZ",3))
shift_encipher('KHOORC',-2)
factorial(26)
random()
random?
randint(1,5)
randint(0,25)