Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
Farah Izzati
Farah Izzati am 23 Apr. 2018
Kommentiert: Stephen23 am 24 Apr. 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 Kommentar
Stephen23
Stephen23 am 24 Apr. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Shounak Shastri
Shounak Shastri am 24 Apr. 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.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by