-
Notifications
You must be signed in to change notification settings - Fork 0
/
Principal.py
81 lines (68 loc) · 2.04 KB
/
Principal.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Author: Edgard Diaz
Date: 17th march 2020
This code performs the encryption of a text file using Cesar encryption.
"""
from files import files
from CesarEncryption import Encryption
from os import system, name
import sys
# define our clear function
def clear():
# for windows
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
if __name__ == '__main__':
#create objects from class
obj_File = files()
obj_Encryption = Encryption()
state = True
flag = True
#print options menu
print("\n\nEncrypt and decrypt text files using Caesar encryption.")
while state:
print("\nSelect an option:\n\n\t1).- Encript text \n\t2).- Encrypt text \n\t3).-Exit")
opt = int(input("Enter option: "))
if opt == 1:
try:
clear();
fileName = input("File name: ")
Text = obj_File.UploadTextFile(fileName)
shift = int(input("Number of letters to move the text: "))
TextEncryp = obj_Encryption.EncrypText(Text,shift)
print(obj_File.WriteFile(TextEncryp,fileName,'e'))
state = False
except ValueError:
clear();
print('\n\nError: must be a numeric value\n\n')
state = True
except FileNotFoundError:
clear();
print('Error: file no fund')
elif opt == 2:
try:
clear();
fileName = input("File name: ")
Text = obj_File.UploadTextFile(fileName)
shift = int(input("Number of letters to move the text: "))
TextDecryp = obj_Encryption.DecrypText(Text,shift)
obj_File.WriteFile(TextDecryp,fileName,'d')
state = False
except ValueError:
clear();
print('\n\nError: must be a numeric value\n\n')
state = True
except FileNotFoundError:
clear();
print('Error: file no fund')
elif opt == 3:
state = False
flag = False
print('The program has finished executing, because the exit option has been chosen.')
sys.exit()
else:
clear();
print("\n\nError: Invalid option\n\n")