Skip to content

Instantly share code, notes, and snippets.

@sean-smith
Created September 19, 2015 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sean-smith/486377ed7fa26a79f108 to your computer and use it in GitHub Desktop.
Save sean-smith/486377ed7fa26a79f108 to your computer and use it in GitHub Desktop.
"""
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)
print
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