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

조회 수: 13 (최근 30일)
Farah Izzati
Farah Izzati 2018년 4월 23일
댓글: Stephen23 2018년 4월 24일
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
Stephen23
Stephen23 2018년 4월 24일

@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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shounak Shastri
Shounak Shastri 2018년 4월 24일
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.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by