Created
September 19, 2015 00:02
-
-
Save sean-smith/486377ed7fa26a79f108 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Sean Smith | |
cs 558 | |
""" | |
""" | |
Problem 1 | |
cipher = list("THVVWCZTQ! CZ WECQ YIAQQ, LFN JCII IVAHZ WEV DCPPVHVZYV MVWJVVZ VZYHLOWCFZ AZD ANWEVZWCYAWCFZ. WECQ RVQQATV CQ VZYHLOWVD JCWE A BVHL CZQVYNHV VZYHLOWCFZ QYEVRV. CDVAIIL, AZ VZYHLOWCFZ QYEVRV QEFNID AIIFJ FZIL ANWEFHCGVD OAHWCVQ, JEF XZFJ WEV XVL, WF HVAD WEV RVQQATV. EFJVBVH, LFN SNQW HVAD WEV RVQQATV JCWEFNW XZFJCZT WEV XVL. EVZYV, WEV VZYHLOWCFZ QYEVRV CQ CZQVYNHV.".lower()) | |
replacement_dict = {"a": "A", "b": "v", "c": "i", "d": "D", "e": "h", "f": "o", "g": "z", "h": "r", "i" : "l", "j": "w", "k": "k", "l": "y", "m": "b", "n": "u", "o": "p", "p": "f", "q": "s", "r": "m", "s": "j", "t": "g", "u": "u", "v": "e", "w": "t", "x": "k", "y": "c", "z": "n"} | |
string = "" | |
for i in range(len(cipher)): | |
old_letter = cipher[i] | |
if not old_letter in [" ", "!", ",", "."]: | |
if replacement_dict[old_letter] != old_letter: | |
cipher[i] = replacement_dict[old_letter].upper() | |
string += cipher[i] | |
print(string) | |
Problem 2 | |
""" | |
""" | |
cipher = list("Z LUNI R HLWED XBSX FRY VEP XBAW EENASE ACDP IMMW YG EHV PZZY GYK XBW XIYY EIRRCFK FJ CLW TVYWH. 'NI BGPU XBWWV XLMXYW NG FV WYDJ VZCVIEX, NZEK EFD QVR UJI TVYSXVH YIYRP' -GDO ".lower()) | |
otp = list("abcde") | |
""" | |
def decode(cipher, otp): | |
cipher = list(cipher.lower()) | |
otp = list(otp.lower()) | |
counter = 0 | |
decoded = "" | |
for each in cipher: | |
if not each in [" ", "!", ",", "."]: | |
decoded += chr((abs((ord(each)-97) - (ord(otp[counter % len(otp)])-97))%26)+97) | |
print(decoded) | |
counter +=1 | |
return decoded | |
def encode(message, otp): | |
cipher = list(message.lower()) | |
otp = list(otp.lower()) | |
counter = 0 | |
encoded = "" | |
for each in cipher: | |
if not each in [" ", "!", ",", "."]: | |
encoded += chr(abs((ord(each)-97) + (ord(otp[counter % len(otp)])-97))%26+97) | |
print(encoded) | |
counter +=1 | |
return encoded | |
#print(decode("Z LUNI R HLWED XBSX FRY VEP XBAW EENASE ACDP IMMW YG EHV PZZY GYK XBW XIYY EIRRCFK FJ CLW TVYWH. 'NI BGPU XBWWV XLMXYW NG FV WYDJ VZCVIEX, NZEK EFD QVR UJI TVYSXVH YIYRP' -GDO ", "bcedf")) | |
# | |
print(encode("secretmessage", "cijthuuhmlfru")) | |
print(decode("umlklngledfxy", "cijthuuhmlfru")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment