-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher.py
More file actions
25 lines (22 loc) · 789 Bytes
/
cipher.py
File metadata and controls
25 lines (22 loc) · 789 Bytes
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
import itertools
def get_password(cipher_grille, ciphered_password):
flat_grille = [True if j == 'X' else False
for i in cipher_grille
for j in i]
flat_password = [j for i in ciphered_password for j in i]
return ''.join(itertools.compress(flat_password, flat_grille))
def recall_password(cipher_grille, ciphered_password):
password = ''
for i in range(4):
password += get_password(cipher_grille, ciphered_password)
cipher_grille = list(map(lambda x: ''.join(x), zip(*cipher_grille[::-1])))
return password
print(recall_password(
('X...',
'..X.',
'X..X',
'....'),
('itdf',
'gdce',
'aton',
'qrdi'))) #== 'icantforgetiddqd', 'First example'