-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodebreak.py
More file actions
45 lines (36 loc) · 1.14 KB
/
codebreak.py
File metadata and controls
45 lines (36 loc) · 1.14 KB
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
code = "pbqrarjovrf ner gur zbfg fhccbegvir pbzzhavgl"
msg1 = "No one can read this secret message"
msg2 = "it is so super secret"
msg3 = "only a CodeNewbie can figure it out"
def decrypt_message(message):
#Code is decrypted by converting to unicode via ord() note a=97 z=122
#code increase by 13
decrypted_msg = ""
for char in message:
ord_char = ord(char.lower())
ord_newchar = ord_char + 13
if ord_newchar > 122:
ord_newchar = 97 + (ord_char + 13) - 123
#account for blanks and keep blanks blanks
if ord_char == 32:
ord_newchar =32
decrypted_msg += str(chr(ord_newchar))
return(decrypted_msg)
def encrypt_message(message):
#as there are 23 letters in the alphabet conversion is the same as decryption
return (decrypt_message(message))
print (60 * '*')
print ('Code Breaker')
print (decrypt_message(code))
print (20 * '=')
print (msg1)
print (encrypt_message(msg1))
print (decrypt_message(encrypt_message(msg1)))
print (20 * '=')
print (msg2)
print (encrypt_message(msg2))
print (decrypt_message(encrypt_message(msg2)))
print (20 * '=')
print (msg3)
print (encrypt_message(msg3))
print (decrypt_message(encrypt_message(msg3)))