-
Notifications
You must be signed in to change notification settings - Fork 0
/
Caesar_Salad.py
45 lines (35 loc) · 1.01 KB
/
Caesar_Salad.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
#!/usr/bin/python3
# RUN WITH PYTHON 3 #
def main():
print('''
[!] Caesar Solver by FYI-PSA
[-] version 1.0
''')
ciphertext = input('[#] Enter ciphertext: ')
solved = solveall(ciphertext)
print('\n')
for index, item in enumerate(solved):
print('[%02d] - %s' % (index, item, ))
print('\n[$] Done!\n')
exit(0)
def solveall(ciphertext: str) -> list:
solved = [solve(key, ciphertext) for key in range(0, 26)]
return solved
def solve(shift: int, ciphertext: str) -> str:
solved = ''
for letter in ciphertext:
if not letter.isalpha():
solved = solved + letter
continue
base = ord('A')
if letter.islower():
base = ord('a')
index = ord(letter) - base
changedindex = index + shift
if changedindex >= 26:
changedindex = changedindex - 26
newchar = chr(base + changedindex)
solved = solved + newchar
return solved
if __name__ == '__main__':
main()