forked from DemonStarAlgol/CTF_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
仿射密码_爆破模数.py
38 lines (32 loc) · 796 Bytes
/
仿射密码_爆破模数.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
import string
letters = string.ascii_letters
def ext_euclid(a, m):
if m == 0:
return 1, 0
else:
x, y = ext_euclid(m, a % m)
x, y = y, (x - (a // m) * y)
return x,y
def decode(encodes, a, b, n):
decode_str = ''
x = ext_euclid(a,n)
a = x[0]
if a < 0:
a = a + n
for s in encodes:
if s in letters:
z = letters.find(s) % n
y = a * (z - b) % n
if s.isupper():
y += n
decode_str += letters[y]
else:
decode_str += s
return decode_str
if __name__ == '__main__':
s = 'oelb{6d332l0-22ck-2b1n-a35i-125f3qe125l1}'
a = 146442
b = 428428
for i in range(1,26):
d = decode(s, a, b, i)
print ("模数:",i , d)