-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathTool.h
More file actions
34 lines (31 loc) · 934 Bytes
/
MathTool.h
File metadata and controls
34 lines (31 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*@author KN 916267142@qq.com*/
#ifndef MATH_TOOL_H
#define MATH_TOOL_H
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
//This class contain all math tool that RSA can be used.
class Math {
private:
//The number of Miller iteration
ll iteration = 30ll;
public:
//Generates a random number of any specified bit
ll randomDigit(ll num);
//Generates a random prime number of any specified bit
ll randomDigitPrime(ll num);
ll mulmod(ll a, ll b, ll mod);
ll modpow(ll base, ll exponent, ll mod);
//Miller prime test. Judge whether a number is a prime
bool Miller(ll p,ll iteration);
//Extend Euclid to get the inverse
ll modInverse(ll a, ll m);
//Extend Euclid
ll extgcd(ll a, ll b, ll& x, ll& y);
//greatest common divisor
ll gcd(ll a, ll b);
};
#endif // MATH_TOOL_H