forked from kh3dron/CTF-Pocket-Sand
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrail_fence.py
46 lines (36 loc) · 994 Bytes
/
rail_fence.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
with open('ciphertext.txt') as f:
ciphertext = f.read()
def identifyMessageCase(text):
lower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
check = 0
completed = False
while not completed:
if text[check] in lower:
return lower
elif text[check] in upper:
return upper
else:
check += 1
clearText = identifyMessageCase(ciphertext)
def railFence(text):
top, bottom = "", "" #never knew I could do this
tick = 1
for x in text:
if x in clearText:
if (tick % 2 == 1):
top += x
else:
bottom += x
tick += 1
return top + bottom
def spaceByFives(text):
modified = ""
tock = 0
for x in text:
if ((tock % 5) == 0) & (tock > 1): #skip the first time
modified += " "
modified += x
tock += 1
return modified
print spaceByFives(railFence(ciphertext))