How to solve the error in this code??

2 vues (au cours des 30 derniers jours)
Darsana P M
Darsana P M le 8 Nov 2017
Commenté : Darsana P M le 9 Nov 2017
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 commentaires
Darsana P M
Darsana P M le 8 Nov 2017
aesinit(), it is actully a function for aes encryption.
Darsana P M
Darsana P M le 8 Nov 2017
>> size(Xd)
ans =
16 8
Size of(Xd)

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 8 Nov 2017
Modifié(e) : per isakson le 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 commentaire
Darsana P M
Darsana P M le 9 Nov 2017
Thanks a lot. This solved the problem. The problem was with the error used in XOR operation.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Linear Algebra dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by