Untitled

 avatar
unknown
plain_text
3 years ago
1.3 kB
5
Indexable
import os
from cryptography.fernet import Fernet
import argparse

msgfName = 'READTHISTOGETBACKYOURDATA.txt'

def discoverFiles(path):
	for dirpath, dirs, files in os.walk(path):
		for i in files:
			if i in [msgfName]:
				continue
			absolute_path = os.path.abspath(os.path.join(dirpath, i))
			if absolute_path is not __file__:
				yield absolute_path

def decryptFile(filepath, key):
	with open(filepath, 'rb') as file:
		contents = file.read()
	decrypted_contents = Fernet(key).decrypt(contents)
	with open(filepath, 'wb') as file:
		file.write(decrypted_contents)

def decrypt(paths, key)
	for currentDir in paths:
		for file in discoverFiles(currentDir):
			print("Decrypting:", file)
			decryptFile(file, key)
	print("Files Decrypted")
    
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("key", "specify key for decryption")
    args = parser.parse_args()

    #defaultStarts = ['/home', '/var/backups']
    defaultStarts = ['/home/tintin/Documents/test']

    if args.key is None:
        print("[ERROR] 'key' option is required for decryption")
    else:
        decrypt(defaultStarts, args.key)
        print("Congrats! All your files have been decrypted using the provided key.")

if __name__ == '__main__':
    main()
Editor is loading...