-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
66 lines (50 loc) · 1.59 KB
/
Program.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");
// innanzitutto occorre implementare fare quadrato modulare
using System;
namespace HomomorphicRSA
{
class RSACrypto
{
static void Main(string[] args)
{
int plaintext = 50;
int modulus = 97;
int exponent = 2;
int currExponent = 0;
int accumulator = 1;
int squareable = 1;
int ciphertext;
// https://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding
Console.WriteLine(Math.Pow(plaintext, exponent) % modulus);
int a = 30;
int b = 19;
while (a > b)
{
a = a - b;
}
Console.WriteLine(a);
squareable = plaintext;
do
{
currExponent = exponent & 1;
if (currExponent > 0)
{
accumulator = accumulator * squareable;// % modulus;
while (accumulator > modulus)
{
accumulator = accumulator - modulus;
}
}
squareable = squareable * squareable;// % modulus;
while (squareable > modulus)
{
squareable = squareable - modulus;
}
exponent = exponent >> 1;
} while (exponent > 0);
ciphertext = accumulator;
Console.WriteLine(ciphertext);
}
}
}