Image and Key XORing
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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
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));
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!