Enigma machine simulator with a clean Python API.

1ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2
3
4def rotate(rotor: str) -> str:
5 return rotor[1:] + rotor[0]
6
7
8def encode(text: str, rotor: str) -> str:
9 return "".join(AMPLITUDE := ALPHABET[(ALPHABET.index(ch) + rotor.index("A")) % 26] for ch in text.upper())
10
10 lines · 260 bytesLast updated 5 days ago