1
1
import base64
2
2
import binascii
3
3
4
- message = input ("Please enter the text you would like to encrypt or decrypt: " )
4
+ # ~~~~~~~~~~~~~~~~~~~~~~ Encryption ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
+ message = input ("Please enter the text you would like to encrypt " )
5
6
option = input ("Please select the method you'd like to use: base64/morse/hex/caesar cipher: " )
6
7
while option == 'base64' or option == 'morse' or option == 'hex' or option == 'caesar cipher' :
7
8
if option == 'base64' :
13
14
14
15
if option == 'morse' :
15
16
Morse_Dict = {'A' :'.-' , 'B' :'-...' ,'C' :'-.-.' , 'D' :'-..' , 'E' :'.' ,'F' :'..-.' , 'G' :'--.' , 'H' :'....' ,'I' :'..' , 'J' :'.---' , 'K' :'-.-' ,'L' :'.-..' , 'M' :'--' , 'N' :'-.' ,'O' :'---' , 'P' :'.--.' , 'Q' :'--.-' ,'R' :'.-.' , 'S' :'...' , 'T' :'-' ,'U' :'..-' , 'V' :'...-' , 'W' :'.--' ,'X' :'-..-' , 'Y' :'-.--' , 'Z' :'--..' ,'1' :'.----' , '2' :'..---' , '3' :'...--' ,'4' :'....-' , '5' :'.....' , '6' :'-....' ,'7' :'--...' , '8' :'---..' , '9' :'----.' ,'0' :'-----' , ', ' :'--..--' , '.' :'.-.-.-' ,'?' :'..--..' , '/' :'-..-.' , '-' :'-....-' ,'(' :'-.--.' , ')' :'-.--.-' }
16
- def encryption (message ):
17
+ def encryption (message ):
17
18
cipher = ' '
18
19
for letter in message :
19
20
if letter != ' ' :
20
21
cipher += Morse_Dict [letter ] + ' '
21
22
else :
22
23
cipher += ' '
23
24
print (cipher )
24
- encryption (message )
25
+ encryption (message )
26
+
27
+
25
28
if option == 'hex' :
26
29
print (message .encode ("utf-8" ).hex ())
30
+
27
31
if option == 'caesar cipher' :
28
32
s = int (input ("Please enter the shift number you'd like (Exmaple: 4): " ))
29
33
def encrypt (message ,s ):
@@ -42,3 +46,64 @@ def encrypt(message,s):
42
46
encrypt (message , s )
43
47
break
44
48
49
+ # ~~~~~~~~~~~~~~~~~~~~~~ DECRYPTION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
50
+ message = input ("Please enter the text you would like to decrypt " )
51
+ option = input ("Please select the method you'd like to use: base64/morse/hex/caesar cipher: " )
52
+ while option == 'base64' or option == 'morse' or option == 'hex' or option == 'caesar cipher' :
53
+ if option == 'base64' :
54
+ message_bytes = message .encode ('ascii' )
55
+ base64_bytes = base64 .b64decode (message_bytes )
56
+ base64_message = base64_bytes .decode ('ascii' )
57
+ print ("Encrypted Message:" + base64_message )
58
+ break
59
+
60
+
61
+ if option == 'morse' :
62
+ Morse_Dict = {'A' :'.-' , 'B' :'-...' ,'C' :'-.-.' , 'D' :'-..' , 'E' :'.' ,'F' :'..-.' , 'G' :'--.' , 'H' :'....' ,'I' :'..' , 'J' :'.---' , 'K' :'-.-' ,'L' :'.-..' , 'M' :'--' , 'N' :'-.' ,'O' :'---' , 'P' :'.--.' , 'Q' :'--.-' ,'R' :'.-.' , 'S' :'...' , 'T' :'-' ,'U' :'..-' , 'V' :'...-' , 'W' :'.--' ,'X' :'-..-' , 'Y' :'-.--' , 'Z' :'--..' ,'1' :'.----' , '2' :'..---' , '3' :'...--' ,'4' :'....-' , '5' :'.....' , '6' :'-....' ,'7' :'--...' , '8' :'---..' , '9' :'----.' ,'0' :'-----' , ', ' :'--..--' , '.' :'.-.-.-' ,'?' :'..--..' , '/' :'-..-.' , '-' :'-....-' ,'(' :'-.--.' , ')' :'-.--.-' }
63
+ def decrypt (message ):
64
+ var = '' #variable for concatenating letters
65
+ decode = ''
66
+ for letter in message :
67
+ if (letter != ' ' ):
68
+ c = 0 #counter for spaces to keep letters separated
69
+ var += letter
70
+ else :
71
+ c += 1
72
+ if c == 2 :
73
+ decode += ' '
74
+ else :
75
+ decode += list (Morse_Dict .keys ())[list (Morse_Dict .values ()).index (var )]
76
+ var = ''
77
+ return decode
78
+ result = decrypt (message )
79
+ print (result )
80
+ break
81
+
82
+
83
+ if option == 'hex' :
84
+ hex_bytes = bytes .fromhex (message )
85
+ message_bytes = hex_bytes .decode ('utf-8' )
86
+ result = message_bytes
87
+ print (result )
88
+ break
89
+
90
+ if option == 'caesar cipher' :
91
+ s = int (input ("Please enter the shift number you'd like (Exmaple: 4): " ))
92
+ def decrypt2 (message ,s ):
93
+ result = ""
94
+ # transverse the plain text
95
+ for i in range (len (message )):
96
+ char = message [i ]
97
+ # Encrypt uppercase characters in plain text
98
+
99
+ if (char .isupper ()):
100
+ result += chr ((ord (char ) - s - 65 ) % 26 + 65 )
101
+ # Encrypt lowercase characters in plain text
102
+ else :
103
+ result += chr ((ord (char ) - s - 97 ) % 26 + 97 )
104
+ print (result )
105
+ decrypt2 (message , s )
106
+ break
107
+
108
+
109
+
0 commit comments