diff --git a/index.py b/index.py index 1d726c3..11de23e 100644 --- a/index.py +++ b/index.py @@ -1,26 +1,50 @@ import argparse -from pathlib import Path - -def encrypt(file): - sal = 'hello encryption' - return sal +from Cryptodome.Cipher import AES +from Cryptodome.Random import get_random_bytes -def decrypt(file): - greet = 'hello decryption' +def encrypt(text, key): + # make encryptor + encryptor = AES.new(key, AES.MODE_CFB) + + # takes the data and returns ciphertext + cipher_text = encryptor.encrypt(text) + + # now to write the ciphertext to the file + encrypted_file = open("encrypted_file.txt", "wb") + encrypted_file.write(cipher_text) + encrypted_file.close() + + # return the cipher_text to show users + return cipher_text + + +def decrypt(): + greet = '\nhello decryption' return greet def main(): + # get arguments from command line parser = argparse.ArgumentParser() parser.add_argument('-f', '--file', type=open) - parser.add_argument('modality', choices=['encrypt', 'decrypt']) args = parser.parse_args() - if args.modality == 'encrypt': - print(encrypt(args.file)) - elif args.modality == 'decrypt': - print(decrypt(args.file)) + # make random 32B long key + key = get_random_bytes(32) + + # read the text file in and make it a string with no line breaks + text = args.file.read().replace('\n', '') + + # encrypt the file + encrypted_text = encrypt(str.encode(text), key) + + # print encrypted text + print("Encrypted file created. Contents:") + print(encrypted_text) + + print(decrypt()) + if __name__ == '__main__': main()