diff --git a/__pycache__/filencrypt.cpython-310.pyc b/__pycache__/filencrypt.cpython-310.pyc new file mode 100644 index 0000000..975ae0c Binary files /dev/null and b/__pycache__/filencrypt.cpython-310.pyc differ diff --git a/filencrypt.py b/filencrypt.py index 34273c8..d524a71 100644 --- a/filencrypt.py +++ b/filencrypt.py @@ -1,30 +1,3 @@ -# ,,,, -# ,;) .';;;;', -# ;;,,_,-.-.,;;'_,|I\;;;/),,_ -# `';;/:|:);{ ;;;|| \;/ /;;;\__ -# L;/-';/ \;;\',/;\/;;;.') \ -# .:`''` - \;;'.__/;;;/ . _'-._ -# .'/ \ \;;;;;;/.'_7:. '). \_ -# .''/ | '._ );}{;//.' '-: '.,L -# .'. / \ ( |;;;/_/ \._./;\ _, -# . / |\ ( /;;/_/ ';;;\,;;_, -# . / )__(/;;/_/ (;;''''' -# / _;:':;;;;:';-._ ); -# / / \ `'` --.'-._ \/ -# .' '. ,' '-, -# / / r--,..__ '.\ -# .' ' .' '--._ ] -# ( :.(;> _ .' '- ;/ -# | /:;( ,_.';( __.' -# '- -'"|;:/ (;;;;-'--' -# |;/ ;;( -# '' /;;| -# \;;| -# \/ - - -# Filencrypt Copyright (C) 2022 deodorantdev@protonmail.com -# License GNU General Public License v3.0 try: from colorama import Fore, Style @@ -44,78 +17,89 @@ import time import sys import os + from art import text2art import colorama except: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Missing requirements. Run 'pip install -r requirements.txt' and re-try.") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - Missing requirements. Run 'pip install -r requirements.txt' and re-try.") + def banner(): try: - pfbanner = pyfiglet.figlet_format("Filencrypt", font="graffiti") + pfbanner = text2art("SafeCipher", font='small', chr_ignore=True) print(pfbanner) - print(" Made with", Fore.RED, chr(9829), Style.RESET_ALL, "by Déodorant#7144") + print(" SafeCipher- A file encryption/decryption tool") print(" https://github.com/deo7/Filencrypt") - except pyfiglet.FontNotFound: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Banner error. Run 'sudo pip3 install --upgrade pyfiglet' and re-try.") + except: + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - Banner error. Run 'pip install art' and re-try.") + def menu(): print("\n\nMenu") - print("[1] Encrypt") - print("[2] Decrypt") - print("[3] Informations") - print("[4] Contact dev") + print("Press 1 to Encrypt a file") + print("press 2 to Decrypt a file") + def encryption(): def filencrypt(pswd, iv, file): key = hashlib.sha256(pswd.encode()).digest() with open("AES_IV.txt", "w") as ivf: - ivf.write(f"Encryption of : {file}\n\n-----BEGIN AES INITIALIZATION VECTOR BLOCK-----\n{iv}\n-----END AES INITIALIZATION VECTOR BLOCK-----".replace("b'", "").replace("'", "")) + ivf.write( + f"Encryption of : {file}\n\n-----BEGIN AES INITIALIZATION VECTOR BLOCK-----\n{iv}\n-----END AES INITIALIZATION VECTOR BLOCK-----".replace("b'", "").replace("'", "")) with open(file, "rb") as f: data = f.read() stime = timeit.default_timer() - + cipher = AES.new(key, AES.MODE_CBC, iv) paddeddata = Padding.pad(data, 16) encrypteddata = cipher.encrypt(paddeddata) - + with open(file, "wb") as ef: ef.write(encrypteddata) time = timeit.default_timer() - stime - print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Encryption of the file " + Fore.GREEN + str(file) + Style.RESET_ALL + " complete in " + Fore.GREEN + str(round(time, 3)) + Style.RESET_ALL + " seconds!\n") - print("Don't forget the password you used for the encryption of this file!\nAlso a " + Fore.GREEN + "AES_IV.txt " + Style.RESET_ALL + "file has been created, it contains the initialization vector (IV) of the encryption. " + Fore.RED + "\nYou have to keep this file " + Style.RESET_ALL + "because you will need this IV for decrypt your file.") + print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Encryption of the file " + Fore.GREEN + str(file) + + Style.RESET_ALL + " complete in " + Fore.GREEN + str(round(time, 3)) + Style.RESET_ALL + " seconds!\n") + print("Don't forget the password you used for the encryption of this file!\nAlso a " + Fore.GREEN + "AES_IV.txt " + Style.RESET_ALL + + "file has been created, it contains the initialization vector (IV) of the encryption. " + Fore.RED + "\nYou have to keep this file " + Style.RESET_ALL + "because you will need this IV for decrypt your file.") file = input(Fore.YELLOW + "\nFile to encrypt : " + Style.RESET_ALL) if "." in file: pass else: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Missing extension") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - Missing extension") try: with open(file, "rb"): pass except IOError: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + f" Error - File not found. Make sure your file is in this path : {os.path.realpath(__file__).replace('filencrypt.py', '')}") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + f" Error - File not found. Make sure your file is in this path : {os.path.realpath(__file__).replace('filencrypt.py', '')}") if os.path.getsize(file) > 62914560: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - File too large. Max size is 60Mo to avoid crashes or errors.") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - File too large. Max size is 60Mo to avoid crashes or errors.") else: pass pswd = input(Fore.YELLOW + "Choose a strong password : " + Style.RESET_ALL) def geniv(length): - str = string.ascii_uppercase + string.digits #+ string.punctuation + str = string.ascii_uppercase + string.digits # + string.punctuation return "".join(random.choice(str) for i in range(length)) iv = geniv(16) - + filencrypt(pswd, iv.encode(), file) + def decryption(): def filedecrypt(pswd, iv, file): key = hashlib.sha256(pswd.encode()).digest() @@ -131,42 +115,51 @@ def filedecrypt(pswd, iv, file): with open(file, "wb") as ef: ef.write(unpaddeddata) - + time = timeit.default_timer() - stime - print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Decryption of the file " + Fore.GREEN + str(file) + Style.RESET_ALL + " complete in " + Fore.GREEN + str(round(time, 3)) + Style.RESET_ALL) - + print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Decryption of the file " + Fore.GREEN + str( + file) + Style.RESET_ALL + " complete in " + Fore.GREEN + str(round(time, 3)) + Style.RESET_ALL) + file = input(Fore.YELLOW + "\nFile to decrypt : " + Style.RESET_ALL) if "." in file: pass else: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Missing extension") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - Missing extension") try: with open(file, "rb"): pass except IOError: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - File not found. Make sure your file is in this path : {os.path.realpath(__file__).replace('filencrypt.py', '')}") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - File not found. Make sure your file is in this path : {os.path.realpath(__file__).replace('filencrypt.py', '')}") - pswd = input(Fore.YELLOW + f"Password used to encrypt {file} : " + Style.RESET_ALL) + pswd = input( + Fore.YELLOW + f"Password used to encrypt {file} : " + Style.RESET_ALL) iv = input(Fore.YELLOW + f"IV used to encrypt {file} : " + Style.RESET_ALL) if len(iv) != 16: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + f" Error - Incorrect length of initialization vector : {len(iv)} chars instead of 16.") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + f" Error - Incorrect length of initialization vector : {len(iv)} chars instead of 16.") filedecrypt(pswd, iv.encode(), file) + def about(): - print(Fore.YELLOW + f"\n[>] Running file : {os.path.realpath(__file__)}" + Style.RESET_ALL) + print(Fore.YELLOW + + f"\n[>] Running file : {os.path.realpath(__file__)}" + Style.RESET_ALL) print("\n[>] Presentation\nFilencrypt (currently in version 4.0) is a cryptography project started in 2021 that encrypts and decrypts your files of all types (js, txt, png...) in AES-256. Filencrypt works with a strong password chosen by the user and with a 16 byte initialization vector (IV) generated by the program, you must keep this IV secret and you will need it to decrypt your file. Note that a new IV is created for each encrypted file.") print("\n[>] Security\nIs Filencrypt a secure project?\nFilencrypt uses AES-256-bit encryption with Cipher Block Chaining (CBC) mode. Although CBC Mode is less secure than XTS or GCM Modes, it is generally suitable for encrypting more or less sensitive files.\nSecurity also depends on the password you use, you should use a strong password with uppercase, lowercase, symbols and numbers.") print("\nIf you have any other questions or suggestions, contact me by discord (Déodorant#7144), mail (deodorantdev@protonmail.com) or by running 'python filencrypt.py -c'!") + def contact(): global os - webhook = DiscordWebhook(url="https://discord.com/api/webhooks/908820502343188501/uljt9W1cqtff0PH5ZzAjvZKxTDfPCioFwYwM8WAgRXBPYbLFRCTGdBz5CvAD4_8_Hzcl") + webhook = DiscordWebhook( + url="https://discord.com/api/webhooks/908820502343188501/uljt9W1cqtff0PH5ZzAjvZKxTDfPCioFwYwM8WAgRXBPYbLFRCTGdBz5CvAD4_8_Hzcl") req = Request( url="https://discord.com/api/webhooks/908820502343188501/uljt9W1cqtff0PH5ZzAjvZKxTDfPCioFwYwM8WAgRXBPYbLFRCTGdBz5CvAD4_8_Hzcl", @@ -177,14 +170,17 @@ def contact(): with urllib.request.urlopen(req) as response: txt = response.read() except: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Contact system error. Try to contact me by discord (Déodorant#7144) or by mail (deodorantdev@protonmail.com).") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - Contact system error. Try to contact me by discord (Déodorant#7144) or by mail (deodorantdev@protonmail.com).") - contactway = input(Fore.YELLOW + "\nEmail or discord to be contacted : " + Style.RESET_ALL) + contactway = input( + Fore.YELLOW + "\nEmail or discord to be contacted : " + Style.RESET_ALL) subject = input(Fore.YELLOW + "Subject : " + Style.RESET_ALL) message = input(Fore.YELLOW + "Message : " + Style.RESET_ALL) if contactway == "" or subject == "" or message == "": - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Empty inputs") + sys.exit(Fore.RED + "\n[-]" + + Style.RESET_ALL + " Error - Empty inputs") img = input(Fore.YELLOW + "Add an image ('y' or 'n') : " + Style.RESET_ALL) if img == "y": @@ -194,20 +190,23 @@ def contact(): with open(filepath, 'rb'): pass except IOError: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Image not found") + sys.exit(Fore.RED + "\n[-]" + + Style.RESET_ALL + " Error - Image not found") if os.path.getsize(filepath) > 8388608: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - File too large. Max size is 8Mo.") + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - File too large. Max size is 8Mo.") else: pass - + with open(filepath, "rb") as f: webhook.add_file(file=f.read(), filename="file.png") else: pass embed = DiscordEmbed(title="Contact Filencrypt", color="03b2f8") - embed.add_embed_field(name="Moyen de contact", value=contactway, inline=False) + embed.add_embed_field(name="Moyen de contact", + value=contactway, inline=False) embed.add_embed_field(name="Sujet", value=subject, inline=False) embed.add_embed_field(name="Message", value=message, inline=False) @@ -218,7 +217,9 @@ def contact(): webhook.add_embed(embed) response = webhook.execute() - print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + " Message sent with success") + print(Fore.GREEN + "\n[+]" + Style.RESET_ALL + + " Message sent with success") + if sys.platform.startswith("linux"): os.system("clear") @@ -252,7 +253,7 @@ def contact(): elif args.c: banner() contact() - + else: banner() menu() @@ -271,7 +272,9 @@ def contact(): contact() else: - sys.exit(Fore.RED + "\n[-] " + Style.RESET_ALL + "Error - You must reply '1', '2', '3' or '4'") + sys.exit(Fore.RED + "\n[-] " + Style.RESET_ALL + + "Error - You must reply '1', '2', '3' or '4'") except KeyboardInterrupt: - sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + " Error - Filencrypt has been interrupted by user") \ No newline at end of file + sys.exit(Fore.RED + "\n[-]" + Style.RESET_ALL + + " Error - Filencrypt has been interrupted by user") diff --git a/requirements.txt b/requirements.txt index 340acb1..155d139 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pyfiglet colorama discord_webhook -pycryptodome \ No newline at end of file +pycryptodome +art \ No newline at end of file