Error with my square and multiply algorithm

8 views (last 30 days)
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.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!