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/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 diff --git a/__pycache__/email_bomber.cpython-36.pyc b/__pycache__/email_bomber.cpython-36.pyc deleted file mode 100644 index 4c9e281..0000000 Binary files a/__pycache__/email_bomber.cpython-36.pyc and /dev/null differ