MATLAB: How can i encrypt a colour image with a psuedo random sequence

encryptionpsuedo random sequence

I want to encrypt an colour image with a psuedo random sequence and decrypt the image with the same sequence.How will be the program for the same.

Best Answer

rng(78932); %agree upon a seed
rand_key = uint8(randi([0 255], 1, 4));
Now do your encryption by xor'ing the bytes of the image with rand_key.
To decrypt, repeat the two steps above, and xor'ing the encrypted image with the rand_key to get the unencrypted image.