-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCriptFile.py
63 lines (54 loc) · 1.98 KB
/
CriptFile.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
from os import system
from sys import exit, platform
import threading
import rsa.randnum
class CriptFile:
def __call__(self, data):
def encrypt_rsa(*args, **kwargs):
(pubkey, privkey) = rsa.newkeys(2048)
crypto = rsa.encrypt(data(*args, **kwargs), pubkey)
print(crypto)
return encrypt_rsa
@staticmethod
def doc(address):
with open(address) as fp:
document = fp.read()
for element in document[::]:
element = str(element)
document = str.encode(document)
return document
class WriteToNewTxt:
def __init__(self, directory_address, data_encrypt_text):
self.directory_address = directory_address
self.data_encrypt_text = data_encrypt_text
def Create_txt_encript(self, directory_address):
system('cd ' + directory_address)
system('NUL> encript.txt')
def Write_in_txt(self, data_encrypt_text):
with open('encript.txt', 'w') as output:
output.write(data_encrypt_text)
output.close()
if __name__ == '__main__':
system_check = platform
if system_check == 'win32':
def realization():
print("---Enter the directory of file---")
directory = str(input()) + '\\' + '\\'
print("---Enter name of txt file---")
name_file = str(input())
address = directory + name_file
try:
print("---Result of RSA---")
print(CriptFile.doc(address))
to_str = str(CriptFile.doc(address))
print(to_str)
WriteToNewTxt(directory, to_str).Create_txt_encript(directory)
WriteToNewTxt(directory, to_str).Write_in_txt(to_str)
except OSError:
print("Some problems...")
exit()
thread = threading.Thread(target=realization(), args=(1,))
thread.start()
else:
print("---System is not win32---")
exit()