How to solve the error in this code??

2 次查看(过去 30 天)
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 个评论
Darsana P M
Darsana P M 2017-11-8
aesinit(), it is actully a function for aes encryption.

请先登录,再进行评论。

采纳的回答

per isakson
per isakson 2017-11-8
编辑:per isakson 2017-11-9
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 个评论
Darsana P M
Darsana P M 2017-11-9
Thanks a lot. This solved the problem. The problem was with the error used in XOR operation.

请先登录,再进行评论。

更多回答(0 个)

类别

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