-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathafindecoder.py
executable file
·55 lines (29 loc) · 969 Bytes
/
afindecoder.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
53
54
55
#!/usr/bin/python3
#_*_utf-8_*_
from math import gcd
from sys import argv
def ayuda():
print("Uso: ./afindecoder.py <codigo_cifrado> <abecedario>")
#codigo a descifrar, abcedario, num_elementos del abecedario
def descifrar(code, abc, elem, a, b):
code_descif=[]
for i in code:
ind = int(abc.index(i))
ind_orig=int( (ind-b)*pow(a, -1, elem) % elem )
code_descif.append(abc[ind_orig])
return "".join(code_descif)
#BUCLE PPAL____________________________________________________________________
if __name__=="__main__":
abcedario=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
try:
codigo=argv[1]
except:
ayuda()
exit(-1)
n_elem=len(abcedario)
for a in range(0, n_elem+1):
if (gcd(a, n_elem)==1):
for b in range(0,n_elem+1):
print(descifrar(codigo, abcedario, n_elem, a, b) + " -> a=" + str(a) + ", b=" + str(b))
print("")