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
| ciphertext = "<<concatanted>>"
password = "KSVVW BGSJD SVSIS VXBMN YQUUK BNWCU ANMJS"
order = ['E','Q','T','S','O','R','I','N','H','C','L','D','U','P','M','F','W','G','Y','B','K','V','X','Q','J','Z']
def letter_order(string):
counts = [0]*26
order = ""
for i in string:
c = ord(i.upper()) - 65
if -1 < c < 26:
counts[c] += 1
for i in range(26):
m = (0,0)
for j in range(26):
if counts[j] > m[1]:
m = (j,counts[j])
counts[m[0]] = 0
order += chr(65+m[0])
return order
def genkeys(order):
if len(order) == 0:
return [""]
keys = []
for i in range(len(order[0])):
if len(order[0]) > 1:
neworder = [order[0][0:i] + order[0][i+1:]] + order[1:]
else:
neworder = order[1:]
for j in genkeys(neworder):
keys.append(order[0][i]+j)
return keys
def solve(s,orig,ceasar):
solved = ""
for i in s:
if 64 < ord(i.upper()) < 91:
solved += orig[ceasar.find(i.upper())]
return solved
cipherorder = letter_order(ciphertext)
for i in genkeys(order):
print(i)
print(cipherorder)
print(solve(password, i, cipherorder))
|