-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesar.py
47 lines (37 loc) · 1.18 KB
/
caesar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from asciimatics import screen
alphas = [
"abcdefghijklmnopqrstuvwxyz",
"aąbcćdeęfghijklłmnńoópqrsśtuvwxyzżź",
"aąbcćdeęfghijklłmnńoóprsśtuwyzżź",
]
cypher = input()
def main(scr: screen.Screen):
offset = 0
def get_rotated(ctext: str, alpha: str, ofs: int):
ptext = ""
for c in ctext:
try:
ptext += alpha[(alpha.index(c) + ofs) % len(alpha)]
except ValueError:
ptext += c
return ptext
while True:
scr.wait_for_input(1)
ev: screen.KeyboardEvent = scr.get_event()
if not isinstance(ev, screen.KeyboardEvent):
continue
scr.print_at(f"{offset:3}", 0, 0)
scr.print_at(cypher, 0, 1)
for aidx, alpha in enumerate(alphas):
scr.print_at(get_rotated(cypher, alpha, offset), 0, aidx + 3)
scr.refresh()
if ev.key_code == scr.KEY_ESCAPE:
break
if ev.key_code in [scr.KEY_LEFT, scr.KEY_UP]:
offset -= 1
if ev.key_code in [scr.KEY_RIGHT, scr.KEY_DOWN]:
offset += 1
try:
screen.Screen.wrapper(main, height=20)
except KeyboardInterrupt:
...