-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolver.py
49 lines (40 loc) · 1.71 KB
/
Solver.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
import CaesarCipher as c
import Atbash as a
import AsciiValues as av
import Base64Solver as b
def try_solve(text, allTests, caesar, RSA, base64, atbash, ascii):
solved = []
text_type = input_is_num_or_hex(text) # to avoid redundant checks i.e. testing a number for caesar shifts
if text_type == "s" or text_type == "h": # we have to test string ciphers for hex to because it is possible that
# a hex valid string is also a valid cipher text sadly
if caesar or allTests:
solved.append(c.solveCaesarCipher(text))
if atbash or allTests:
solved.append(a.solveAtbashCipher(text))
if ascii or allTests:
solved.append(av.solveAsciiValues(text, text_type))
if base64 or allTests:
solved.append(b.solvebase64values(text))
# if len(solved) == 0:
#print("""\n \tWe couldn't solve %s :( We may not currently support the ciphertype that encrypts your message,
#or the translated message may not have appeared in our dictionary. If this is the case, you can check all of the
#output above to check if your solution was generated.""" % text)
print("""\n\n\tAll likely solutions to the inputted text:
________________________________________________
""")
for s in solved:
print("\t" + str(s))
print("________________________________________________")
def input_is_num_or_hex(text):
text = text.split(" ")
try:
for t in text:
t = int(t, 10)
return "n"
except ValueError:
try:
for h in text:
h = int(h, 16)
return "h"
except ValueError:
return "s"