-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.py
45 lines (36 loc) · 1.03 KB
/
files.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
"""
Author: Edgard Diaz
Date: 17th March 2020
This class implements the methods used to read and write the
plaintext files that are processed by the encryption algorithm.
"""
import os
class files:
def UploadTextFile(self, path):
File = ""
PlaneText = ""
try:
File = open(path)
PlaneText = (File.read().rstrip())
File.close()
return PlaneText
except ValueError:
print ("File or path not found.")
def WriteFile(self, Text,OriginalFileName,opt):
if opt == 'e':
OriginalFileName = OriginalFileName.replace(".txt","_")
FileName = OriginalFileName + "Encrypted.txt"
try:
FileToWrite = open(FileName, 'w+')
FileToWrite.write(Text)
except ValueError:
print(ValueError)
return 'file encryption completed successfully'
elif opt == 'd':
FileName = "Text_decrypted.txt"
try:
FileToWrite = open(FileName, 'w+')
FileToWrite.write(Text)
except ValueError:
print(ValueError)
return 'file decryption completed successfully'