-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path03-caesarHacker.py
32 lines (23 loc) · 984 Bytes
/
03-caesarHacker.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
#message = 'guv6(v6(z!(6rp5r7(zr66ntr+'
message = raw_input('\nEnter message: ')
SYMBOLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.`~@#$%^&*()_+-=[]{}|;:<>,/\'"'
print ''
# Loop through every possible key:
for key in range(len(SYMBOLS)):
translated = ''
# Loop through each symbol in `message`:
for symbol in message:
if symbol in SYMBOLS:
symbolIndex = SYMBOLS.find(symbol)
translatedIndex = symbolIndex - key
# Handle the wrap-around:
if translatedIndex < 0:
translatedIndex = translatedIndex + len(SYMBOLS)
# Append the decrypted symbol:
translated = translated + SYMBOLS[translatedIndex]
else:
# Append the symbol without encrypting/decrypting:
translated = translated + symbol
# Display every possible decryption:
print 'Key #%s: %s' % (key, translated)
print ''