Problem with RC5 Image encryption

Hello ,
I am working now on an image encryption script based on RC5 Encryption Algorithm
but i am little confused about how to read an image & convert it into an array of plain text & after decryption reconvert it into an image again
w = 32; %/* word size in bits */
r = 12; %/* number of rounds */
b = 16; %/* number of bytes in key */
c = 4; %/* number words in key = ceil(8*b/w)*/
t =26; %/* size of table S = 2*(r+1) words */
e=2.71828182846566; %Natural Logarithm
gr=1.61803398875; % Golden Ratio
ModParam=uint64(2^w);
P=uint64((e-2)*2^w); %Magic P Constant
Q=uint64((gr-2)*2^w+2^w); %Magic Q Constant
S=uint64(zeros(1,t)); %Sub-Key /Empty Variable
Original_Data=uint64(zeros(1,2)); %Empty Variable
K=uint64(ones(1,b)); %Key
original = imread('1.bmp');
Original_Data(1)=original(1); % Text block-1 to be encrypted
Original_Data(2)=original(2); % Text block-2 to be encrypted
S=RC5_Initialize(w,c,b,K,S,P,Q,t,ModParam);
CryptedText=RC5_Encrypt(S,r,w,Original_Data,ModParam);
DecryptedText=RC5_Decrypt(S,r,w,CryptedText,ModParam);
i will attach a .zip file which contains the script, functions & inputs
Thanks in Advance

Respuestas (1)

Jan
Jan el 18 de Nov. de 2021

0 votos

For images, "plain text" means the sequence of bytes. Import the image file by fopen&fread(fid, Inf, '*uint8'), not by imread().

3 comentarios

Muhammad Abdulrazek
Muhammad Abdulrazek el 18 de Nov. de 2021
i used fopen&fread functions & the encryption process ran smoothly but i still dont know how to recreate the image after being decrypted ?
Jan
Jan el 18 de Nov. de 2021
What do you want to do exactly: Encrypt a file, or the data of the image? For the 1st, use fopen&fread and fwrite. After decryption you have the image file again, which can be imported by imread. If you want to encrypt the image data only, import the data by imread. You can store them with imwrite also, or with fread, depending on how you want to access the encrypted data.
Muhammad Abdulrazek
Muhammad Abdulrazek el 18 de Nov. de 2021
i want to encrypt the image file to send it in a communication device " Simulation Script " & in the other side decrypt it & be able to show the original image
  • if i use imread() it reads the image & after that it will be encrypted using the rc5 algorithm but the decrypted data is an array
  • original image is 128x128 uint8
  • but the decrypted image is [ 167,164 ] : how to convert that into an image again ?

La pregunta está cerrada.

Productos

Versión

R2016a

Etiquetas

Preguntada:

el 18 de Nov. de 2021

Cerrada:

el 18 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by