-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler59.py
99 lines (76 loc) · 1.59 KB
/
euler59.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
ls=[]
f=open('words.txt')
a=f.readline()
while a!='':
ls.append(a[:-2])
a=f.readline()
f.close()
f=open('cipher1.txt')
cipher=f.read()
cipher=cipher.split(",")
f.close()
cipher1=[]
cipher2=[]
cipher3=[]
for i in range(0,len(cipher),3):
cipher1.append(cipher[i])
for i in range(1,len(cipher),3):
cipher2.append(cipher[i])
for i in range(2,len(cipher),3):
cipher3.append(cipher[i])
from collections import Counter
cipher1=Counter(cipher1).most_common()[:4]
cipher2=Counter(cipher2).most_common()[:4]
cipher3=Counter(cipher3).most_common()[:4]
import math
read=''
order=[103,111,100]
key="god"
def xor(a,b):
a=makebinary(a)
b=makebinary(b)
if len(a)!=len(b):
while len(a)>len(b):
b.append(0)
while len(b)>len(a):
a.append(0)
ls=[]
for i in range(len(a)):
if a[i]+b[i]==1:
ls.append(1)
else:
ls.append(0)
return makenumber(ls)
def makenumber(n):
a=0
for i in range(len(n)):
a= a + n[i]*(2**i)
return a
def makebinary(n):
if n==0:
return [0]
elif n==[]:
return []
c=[]
b =int(math.log(n)/math.log(2))
d= divideby2s (n,b,c)
return d
def divideby2s (n,b,c):
if b == -1:
return c
else:
d = n/2**b
n = n%2**b
c= [d] + c
b = b-1
return divideby2s(n,b,c)
for x in cipher:
z=xor(int(x),order[0])
read+=str(chr(z))
order.append(order.pop(0))
order=[103,111,100]
total=0
for x in cipher:
z==xor(int(x),order[0])
total+=z
order.append(order.pop(0))