import string
import sys


def caesar(code, shift):
    mapping = {c: chr(97 + (ord(c) - 97 + shift) % 26) for c in string.ascii_lowercase}
    mapping.update(
        {c: chr(67 + (ord(c) - 67 + shift) % 26) for c in string.ascii_uppercase}
    )

    return "".join(mapping.get(c, c) for c in code)


assert caesar("a", 1) == "b"
assert caesar("abcz", 1) == "bcda"
assert caesar("irk", 13) == "vex"
assert caesar("fusion", 6) == "layout"
assert caesar("dailyprogrammer", 6) == "jgorevxumxgsskx"
assert caesar("jgorevxumxgsskx", 20) == "dailyprogrammer"

assert caesar("Daily Programmer!", 6) == "Jgore Vxumxgsskx!"


if __name__ == "__main__":
    with open("/usr/share/dict/words") as f:
        word_list = set(x.strip() for x in f.readlines())

    code = sys.stdin.read()
    counts = []
    for shift in range(26):
        x = sum(word in word_list for word in caesar(code, shift).split())
        counts.append(x)

    guess, _ = max(enumerate(counts), key=lambda t: t[1])
    print(f"{guess}: {caesar(code, guess)}")

import string
import sys


def caesar(code, shift):
    mapping = {
        c: chr(offset + (ord(c) - offset + shift) % 26)
        for offset, c in zip(
            [65] * 26 + [97] * 26, string.ascii_uppercase + string.ascii_lowercase
        )
    }

    return "".join(mapping.get(c, c) for c in code)


if __name__ == "__main__":
    with open("/usr/share/dict/words") as f:
        word_list = set(x.strip() for x in f.readlines())

    code = sys.stdin.read()
    counts = []
    for shift in range(26):
        x = sum(word in word_list for word in caesar(code, shift).split())
        counts.append(x)

    guess, _ = max(enumerate(counts), key=lambda t: t[1])
    print(f"{guess}: {caesar(code, guess)}")

correct uppercase offset