-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAtbash.py
45 lines (36 loc) · 1.34 KB
/
Atbash.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
import enchant
def solveAtbashCipher(text):
dictionary = enchant.Dict("en_US")
print("\n")
print("\tRunning Atbash Cipher on input string " + text + "\n")
print("Atbash Ciphered Response")
uppercase_shift = ord("A") #65
lowercase_shift = ord("a") #97
shifted_upper_z = ord("Z") - uppercase_shift #97-65 = 25
shifted_lower_z = ord("z") - lowercase_shift #122 - 97 = 25
result_string = ""
for l in text:
if ord("A") <= ord(l) <= ord("Z"):
result_string += chr((shifted_upper_z - (ord(l)-uppercase_shift))+uppercase_shift)
elif ord("a") <= ord(l) <= ord("z"):
result_string += chr((shifted_lower_z - (ord(l)-lowercase_shift))+lowercase_shift)
else:
result_string += l
print("________________________________________________")
print("\t" + result_string)
print("________________________________________________")
result_string.strip()
result_words = result_string.split(" ")
correctness = 0
for word in result_words:
result_word = ""
for l in word:
if l.isalnum() and l != " ":
result_word += l
result_word.strip()
try:
correctness += 1 if dictionary.check(result_word) else -.5
except:
pass
if correctness > 0:
return result_string