Image and Key XORing

1 回表示 (過去 30 日間)
Evolution
Evolution 2012 年 2 月 8 日
Hi there i am still stuck in xoring a 256 byte value with an image stored in a 3D array ? what should be the steps to do it ?I want to the store the first 256 bytes of the image and xor it with key then another 25 bytes of image with the same key and so on .I would later display my results in a figure ?
Any help would be greatly appreciated .
thanks

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 2 月 8 日
Untested:
t = reshape(YourImage(:), 256, []);
EncryptedImage = reshape( bsxfun(@xor, t, YourKey(:).'), size(YourImage) );
Of course you might have a rather different idea of what the "first" 256 bytes of an image are...
  3 件のコメント
Walter Roberson
Walter Roberson 2012 年 2 月 8 日
Correct. Your question did say what to do if your image was not divisible in to 256 byte groups, so I did not code for it.
xc = x(:);
nel = size(xc,1);
npad = mod(256 - mod(nel,256), 256);
xc = vertcat(xc, zeros(npad, 1));
t = reshape(xc, 256, []);
enct = bsxfun(@xor, t, YourKey(:).');
enct(end-npad+1:end) = [];
EncryptedImage = reshape( enct, size(x));
Evolution
Evolution 2012 年 2 月 9 日
thank a lot for the code .Its really helping me .Just before executing the bsxfun command i checked the values in variable passed in the function.
t has dimensions of 256x589 and yourkey(:).' has 1X256
After executing the function i got the error .
>> enct = bsxfun(@xor, t, r(:).');
??? Error using bsxarg: All non-singleton dimensions must match.
Error in ==> bsxfun at 100
[AX BX] = bsxarg(A,B);
I then swapped the variables
>> enct = bsxfun(@xor,r(:).',t);
??? Error using bsxarg: All non-singleton dimensions must match.
Error in ==> bsxfun at 100
[AX BX] = bsxarg(A,B);
again same error .
if its not too much can you help me with the error ?
thank you again for all the help.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by