Cod Lab4 SI
Cod Lab4 SI
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace ConsoleApplication21
{
class Program
{
public static double[] time_gen(int initialSize, byte[] plain) {
double[] results = new double[5];
swatch.Start();
swatch.Reset();
swatch.Start();
for (int i = 0; i < count; i++)
{
plain = myrsa.Decrypt(ciphertext, true);
}
swatch.Stop();
Console.WriteLine("Encryption time at " + initialSize + " bits ... " +
(swatch.ElapsedTicks / (10 * count)).ToString() + " ms");
results[2] = (double)(swatch.ElapsedTicks / ((double)count));
swatch.Reset();
swatch.Start();
for (int i = 0; i < count; i++)
{
myrsa.VerifyData(plain, myHash, signature);
}
swatch.Stop();
return results;
}
try
{
optiune = Convert.ToInt16(Console.ReadLine());
}
catch (Exception err)
{
Console.WriteLine("Unknown option. Exiting...");
return;
}
double[] results = null;
switch (optiune)
{
case 1:
results = time_gen(1024,
Encoding.ASCII.GetBytes("myText"));
break;
case 2:
results = time_gen(2048,
Encoding.ASCII.GetBytes("myText"));
break;
case 3:
results = time_gen(3072,
Encoding.ASCII.GetBytes("myText"));
break;
case 4:
results = time_gen(4096,
Encoding.ASCII.GetBytes("myText"));
break;
case 0:
Console.WriteLine("Exiting...");
break;
default:
Console.WriteLine("Unknow Option");
break;
}
if (results != null)
{
Console.WriteLine("Timp generare: " + results[0].ToString());
Console.WriteLine("Timp Criptare: " + results[1].ToString());
Console.WriteLine("Timp Decriptare: " + results[2].ToString());
Console.WriteLine("Timp Semnare: " + results[3].ToString());
Console.WriteLine("Timp Verificare: " + results[4].ToString());
}
} while (optiune != 0);
}
}
}