-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRSAalgorithm.cs
More file actions
51 lines (44 loc) · 1.24 KB
/
RSAalgorithm.cs
File metadata and controls
51 lines (44 loc) · 1.24 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Filtermap
{
class RSAalgorithm
{
public static long square(long a)
{
return (a * a);
}
public static long BigMod(int b, int p, int m) //b^p%m=?
{
if (p == 0)
return 1;
else if (p % 2 == 0)
return square(BigMod(b, p / 2, m)) % m;
else
return ((b % m) * BigMod(b, p - 1, m)) % m;
}
public static int n_value(int prime1, int prime2)
{
return (prime1 * prime2);
}
public static int cal_phi(int prime1, int prime2)
{
return ((prime1 - 1) * (prime2 - 1));
}
public static Int32 cal_privateKey(int phi, int e, int n)
{
int d = 0;
int RES = 0;
for (d = 1; ; d++)
{
RES = (d * e) % phi;
if (RES == 1) break;
}
return d;
}
}
}