0

I am working on a python script which encrypts text using 128-AES algorithm but i have a problem:

Picture shows my script processes. This works fine the thing is in the decryption when i give wrong key output decimals goes out of range of ASCII, so program can't show any text at the output.
I expected a wrong text! Is it wrong with code or it should be like that?

enter image description here

1
  • 2
    A word of warning: doing your own AES implementation is potentially dangerous; even though the AES (and similar) algorithms are 100% open, implementations often have bugs, which may make decrypting the ciphertext without the key trivially easy. While this is an excellent learning project, you probably don't want to use your code to actually encrypt stuff. Commented Nov 13, 2014 at 15:35

1 Answer 1

1

That's normal, because AES (and most modern cryptosystems) is dealing with encrypting the actual byte values, not the ASCII values. With an incorrect key, the data won't be decrypted correctly, resulting in ranges outside of the normal ASCII values.

If you're looking for something that encrypts/decrypts ASCII, look into some of the "classic" ciphers: Caesar shift, vigenere, etc.

Sign up to request clarification or add additional context in comments.

4 Comments

Will just add that the right term for the mentioned "classic" ciphers is classical/polyalphabetic ciphers.
I used hex ASCII values because in almost every AES encryption references plaintext examples were like this:5e390f7df7a69296a7553dc10aa31f6b So i thought they might be ASCII values.
That's because it's content-agnostic, so it deals in bytes (encrypting files, IO streams, etc), plus the references and (good) tutorials are also discussing the algorithm and low-level details. You can use the unhexlify and hexlify functions in the binascii library in Python to convert back and forth. hex_plaintext = binascii.hexlify(message) docs.python.org/3/library/binascii.html
@CurtisMattoon Thank you it was so helpful. Could you recommend some good and high-level detailed references?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.