def ECB_encryption_oracle(input_string, key): app_aft = b64.b64decode( "Um9sbGluJyBpbiBteSA1LjAKV2l0aCBteSByYWctdG9wIGRvd24gc28gbXkgaGFpciBjYW4gYmxvdwpUaGUgZ2lybGllcyBvbiBzdGFuZGJ5IHdhdmluZyBqdXN0IHRvIHNheSBoaQpEaWQgeW91IHN0b3A/IE5vLCBJIGp1c3QgZHJvdmUgYnkK" ) _unencrypted = input_string + app_aft to_encrypt = s2_1.pad_string_pkcs7(_unencrypted) encrypted_string = s2_2.encrypt_AES_ECB(to_encrypt, key) return encrypted_string
def CBC_encryption_oracle(user_input): prepend = "comment1=cooking%20MCs;userdata=" append = ";comment2=%20like%20a%20pound%20of%20bacon;" user_input = user_input.replace(';', '').replace('=', '') to_encrypt = s2_1.pad_string_pkcs7( (prepend + user_input + append).encode()) encrypted_string = s2_2.CBC_encrypt(to_encrypt, unkown_key, IV) return encrypted_string
def profile_for(user_input, key): if type(user_input) == bytes: user_input = user_input.decode() user_input = user_input.replace('&', '') user_input = user_input.replace('=', '') UID = 10 role = 'user' profile = "email={}&UID={}&role={}".format(user_input, str(UID), role) to_encrypt = s2_1.pad_string_pkcs7(profile.encode()) profile = s2_2.encrypt_AES_ECB(to_encrypt, key) return profile
def CBC_encryption_oracle(user_input): to_encrypt=s2_1.pad_string_pkcs7((user_input)) encrypted_string=s2_2.CBC_encrypt(to_encrypt, unknown_key, IV) return encrypted_string
def u_encrypt_cbc(plain_text): padded_plain_text = s2_1.pad_string_pkcs7(plain_text) cipher_text = s2_2.CBC_encrypt(padded_plain_text, ukey, IV) return cipher_text