1
+ import os
2
+
3
+ def xor_encrypt_decrypt (data , key ):
4
+ return bytes ([byte ^ key for byte in data ])
5
+
6
+ def lock_file (file_path , key ):
7
+ try :
8
+ with open (file_path , 'rb' ) as file :
9
+ data = file .read ()
10
+
11
+ encrypted_data = xor_encrypt_decrypt (data , key )
12
+
13
+ with open (file_path , 'wb' ) as file :
14
+ file .write (encrypted_data )
15
+
16
+ except Exception as e :
17
+ print (f'Error locking the file: { e } ' )
18
+
19
+ def hide_file (file_path ):
20
+ try :
21
+ os .rename (file_path , '.' + file_path )
22
+ except Exception as e :
23
+ print (f'Error hiding the file: { e } ' )
24
+
25
+ def lock_and_hide_folder (folder_path , key ):
26
+ try :
27
+ for root , dirs , files in os .walk (folder_path ):
28
+ for file in files :
29
+ file_path = os .path .join (root , file )
30
+ lock_file (file_path , key )
31
+ hide_file (file_path + '.locked' )
32
+
33
+ os .rename (folder_path , '.' + folder_path )
34
+ print (f'Folder locked and hidden as .{ folder_path } ' )
35
+
36
+ except Exception as e :
37
+ print (f'Error locking and hiding the folder: { e } ' )
38
+
39
+ def main ():
40
+ folder_path = input ("Enter the folder path: " )
41
+ key = int (input ("Enter the encryption key (an integer): " ))
42
+
43
+ lock_and_hide_folder (folder_path , key )
44
+
45
+ if __name__ == "__main__" :
46
+ main ()
0 commit comments