File tree Expand file tree Collapse file tree 4 files changed +29
-0
lines changed
Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 1+ def xor_encrypt_decrypt (input_path , output_path , key ):
2+ try :
3+ with open (input_path , 'rb' ) as f :
4+ data = bytearray (f .read ()) # Read image as byte array
5+
6+ for i in range (len (data )):
7+ data [i ] ^= key # XOR each byte with key
8+
9+ with open (output_path , 'wb' ) as f :
10+ f .write (data )
11+
12+ print (f"[+] Process completed. Output saved to: { output_path } " )
13+ except FileNotFoundError :
14+ print ("[-] File not found. Please check the path." )
15+ except Exception as e :
16+ print (f"[-] Error: { str (e )} " )
17+
18+ # Example usage
19+ if __name__ == "__main__" :
20+ print ("Image Encryption/Decryption Tool" )
21+ input_file = input ("Enter image path: " )
22+ output_file = input ("Enter output file path: " )
23+ key = int (input ("Enter a secret key (0-255): " ))
24+
25+ if 0 <= key <= 255 :
26+ xor_encrypt_decrypt (input_file , output_file , key )
27+ else :
28+ print ("[-] Key must be between 0 and 255." )
29+
You can’t perform that action at this time.
0 commit comments