-
Notifications
You must be signed in to change notification settings - Fork 1
/
railfence.py
106 lines (90 loc) 路 2.69 KB
/
railfence.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
100
101
102
103
104
105
106
'''
Author : AjayBadrinath
will document this soon for future audit purposes
'''
def railfence(st,key):
l=2*key-2
j=0
s1=""
m=0
for i in range(key):
m=i
s1+=st[m]
while m<len(st):
print(m)
try:
#s1+=st[m]
if(l==0):
m+=j
s1+=st[m]
continue
m+=l
s1+=st[m]
if(j==0):
m+=l
s1+=st[m]
continue
m+=j
s1+=st[m]
except Exception:
break
j+=2
l-=2
return s1
x1=railfence("theyareattackingfromthenorth",4)
i=0
print(x1)
'''
#crappy bruteforcing
while x1!="defendtheeastwall":
=======
#crappy bruteforcing you just need any cipher text to bruteforce
while x1!="wearediscoveredrunatonce":
>>>>>>> d3068faa6351a971488fe9e7e85ff2463c7dc29e
x1=railfence(x1,4)
print(x1)
print(i)
i+=1
'''
def decrypt(stt_cipher,key):
l1=["" for i in range(len(stt_cipher))]
# 0-len(x) 2-len-2 4 - len-k
l=2*(key-1)
j=0
m=0
i=0
ol_val=0
for w in range(key):
m=ol_val
l1[m]=stt_cipher[i]
i+=1
while m<len(stt_cipher):
#print(stt_cipher[i])
try:
#s1+=st[m]
if(l==0):
m+=j
l1[m]=stt_cipher[i]
i+=1
continue
if(j==0):
m+=l
l1[m]=stt_cipher[i]
i+=1
continue
m+=l
l1[m]=stt_cipher[i]
i+=1
m+=j
l1[m]+=stt_cipher[i]
i+=1
except Exception:
break
j+=2
ol_val+=1
l-=2
s=""
s=s.join(l1)
print(s)
#decrypt("dnetleedheswlftaa",3)
decrypt("tekoohracirmnreatanftetytghh",4)