Error with my square and multiply algorithm

9 次查看(过去 30 天)
So basically I have to implement a 32-bit version of RSA. However there's a problem with the SaM algorithm, which is the following:
function result = SquareAndMultiply(exponent,basis,modulus)
result = 1;
while exponent>0
if mod(exponent,2)==1
result = mod(result.*basis, modulus);
end
basis = mod(basis.*basis, modulus);
exponent = fix(exponent/2);
end
end
It shows that the encrypted message I decrypted is not equal to the original message, which began when the primes are 14 bits in size (before if it's 13 bits or less it works fine), which makes the modulus be 28 bits in size.
Anyone knows what happened here?
EDIT: It seems the value of n plays a role here.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by