I am getting this error: Error using * MTIMES (*) is not fully supported for integer classes. At least one argument must be scalar. Error in RSA (line 4) n =p*q;
16 次查看(过去 30 天)
显示 更早的评论
%Input value of p and q
p =input('\nValue of p: ');
q =input('\nValue of q: ');
n =p*q;%Calculate value of n
tf=(p-1)*(q-1);%Calculate value of totien function
%Calculate the value of e
x=2;e=1;
while x > 1
e=e+1;
x=gcd(tf,e);%Search greatest common division
end
%Calculate the value of d
i=1;
d=0;
e=7;
while i > 0
d = d+1;
x = e*d;
x = mod(x,tf);
if x == 1
i = 0;
end
end
P = input('\nInput text: ','s');
c = double(P);
disp('Text: ');
disp(P);
disp(e);
disp(d);
disp('Ascii Text: ');
disp(c);
%Encrypt
%cipher= power(c,e);
%cipher= mod(cipher,n);
cipher=powermod (c, e, n);
disp('cipher: ');
disp(cipher);
%Decrypt
%plain= power(cipher,d);
%plain= mod(plain,n);
plain=powermod (cipher, d, n);
disp('decrypt: ');
disp(plain);
disp('Inputted Text: ');
disp(char(plain));%Convert double to char
0 个评论
回答(1 个)
Walter Roberson
2020-2-21
somehow you are entering integer data-type arrays in response the prompts for p and q. For example you might be naming variables that store the data in response to the prompts. If you are working with image encryption then your variables would be likely to be uint8.
You are trying to use the * operator between two integer data-type arrays. The * operator is the algebraic matrix multiplication operator ("inner product"), not the element-by-element multiplication operators. The * operator is not supported between two arrays that are integer data-type .
The work-around would be:
n = cast(double(p)*double(q), class(p));
However, in context I think your code is expecting you to enter scalar values in response to the two prompts, so you should explore more how whatever response you are making to the prompts is getting interpreted as designating integer arrays.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!