From cbaf73dc334b0317c6f4934cb332ec97f738f0e2 Mon Sep 17 00:00:00 2001 From: Rishav Das Date: Mon, 3 May 2021 21:37:41 +0530 Subject: [PATCH 1/2] Updated the .gitignore file with corrections in the ignoring of the __pycache__ directory. Previously, it was written for all the files inside that directory to be ignored, but now it is changed to the entire directory itself will be ignored. Although, the pycache folder is a waste folder, which has no need, but still makes the crowd. So, better to remove it. Also, added the code for ignoring the other __pycache__ folders inside the other directories. --- .gitignore | 9 ++++++++- __pycache__/email_bomber.cpython-36.pyc | Bin 1639 -> 0 bytes 2 files changed, 8 insertions(+), 1 deletion(-) delete mode 100644 __pycache__/email_bomber.cpython-36.pyc diff --git a/.gitignore b/.gitignore index 96403d3..0ee10e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,8 @@ -__pycache__/* +# The ignore list for PyCk +# +# [!] Ignore the cache folders and files. +# + +# Ignoring pycache folders of each directory +__pycache__/ +*/__pycache__/ diff --git a/__pycache__/email_bomber.cpython-36.pyc b/__pycache__/email_bomber.cpython-36.pyc deleted file mode 100644 index 4c9e2813cbc15a670d0e48552a2a497b45a95b18..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1639 zcmZ8iPjB2r6rZuZws+&*CLwJ~RUrq#VUaeG=mAtkh*AhbB3VMvM~+9XW_Vf{ z0mefN`5J`LDOr*gE#0NdEXdZ1enQO5#>{>@TRPjM^cFw9j1*@JId4K zTO4B7s+>tKRpiWbp}Ka|JVUNQ%$SILl^a1;b}Gk3`&Aio9UMxYsbc#8B4?q>^_R-vvSXJk;bZOh&UVb%G2x4l40bW9G&(fU#eIrHIq?emXDJR3dHNgmGk^OLD*a* znd-JGR~tAAna5JT$OVf$!AHqYTp(w?J>g(yRYN5ymz6u=G5jkJ6B%P=nnlPV5bzrj z>+t;d{k=(^@;xOIRFUoV7Z0E9nN1Cbc{=1`cfP1hJx8cVgG1g0A+$w1cztTob;AR2 zpWdP_6`Qb+w3B`s7{F?cqkkYMGNlZNyr3oUGzBu5qYN@G9Nf9q;Qpa$GWSZ;Vr$R@ z*EDU`f#$|F%{tqFX7ifn9k!($cJoTpSdo%0>C_E~{1x20}8G?G+HV=g;n z+oi>Bmo|I1bl|%te%G|LvOC~`_(Rju&I0hZ_*2u;Q5|p>!^7}_WP9nXTy&Vm<(=aq z_{zYgKG`mf))UYG8(sjt`%N zC*Sw`kG?xS3BNvi@Xeuyuv*MHfXrueJKv~$)IX1fcWseEe+MhKKD@|M zxoB#I!(S#!tU(kVP4t)2;J(|?&L+EK;*F2)$=XNvoM}9<0jY9ur`a|n`4I@Q0=jwa z_3hi}Dc^FaeqG4*K##qrqy51^#}5YGhR{7GZfc_2@5-LVDIW~#75}%kzn|vpe8xZ1 RzYeMQiM4Eh!@uj({{UV%uz>&o From 22121dee808bf8791a89d869c2066cc7b4e3c586 Mon Sep 17 00:00:00 2001 From: Rishav Das Date: Tue, 4 May 2021 15:11:41 +0530 Subject: [PATCH 2/2] Updated the xorCrypt.py, crypto.py, and text_to_hash.py Changes made in this commit : 1. Made the code clean and error free. 2. Added the function of quiting the script immediately when the user presses the CTRL+C. 3. Added the commented docs, making things easy for the readers of the code. --- Cryptography/crypto.py | 91 +++++++++++++++++++++++++++++------- Cryptography/text_to_hash.py | 89 ++++++++++++++++++++++++++++------- Cryptography/xorCrypt.py | 75 +++++++++++++++++++++++------ 3 files changed, 205 insertions(+), 50 deletions(-) diff --git a/Cryptography/crypto.py b/Cryptography/crypto.py index 789ccc6..8342396 100644 --- a/Cryptography/crypto.py +++ b/Cryptography/crypto.py @@ -1,24 +1,81 @@ -from Crypto.Cipher import XOR -import base64, argparse +""" +crypto.py [python3] + +This tool is written in python3 and it serves the feature of encryption and decryption of text (strings) using a key (password). How to use this tool, just type the following commands on terminal and press enter key : 'python3 crypto.py '. +The arguments that the script uses are listed below : + -d, --decrypt For decryption process + -e, --encrypt For encryption process + -k, --key For specifying the key of the encryption/decryption + -t, --text For specifying the text for the encryption/decryption + +Author : Naategh (https://github.com/Naategh/) +Created on : - + +Last modified by : Rishav Das (https://github.com/rdofficial/) +Last modified on : May 4, 2021 + +Changes made in last modification : +1. Made the code clean and error free. +2. Added the function of quiting the script immediately when the user presses the CTRL+C. +3. Added the commented docs, making things easy for the readers of the code. + +Authors contributed to this script (Add your name below if you have contributed) : +1. Naategh (github:https://github.com/Naategh/) +2. Rishav Das (github:https://github.com/rdofficial/, email:rdofficial192@gmail.com) +""" + +# Importing the required functions and modules +try: + from Crypto.Cipher import XOR + import base64, argparse +except Exception as e: + # If there are any errors encountered during the importing of the required modules, then we display the error on the console screen + + input('\n[ Error : {} ]\nPress enter key to continue...'.format(e)) + exit() def encrypt(key, plaintext): - cipher = XOR.new(key) - return base64.b64encode(cipher.encrypt(plaintext)) + """ The function to encrypt the plain text into a cipher text using an user specified key. The function takes two arguments : key, plaintext """ + + cipher = XOR.new(key) + return base64.b64encode(cipher.encrypt(plaintext)) def decrypt(key, ciphertext): - cipher = XOR.new(key) - return cipher.decrypt(base64.b64decode(ciphertext)) + """ The function to decrypt the cipher text into a plain text using an user specified key. The function takes two arguments : key, plaintext. Note : For decryption of a cipher text to its original version, the function would require the original key that was used to encrypt the string/text. """ + + cipher = XOR.new(key) + return cipher.decrypt(base64.b64decode(ciphertext)) if __name__ == '__main__': - parser = argparse.ArgumentParser("Simple crypto script") - parser.add_argument("-d", "--decrypt", action="store_true") - parser.add_argument("-e", "--encrypt", action="store_true") - parser.add_argument("-k", "--key", required=True, help="Key for encryption/decryption") - parser.add_argument("-t", "--text", required=True, help="Text you want encrypt/decrypt") - args = parser.parse_args() - - if args.decrypt: - print(decrypt(args.key, args.text)) - elif args.encrypt: - print(encrypt(args.key, args.text)) + try: + # First, we will parse all the arguments entered by the user while calling this script + parser = argparse.ArgumentParser('Simple crypto script') + parser.add_argument('-d', '--decrypt', action = 'store_true') + parser.add_argument('-e', '--encrypt', action = 'store_true') + parser.add_argument('-k', '--key', required = True, help = 'Key for encryption/decryption') + parser.add_argument('-t', '--text', required = True, help = 'Text you want encrypt/decrypt') + args = parser.parse_args() + + if args.decrypt: + # If the user choosed encryption, then we continue to execute the task + + print(decrypt(args.key, args.text)) + elif args.encrypt: + # If the user choosed decryption, then we continue to execute the task + + print(encrypt(args.key, args.text)) + else: + # If the user's choice is neither encryption nor decryption, then we display the error on the console screen + + input('\n[ Error : Please specify either encryption (-e, --encrypt) or decryption (-d, --decryption) ]\nPress enter key to continue...') + exit() + except KeyboardInterrupt: + # If the user presses CTRL+C key combo, then we exit the script + + exit() + except Exception as e: + # If there are any errors encountered during the process, then we display the error on the console screen + + input('\n[ Error : {} ]\nPress enter key to continue...'.format(e)) + exit() \ No newline at end of file diff --git a/Cryptography/text_to_hash.py b/Cryptography/text_to_hash.py index 84b0e5f..18e0a0f 100644 --- a/Cryptography/text_to_hash.py +++ b/Cryptography/text_to_hash.py @@ -1,35 +1,88 @@ +""" +Text to Hash [python3] + +This tool is written in python3 and it serves the feature of hashifying the user entered text. To use the tool follow the below commands and arguments guide. +python3 text_to_hash.py + +Arguments +-t, --text The plain text to be converted to hash form +-T, --Type The type of the hashing algorithm + +Author : Naategh (https://github.com/Naategh/) +Created on : - + +Last modified by : Rishav Das (https://github.com/rdofficial/) +Last modified on : May 4, 2021 + +Changes made in last modification : +1. Made the code clean and error free. +2. Added the function of quiting the script immediately when the user presses the CTRL+C. +3. Added the commented docs, making things easy for the readers of the code. + +Authors contributed to this script (Add your name below if you have contributed) : +1. Naategh (github:https://github.com/Naategh/) +2. Rishav Das (github:https://github.com/rdofficial/, email:rdofficial192@gmail.com) +""" + +# Importing the required functions and modules import hashlib import argparse -def main(text, hashType): - encoder = text.encode('utf_8') +def main(): + # DRIVER CODE + + # Parsing the user entered arguments + parser = argparse.ArgumentParser(description = 'Convert text to hash') + parser.add_argument('-t', '--text', dest = 'text', required = True) + parser.add_argument('-T', '--Type', dest = 'type', required = True) + args = parser.parse_args() + + # Encoding the user specified text to utf-8 encoding + encoder = args.text.encode('utf_8') myHash = '' - if hashType.lower() == 'md5': + if args.type.lower() == 'md5': + # If the user specified md5 hashing algorithm + myHash = hashlib.md5(encoder).hexdigest() - elif hashType.lower() == 'sha1': + elif args.type.lower() == 'sha1': + # If the user specified sha1 hashing algorithm + myHash = hashlib.sha1(encoder).hexdigest() - elif hashType.lower() == 'sha224': + elif args.type.lower() == 'sha224': + # If the user specified sha224 hashing algorithm + myHash = hashlib.sha224(encoder).hexdigest() - elif hashType.lower() == 'sha256': + elif args.type.lower() == 'sha256': + # If the user specified sha256 hashing algorithm + myHash = hashlib.sha256(encoder).hexdigest() - elif hashType.lower() == 'sha384': + elif args.type.lower() == 'sha384': + # If the user specified sha384 hashing algorithm + myHash = hashlib.sha384(encoder).hexdigest() - elif hashType.lower() == 'sha512': + elif args.type.lower() == 'sha512': + # If the user specified sha512 hashing algorithm + myHash = hashlib.sha512(encoder).hexdigest() else: - print('[!] The script does not support this hash type') - exit(0) - print("Your hash is: ", myHash) + # If the user specified hashing algorithm is not supported by the script + + raise TypeError('The specified hashing algorithm is not supported by this tool') + # If there are no errors in the process, then we display the created hash on the console screen + print('[$] Hash formed : {}'.format(myHash)) if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Convert text to hash') - parser.add_argument('-t', '--text', dest='text', required=True) - parser.add_argument('-T', '--Type', dest='type', required=True) - args = parser.parse_args() + try: + main() + except KeyboardInterrupt: + # If the user presses CTRL+C key combo, then we exit the script + + exit() + except Exception as e: + # If there are any errors during the process, then we display the error message on the console screen - txt = args.text - hType = args.type - main(txt, hType) + input('\n[ Error : {} ]\nPress enter key to continue...') + exit() \ No newline at end of file diff --git a/Cryptography/xorCrypt.py b/Cryptography/xorCrypt.py index cc3033d..42fdca7 100644 --- a/Cryptography/xorCrypt.py +++ b/Cryptography/xorCrypt.py @@ -1,36 +1,81 @@ #!/usr/bin/env python3.6 -#xorCrypt.py -#impliments xor encryption/decryption + +""" +xorCrypt [python3] + +This tool is written in python3 and it serves the feature of implementing the XOR cryptographic algorithms. The arguments that the tool takes in are described below. +--key File containting the key +--text File containing the text +Using these arguments, the user inputs information to this tool, and then it processes the task. + +Author : Naategh (https://github.com/Naategh/) +Created on : - + +Last modified by : Rishav Das (https://github.com/rdofficial/) +Last modified on : May 4, 2021 + +Changes made in last modification : +1. Made the code clean and error free. +2. Added the function of quiting the script immediately when the user presses the CTRL+C. +3. Added the commented docs, making things easy for the readers of the code. + +Authors contributed to this script (Add your name below if you have contributed) : +1. Naategh (github:https://github.com/Naategh/) +2. Rishav Das (github:https://github.com/rdofficial/, email:rdofficial192@gmail.com) +""" + +# Importing the required functions and modules import argparse import logging def xorcrypt(cipher_text, key): - #Xor encryption implimentation + """ The function for implementing the XOR cryptographic algorithm. The function takes two arguments as input, they are : cipher_text and key. The ciper_text is the plain user entered text that is needed to be encrypted, and the key is the password that is used to encrypt the text. """ + endRes = "" if len(cipher_text) != len(key): logging.error("cipher and key must be the same length") else: for i in range(0, len(cipher_text)): - #Converts a character from cipher_text and key to its decimal value - #Then xors the two + # Converts a character from cipher_text and key to its decimal value + # Then xors the two intResult = ord(cipher_text[i]) ^ ord(key[i]) - #Convert intResult to its character representation + + # Convert intResult to its character representation endRes += chr(intResult) return endRes def main(): - #Argparse setup - parser = argparse.ArgumentParser(description="xorCrypt") - parser.add_argument("--key", type=argparse.FileType("r"), help="File containing the key") - parser.add_argument("--text", type=argparse.FileType("r"), help="File containing the text") + # DRIVER CODE + + # Parsing the user entered arguments while calling the script (.py file) + parser = argparse.ArgumentParser(description = 'xorCrypt') + parser.add_argument("--key", type = argparse.FileType('r'), help = 'File containing the key') + parser.add_argument("--text", type = argparse.FileType('r'), help = 'File containing the text') args = parser.parse_args() + + # Checking the user entered arguments if not args.key or not args.text: - logging.error("arguments required to run") + # If the user has not entered the required arguments, then we display the error on the console screen + + logging.error('arguments required to run') else: - #call xorcrypt using the input from the two files - res = xorcrypt(str(args.text.read()), str(args.key.read())) - print(res) + # If the user entered proper arguments, then we continue to complete the task + + # Calling xorcrypt using the input from the two files, and then printing the result on the console screen + result = xorcrypt(str(args.text.read()), str(args.key.read())) + print(result) + input('\nPress enter key to continue...') if __name__ == "__main__": - main() + try: + main() + except KeyboardInterrupt: + # If the user presses CTRL+C key combo, then we exit the script + + exit() + except Exception as e: + # If we encounter an error during the process, then we display the error message on the console screen and exit + + input('\n[ Error : {} ]\nPress enter key to continue...'.format(e)) + exit() \ No newline at end of file