Error with my square and multiply algorithm

9 ビュー (過去 30 日間)
Silverhawke
Silverhawke 2012 年 11 月 2 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by