How to solve the error in this code??

조회 수: 1 (최근 30일)
Darsana P M
Darsana P M 2017년 11월 8일
댓글: Darsana P M 2017년 11월 9일
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.
Darsana P M
Darsana P M 2017년 11월 8일
>> size(Xd)
ans =
16 8
Size of(Xd)

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

채택된 답변

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