Skip to content

Commit b731646

Browse files
committed
Created File-Encrypter
1 parent 5a3264a commit b731646

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

File-Encrypter/README.md

2.74 KB

File Encrypter

This is a command-line interface (CLI) tool that provides secure file encryption and decryption functionalities. The tool allows users to encrypt sensitive files using a strong encryption algorithm, making the contents unreadable to unauthorized individuals. It also enables users to decrypt encrypted files, restoring them to their original state.

Install Dependencies

  • Step 1 : Clone the Repository
  • Step 2 : Change directory to File-Encrypter
  cd Amazing-Python-Scripts/File-Encrypter
  • Step 3: run the command
 pip install -r requirements.txt  

Usage

  • Create a file with the content you want to encrypt in the same directory as the script, the run -
  python script.py <file_name> encrypt
  • Congratulations ! The file is encrypted. You would notice that your original file is gone and replaced with a .encrypted file of the same name. To decrypt it run -
  python script.py <file_name.encrypted> decrypt
  • For more info, run this -
  python script.py --help

secret.key

This is a crucial file generated automatically when you first encrypt your file. It contained the main Encryption Key. It needs to be present in the same folder too. If you're really planning to hide some important data, better move this file somewhere else. But dont lose it.

File-Encrypter/requirements.txt

50 Bytes
Binary file not shown.

File-Encrypter/script.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from cryptography.fernet import Fernet
2+
import os
3+
import sys
4+
import argparse
5+
6+
def generate_key():
7+
return Fernet.generate_key()
8+
9+
def save_key(key, file_path):
10+
# save encryption key to a file
11+
with open(file_path,'wb') as f:
12+
f.write(key)
13+
14+
def load_key(file_path):
15+
with open(file_path,'rb') as f:
16+
return f.read()
17+
18+
def encrypt_file(key,file_path):
19+
f=Fernet(key)
20+
with open(file_path,'rb') as f_input:
21+
data = f_input.read()
22+
encrypted_data = f.encrypt(data)
23+
with open(file_path.split(".")[0]+'.encrypted','wb') as f_output:
24+
f_output.write(encrypted_data)
25+
os.remove(file_path)
26+
27+
def decrypt_file(key, file_path):
28+
f=Fernet(key)
29+
with open (file_path,'rb') as f_enc:
30+
data = f_enc.read()
31+
dec_data = f.decrypt(data)
32+
with open(file_path.split(".")[0]+".txt",'wb') as f_dec:
33+
f_dec.write(dec_data)
34+
os.remove(file_path)
35+
36+
if __name__ == "__main__":
37+
parser = argparse.ArgumentParser(description = "[*]Encrypt youre files and password protect them")
38+
parser.add_argument('file_path', help="Add the name of the file to be encrypted")
39+
parser.add_argument('mode',choices=['encrypt','decrypt'],help="Choose either encrypt or decrypt")
40+
args = parser.parse_args()
41+
42+
if args.mode == "encrypt":
43+
key = generate_key()
44+
save_key(key,"secret.key")
45+
encrypt_file(key,args.file_path)
46+
print("Encrypted")
47+
else:
48+
key = load_key("secret.key")
49+
50+
decrypt_file(key, args.file_path )
51+
print("Decrypted")

Keylogger/keylogger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ def off_press(key):
3636
with Listener(on_press=on_press, off_press=off_press) as i:
3737
i.join()
3838

39-
f.close()
39+
f.close()

0 commit comments

Comments
 (0)