-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaesarcipher.py
executable file
·46 lines (37 loc) · 1.28 KB
/
caesarcipher.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
# Caesar Cipher
import random
import encryption as en
import decryption as de
message = input('Enter the message to be encrypted\\decrypted: \n').lower()
while True:
answer = input('Do you have a specific key to use? y\\n\n').lower()
if answer == 'y':
while True:
key = input('Please enter the key value: \n')
try:
if int(key):
key = int(key)
break
except ValueError:
print('Please enter a digit value.\n')
break
elif answer == 'n':
key = random.randint(7, 18)
break
else:
print('Please enter a valid value: y or n\n')
while True:
mode = input('You want encryption or decryption? Press e or d.\n').lower()
if mode == 'e':
enc = en.encryption(message, key)
with open('encrypted.txt', 'a') as fo:
add_cont = fo.write(message + ' ' + enc + ' ' + str(key) + '\n')
break
elif mode == 'd':
dec = de.decryption(message, key)
with open('decrypted.txt', 'a') as fo:
add_cont = fo.write(message + ' ' + dec + ' ' + str(key) + '\n')
print(dec)
break
else:
print('Please enter a valid mode: e or d.\n')