-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathforbidden_love.py
52 lines (38 loc) · 1.11 KB
/
forbidden_love.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
48
49
50
51
52
from typing import Tuple
MATRIX = [
['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'],
['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';'],
['Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '-'],
]
def find(c: chr) -> Tuple[int, int]:
for i, row in enumerate(MATRIX):
try:
j = row.index(c)
return i, j
except ValueError:
pass
def decrypt(x, y, message) -> str:
result = str()
for c in message:
if c != ' ':
a, b = find(c)
result += MATRIX[(a + x) % len(MATRIX)][(b + y) % len(MATRIX[0])]
else:
result += ' '
return result
def solve_case() -> str:
who = input().strip()
message = input().strip()
a, b = find(who)
x, y = find(message[-1])
x_offset = a - x
y_offset = b - y
return decrypt(x_offset, y_offset, message)
def main():
n = int(input())
mapping = map(lambda i: (solve_case(), i + 1), range(n))
for result, i in mapping:
print(f'Case #{i}: {result}')
if __name__ == '__main__':
main()