Calculating pow(a,b) mod n

后端 未结 14 994
执念已碎
执念已碎 2020-11-22 16:25

I want to calculate ab mod n for use in RSA decryption. My code (below) returns incorrect answers. What is wrong with it?

unsigned long i         


        
14条回答
  •  孤街浪徒
    2020-11-22 17:23

    For my code a^k mod n in php:

    function pmod(a, k, n)
    {
        if (n==1) return 0;
        power = 1;
        for(i=1; i<=k; $i++)
        {
            power = (power*a) % n;
        }
        return power;
    }
    

提交回复
热议问题