Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Does there exist a cipher that can be encrypted twice with two different keys an

ID: 652606 • Letter: D

Question

Does there exist a cipher that can be encrypted twice with two different keys and then decrypted twice using either key first?

For example:

Plaintext is "Lemons are great!"
Encode with Key #1
Encode with Key #2
Decode with Key #1
Decode with Key #2
Result is "Lemons are great!"

To my understanding TLS does something like this, but I'm not sure. I've also tried reading about elliptical curve cryptography to no avail (of useful understanding, that is). I've also tried my own tests with OpenSSL but I feel like it's salting things and therefore is making it not work.

I understand this is possible with a ROT(n), but that's of course not considered cryptographically secure.

Explanation / Answer

ROT(n) can be thought of as a character based stream cipher. It works because addition - the encryption method used - is commutative, i.e. ROT(x,ROT(y,m))=ROT(y,ROT(x,m)).

Another well known commutative function is XOR. It is used by the one time pad, but - more practically - also for block ciphers in streaming mode. So you can encrypt using AES in CTR mode using two different keys in any order and get the same ciphertext. And decryption will work in any order as well.

Note that you should use an IV or nonce if you reuse the keys. A single IV should do even if you have two separate keys.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote