Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 73552a6

Browse files
Merge pull request avinashkranjan#1480 from AvishkarArjan/branch_avishkar
Branch avishkar
2 parents 4bfa5be + b731646 commit 73552a6

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
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")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /