-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (72 loc) · 2.86 KB
/
main.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
#!/usr/bin/python3
from art import text2art
import string
def engBruteforceDecrypt(enc_string):
LettersAndDigits = string.ascii_letters + string.digits + string.punctuation # lowercase and uppercase eng aphabet + spec. symbols
print("ROT RIGHT") # Shift right(exp. +i shifts)
for shift in range(len(LettersAndDigits)):
encoded = ""
for i in enc_string:
if i in LettersAndDigits:
pos = LettersAndDigits.find(i)
pos -= shift
if pos < 0:
pos += len(LettersAndDigits)
encoded += LettersAndDigits[pos]
else:
encoded += i
print(f"Shift {shift}: {encoded}")
print("ROT LEFT")# Shift left(exp. -i shifts)
for shift in range(len(LettersAndDigits)):
encoded = ""
for i in enc_string:
if i in LettersAndDigits:
pos = LettersAndDigits.find(i)
pos += shift
if pos < 0:
pos -= len(LettersAndDigits)
encoded += LettersAndDigits[pos]
else:
encoded -= i
print(f"Shift {shift}: {encoded}")
def rusBruteforceDecrypt(enc_string):
LettersAndDigits = "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ" # russian alphabet
print("ROT RIGHT")
for shift in range(len(LettersAndDigits)):
encoded = ""
for i in enc_string:
if i in LettersAndDigits:
pos = LettersAndDigits.find(i)
pos -= shift
if pos < 0:
pos += len(LettersAndDigits)
encoded += LettersAndDigits[pos]
else:
encoded += i
print(f"Shift {shift}: {encoded}")
print("ROT LEFT")
for shift in range(len(LettersAndDigits)):
encoded = ""
for i in enc_string:
if i in LettersAndDigits:
pos = LettersAndDigits.find(i)
pos += shift
if pos < 0:
pos -= len(LettersAndDigits)
encoded += LettersAndDigits[pos]
else:
encoded -= i
print(f"Shift {shift}: {encoded}")
if __name__ == '__main__':
print(text2art("Caesar cipher decoder"))
inputLang = input("RUS(1) or ENG(2) string: ")
while True:
if inputLang in ("1" or "rus" or "RUS"):
inputString = input("Input string: ")
rusBruteforceDecrypt(inputString)
elif inputLang in ("2" or "eng" or "ENG"):
inputString = input("Input string: ")
engBruteforceDecrypt(inputString)
else:
print("Incorrect input")
inputLang = input("RUS(1) or ENG(2) string: ")