Calculating pow(a,b) mod n

后端 未结 14 1145
执念已碎
执念已碎 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:25

    #include 
    ...
    static_cast(std::pow(a,b))%n
    

    but my best bet is you are overflowing int (IE: the number is two large for the int) on the power I had the same problem creating the exact same function.

提交回复
热议问题