How to solve the error in this code??

1 view (last 30 days)
x= {'d9' '31' '32' '25' 'f8' '84' '06' 'e5' 'a5' '59' '09' 'c5' 'af' 'f5' '26' '9a'};
y= {'fe' 'ff' 'e9' '92' '86' '65' '73' '1c' '6d' '6a' '8f' '94' '67' '30' '83' '08'};
X=hex2dec(x);
XX=dec2bin(X);
k=hex2dec(y);
u=aesinit(k);
w=aesencrypt(u,X);
U=dec2bin(w);
Xd = XX - '0'; % Convert CHAR '01' to DOUBLE [0, 1]
Ud = U - '0';
Result = [Ud(:, 1:end-1), xor(Xd, Ud(:, end))]
The error in the above code is:
Error using xor
Matrix dimensions must agree.
Error in counter1 (line 35)
Result = [Ud(:, 1:end-1), xor(Xd, Ud(:, end))]
I would like to find the xor of the encrypted value U and plaintext X??
  3 Comments
Darsana P M
Darsana P M on 8 Nov 2017
aesinit(), it is actully a function for aes encryption.
Darsana P M
Darsana P M on 8 Nov 2017
>> size(Xd)
ans =
16 8
Size of(Xd)

Sign in to comment.

Accepted Answer

per isakson
per isakson on 8 Nov 2017
Edited: per isakson on 9 Nov 2017
The error is caused by
xor( Xd, Ud(:,end) )
The R2017b doc on xor says
Input arrays, specified as scalars, vectors, matrices, or multidimensional arrays.
Inputs A and B must either be the same size or have sizes that are compatible
(for example, A is an M-by-N matrix and B is a scalar or 1-by-N row vector). For
more information, see Compatible Array Sizes for Basic Operations.
Compatible Array Sizes for Basic Operations is rather new. There used to be scalar expansion and the function, bsxfun. Which release do you run?
Replacing the statement that causes the error by
xor( Xd, repmat(Ud(:,end),[1,size(Ud,2)]))
gives a result. However, I don't know whether it's the result you want.
  1 Comment
Darsana P M
Darsana P M on 9 Nov 2017
Thanks a lot. This solved the problem. The problem was with the error used in XOR operation.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!