I am trying to encrypt binary vector using AES encryption in matlab, the problem is that I want the output to be binary vector aswell, and the same size as the original binary vector, is that possible ? and if yes, how can I do that ?

 Respuesta aceptada

Walter Roberson
Walter Roberson el 3 de Oct. de 2015
Note that due to US laws, we are not able to discuss the implementation of AES in this forum. However, your question does not depend upon the implementation of AES, so it can be discussed.
You will need to pack your bits together into 8 bit bytes and encrypt the sequence of bytes; then unpack the sequence of encrypted bytes to form a sequence of bits.
ByteVector = bin2dec( char(reshape(BitVector, 8, []).' + '0') );
But first you have to pad BitVector out to a multiple of 8 bits.
Then you can encrypt ByteVector. Then afterwards
EncryptedBitVector = reshape( dec2bin( EncryptedByteVector, 8) .' - '0', 1, [])
This will almost certainly be longer than the original vector due to the way that AES works.

4 comentarios

Mohab Mostafa
Mohab Mostafa el 4 de Oct. de 2015
Thank you, it works :)
roja chigiti
roja chigiti el 20 de Abr. de 2018
Editada: Walter Roberson el 20 de Abr. de 2018
my plaintext is of size 32X1 I applied aes to it and i wanted to check decrypted value matches to the plain text or not but they are not equal
i am not getting where I am doing wrong. kindly guide me through it. below is my code
[CODE REMOVED]
Walter Roberson
Walter Roberson el 20 de Abr. de 2018
roja chigiti,
Note that due to US laws, we are not able to discuss the implementation of AES in this forum. I removed your code, which contained an implementation of AES.
roja chigiti
roja chigiti el 21 de Abr. de 2018
thank you, i will keep in mind.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Encryption / Cryptography en Centro de ayuda y File Exchange.

Preguntada:

el 3 de Oct. de 2015

Comentada:

el 21 de Abr. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by