Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AES Decryption too slow
#5
(May-05-2018, 12:03 AM)Hairy_Ape Wrote: Sorry for any confusion but with this being aes 256 the password is 32 bits in length. So we need to figure out the last 8 bits of the password which is why I’m iterating from 00000000 to 99999999.

You are mixing bits and bytes.
The key in a AES256 is... 256 bits that are exactly 32 bytes.
I have done some tests and a script that encrypt a text of ~1500 bytes and after that tries to decode it changing the last byte of the key in the 256 options takes less than a second and almost all the time is lost printing to the stdout.

To help you this is the script that encodes a secret and returns 3 values: the coded text, the nonce and the truncated key (is missing the last byte)
It also prints in the stdout the right solution.
#!/usr/bin/env python3

import os

from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend


def prepare_secret(msg: bytes):
    key = os.urandom(32)
    
    algo = algorithms.AES(key)
    # Block size in bytes... I expect nobody will create an algorithm with a
    # block size not multiplo of 8
    sz = algo.block_size // 8
    # Create the nonce
    iv = os.urandom(sz)
    cipher = Cipher(algo, modes.CBC(iv), backend=default_backend())

    # Pad the message with nulls up to the chipher block
    # This is essentially *WRONG* but for this demo...
    msg += bytes(sz - len(msg) % sz)

    encryptor = cipher.encryptor()
    ct = encryptor.update(msg) + encryptor.finalize()
    
    print(f"The answer is at {key[-1]}")
    return key[:-1], iv, ct


def hack(hint: bytes, iv: bytes, ct: bytes):
    """
    This is the answer to your homework... And I am a mean person and I do not give it to you :D
    """
    pass

hint, iv, ct = prepare_secret(b'This is the Plain Text message that you are trying to recover')

hack(hint, iv, ct)
You can use this to explore the problem and understand the different element sizes.
Also notice that the padding I am using to make the lenght of the plain text a multiplo of the cypher block size is WRONG... in reality you shall use something like PKCS7 or similar.
Reply


Messages In This Thread
AES Decryption too slow - by Hairy_Ape - May-04-2018, 11:13 PM
RE: AES Decryption too slow - by killerrex - May-04-2018, 11:53 PM
RE: AES Decryption too slow - by Hairy_Ape - May-05-2018, 12:03 AM
RE: AES Decryption too slow - by killerrex - May-05-2018, 12:01 PM
RE: AES Decryption too slow - by micseydel - May-05-2018, 12:14 AM
RE: AES Decryption too slow - by Hairy_Ape - May-07-2018, 04:22 PM
RE: AES Decryption too slow - by killerrex - May-07-2018, 09:44 PM
RE: AES Decryption too slow - by Hairy_Ape - May-08-2018, 08:00 PM
RE: AES Decryption too slow - by Hairy_Ape - May-09-2018, 11:05 AM
RE: AES Decryption too slow - by killerrex - May-09-2018, 11:53 AM
RE: AES Decryption too slow - by Hairy_Ape - May-10-2018, 06:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decryption not working if key has same symbol like text Paragoon2 0 908 Nov-11-2023, 09:32 PM
Last Post: Paragoon2
  encryption and decryption with python ibrahim 1 2,539 May-16-2020, 03:14 PM
Last Post: Larz60+
  cipher decryption tool nightfox82 0 1,939 Mar-25-2020, 06:36 AM
Last Post: nightfox82
  Regarding encryption and decryption naressh1994 1 3,222 Jan-25-2019, 07:26 AM
Last Post: buran
  What is an Encryption And Decryption Lamon112 8 8,736 Jan-14-2017, 10:14 PM
Last Post: Kebap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020