-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncryptCommand.cs
48 lines (43 loc) · 1.29 KB
/
EncryptCommand.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace RSA
{
class EncryptCommand : Command
{
private PublicKey key;
private RSAEncryptor encryptor;
public void init()
{
initPublicKey();
this.encryptor = new RSAEncryptor(key, new RSAHelper());
}
public void initPublicKey()
{
try
{
Console.WriteLine("To encrypt you must have public key.");
Console.Write("Enter n: ");
BigInteger n = BigInteger.Parse(Console.ReadLine());
Console.Write("Enter e: ");
BigInteger e = BigInteger.Parse(Console.ReadLine());
this.key = new PublicKey(n, e);
}
catch (Exception)
{
Console.WriteLine("Something wrong! Please, retry.\n");
initPublicKey();
}
}
protected override void doExecute()
{
init();
Console.WriteLine("Enter message to encrypt: ");
String message = Console.ReadLine();
Console.WriteLine("Encrypted message:\n" + encryptor.encrypt(message) + "\n");
}
}
}