シーザー暗号
解き方
this、that、theのいずれかの単語が必ず含まれているので、どの単語が含まれているのかを見つける。 見つけ出したあとはその単語ともとに復号していく。
コード(python)
import string strings = string.ascii_lowercase clues = [(19, 7, 8, 18), (19, 7, 0, 19), (19, 7, 4)] while True: try: data = input() except: break for word in data.split(): if len(word) == 4 or 3: dif = 19 - (ord(word[0]) - 97) enc = ["" for _ in range(26)] for k, v in zip([i for i in range(dif, dif+26)], strings): enc[k%26] = v candidate = tuple(enc.index(c) for c in word) try: clues.index(candidate) except: continue break ans = "" for c in data: try: ans += strings[enc.index(c)] except: ans = ans + "." if c == "." else ans + " " print(ans)
めっちゃコードが長くなってしまった。ほかの人のコードを見るとこれよりもかなり短いコードで書いていた。 あらためて、自分はプログラミングは向いていない、才能がないと感じる。