How to xor key with the element by element in an array?

13 visualizaciones (últimos 30 días)
Farah Izzati
Farah Izzati el 23 de Abr. de 2018
Comentada: Stephen23 el 24 de Abr. de 2018
hi, Currently i'am doing image encryption for my project. Basically what i want to do is.. XOR key with the first element(done). The answer would XOR with the 2nd element. Next answer will be XOR with the 3rd element and so on. (It is similar to cumsum but i want to do it using XOR)
This is my code..
key = bitxor(bin2dec(strAscii), bitt(1,1))
for r = 1:rw
for c = 1:cl
xored = bitxor(key,bitt(r:-1:c))
end
end
and the output is xored =
1×0 empty uint8 row vector
I hope somebody could share with me how to do this. because i have been stuck for few days to figure out this.
  1 comentario
Stephen23
Stephen23 el 24 de Abr. de 2018

@Farah Izzati: this is not twitter, so I removed the ugly # symbol from your tags, and split them correctly into separate tags. Next time you can do this yourself: simply enter each tag as words, and place a comma to separate the tags. Simple.

Iniciar sesión para comentar.

Respuestas (1)

Shounak Shastri
Shounak Shastri el 24 de Abr. de 2018
Here, try this
I = randi([1,10],5); %Input matrix
[m, n] = size(I) %Size of the input matrix for looping
key = randi([1,10]); %Key
I = uint8(I); %Making sure the key and the input matrix have same number of bits
key = uint8(key);
for ii = 1 : m
for jj= 1 : n
c(ii, jj) = bitxor(key, I(ii,jj));
key = c(ii, jj); %Storing the encrypted value as the new key
end
end
This is just a suggestion. This code could probably be optimized.
Best of Luck.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by