Last active
March 25, 2020 11:15
-
-
Save spdskatr/01f5f4981956e54310d22b3b3918b04b 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
alphabet = "abcdefghijklmnopqrstuvwxyz" | |
syllables = "ing er a ly ed i es re tion in e con y ter ex al de com o di en an ty ry u ti ri be per to pro ac ad ar ers ment or tions ble der ma na si un at dis ca cal man ap po sion vi el est la lar pa ture for is mer pe ra so ta as col fi ful get low ni par son tle day ny pen pre tive car ci mo an aus pi se ten tor ver ber can dy et it mu no ple cu fac fer gen ic land light ob of pos tain den ings mag ments set some sub sur ters tu af au cy fa im li lo men min mon op out rec ro sen side tal tic ties ward age ba but cit cle co cov daq dif ence ern eve ies ket lec main mar mis my nal ness ning n't nu oc pres sup te ted tem tim tri tro up" | |
def caesar_decipher(text): | |
text = text.lower() | |
results = [] # Item 0 is score, item 1 is text | |
for i in range(26): # Decode ciphertext, then record number of commonly used syllables present, favouring longer syllables | |
decoded = "".join([(alphabet[i:] + alphabet[:i])[alphabet.index(c)] if c in alphabet else c for c in text]) | |
score = sum(decoded.count(s) * 2 ** len(s) for s in syllables.split(' ')) | |
results.append((score, decoded, i)) # Keep track of max | |
results.sort() | |
results = list(reversed(results)) | |
for res in results: | |
print(res[2], "".join(res[1])) | |
caesar_decipher(input("> ")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment