# BY Jamison Nielsen
# Made in Mr. Delfino's Computational Thinking Class
# Basic AES Algorithm implemented in Python
# Built using python
import time, os
from Crypto.Cipher import AES
import base64
encordec=input("Do you want to Encrypt your data or Decrypt your data:")
ifor=0
if encordec.lower()=="encrypt":  # Checks to see if you want to encrypt or decrypt text
    print("Great!")
    time.sleep(1)
    print("What do you want to encrypt?")
    txttoencrypt=input('')
    ifor=1
elif encordec.lower()=='Encrypt':
    print("Great!")
    time.sleep(1)
    print("What do you want to encrypt?")
    txttoencrypt=input('')
    ifor=1
elif encordec.lower()=='e':
    print("Great!")
    time.sleep(1)
    print("What do you want to encrypt?")
    ifor=1
    txttoencrypt=input('')
elif encordec.lower()=='E':
    print("Great!")
    time.sleep(1)
    print("What do you want to encrypt?")
    txttoencrypt=input('')
    ifor=1
elif encordec.lower()=='Decrypt':
    print("Great!")
    time.sleep(1)
    print('What do you want to encrypt?')
    ciphertxt=input('')
    print("Whats your secret Key?")
    secretkey=input('')
    ifor=2
elif encordec.lower()=='decrypt':
    print("Great!")
    time.sleep(1)
    print('What do you want to encrypt?')
    ciphertxt=input('')
    print("Whats your secret Key?")
    secretkey=input('')
    ifor=2
elif encordec.lower()=='D':
    print("Great!")
    time.sleep(1)
    print('What do you want to encrypt?')
    ciphertxt=input('')
    print("Whats your secret Key?")
    secretkey=input('')
    ifor=2
elif encordec.lower()=='d':
    print("Great!")
    time.sleep(1)
    print('What do you want to encrypt?')
    ciphertxt=input('')
    print("Whats your secret Key?")
    secretkey=input('')
    ifor=2
else:
    print("sorry")
    print("I don't know what you want to encrypt")
    print("please try again")
class Aes:
    def encrypt(self, privateInfo):
        #BLOCK SIZE DETERMINES ENCRYPTION LEVEL 32:256 16:128
        BLOCK_SIZE = 32
        # PADDING CHARACTER USED TO PAD ANY EXTRA SPACE IN THE STRING
        padd = '{'
        pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * padd
        # encrypt with AES, encode with base64
        EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
        # generate a randomized secret key with urandom
        supersecretencryptionkey = os.urandom(BLOCK_SIZE)
        print('encryption key:',supersecretencryptionkey)
        # creates the cipher object using the key
        cipher = AES.new(supersecretencryptionkey)
        encoded = EncodeAES(cipher, privateInfo)
        print ('Encrypted string:', encoded)
        print("BE SURE TO SAVE THE ENCRYPTION KEY IF YOU WANT TO DECRYPT DATA LATER")
    def decrypt(self, encryptedString):
        pad = '{'
        Decoder = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(pad)
        encryption = encryptedString
        key = secretkey
        cipher = AES.new(key)
        decoded = Decoder(cipher, encryption)
        print(decoded)
if ifor==1:
    Aes.encrypt(txttoencrypt,txttoencrypt)
elif ifor==2:
    Aes.decrypt(ciphertxt,ciphertxt)
else:
    x=100
    while x>=1:
        print("Please try again")
        x-1
