-
Notifications
You must be signed in to change notification settings - Fork 0
/
v.py
98 lines (74 loc) · 2.46 KB
/
v.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 28 20:15:46 2022
@author: ebrahim
"""
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 28 19:30:55 2022
@author: ebrahim
"""
from cryptography.fernet import Fernet
import os
from alive_progress import alive_bar
import time
def is_same(file):
key = open("protect_file/encripted_text.key", "rb").read()
data = open("protect_file/encripted_text.txt", "rb").read()
decrypted_data = Fernet(key).decrypt(data)
write_file = open("protect_file/temp", 'wb').write(decrypted_data)
temp_file = open("protect_file/temp", "r+").read()
if(file == temp_file):
return True
else:
return False
def load_key():
try:
key = open("protect_file/encripted_text.key", "rb").read()
data = open("protect_file/encripted_text.txt", "rb").read()
f = Fernet(key)
decrypted_encrypted = f.decrypt(data)
open("protect_file/@#$.int", 'wb').write(decrypted_encrypted)
print("Sucessfully decripred ebrahim")
except:
print("file name encripted_text.key and encripted_text.txtnot exists ")
def enc_or_dec():
try:
if os.path.exists('protect_file/@#$.int'):
key = Fernet.generate_key()
text = open("protect_file/@#$.int", "r").read()
if is_same(text):
os.remove("protect_file/temp")
print("Your file is same as befor")
os.remove("protect_file/@#$.int")
print("we deleted main file")
else:
f = Fernet(key)
encrypted = f.encrypt(text.encode())
print(encrypted)
open("protect_file/encripted_text.txt", "wb").write(encrypted)
open("protect_file/encripted_text.key", "wb").write(key)
print("your file is sucessfully edited")
os.remove("protect_file/temp")
os.remove("protect_file/@#$.int")
else:
load_key()
except:
print("file name protect_file not exists")
def ok():
with alive_bar(100, bar='smooth', spinner='waves3') as bar:
for i in range(100):
time.sleep(.005)
bar()
def delf():
i=str(input("input file path name = "))
os.rmdir(i)
ok()
delf()
# with alive_bar(100, bar='smooth', spinner='waves3') as bar:
# for i in range(100):
# time.sleep(.005)
# bar()
# enc_or_dec()