The encryption method of RSA public key is a^b%c; when a/b value is large, it is difficult to evaluate directly, so there are the following algorithms:
1: Use the formula (A*B)%c= ((a%c) *b)%c to process each step, as the formula shows ... This algorithm only handles the problem that the data is too big, the time is still not solved.
The code is as follows:
void Mmode () { int temp=b; Long long res=1; while (temp--) { res=res*a%c; } cout<<res<<Endl;}
2: Fast power modulus algorithm, using the binary method optimization, will be replaced each time res*a res*a^2 optimization time complexity of O (LOGN)
The code is as follows:
void X_mmode () { long long res=1 ; long long temp=a; while (B!=0 2 ==1 ) res =res*temp%c; b /=2 =temp*temp%C; } cout <<res<<endl;}
The above is the study of the power-taking modulus algorithm
2016.4.19
Fast power-take modulus algorithm