Commit a82d7a83 by adbaga

yes

parent 108dc359
......@@ -18,14 +18,14 @@ namespace CryptoAlgo
do
{
p = g.Next(2, 100);
p = g.Next(100, 500);
} while (!PrimeChecker(p));
var h = new Random();
int q;
do
{
q = h.Next(2, 100);
q = h.Next(100, 500);
} while (!PrimeChecker(q));
Console.WriteLine($"P value: {p}");
......@@ -60,8 +60,8 @@ namespace CryptoAlgo
var d = (1 + k * m) / e;
Console.WriteLine($"d: {d}");
Console.WriteLine($"Public key \n n: {n} e: {e}");
Console.WriteLine($"Private key: p*q = {p}*{q} = {n} d:{d}");
Console.WriteLine($"Public key n: {n} e: {e}");
Console.WriteLine($"Private key: p*q = {p}*{q} ={n} d:{d}");
Console.WriteLine("Plaintext char:");
var plainTextString = Console.ReadLine();
......@@ -73,13 +73,13 @@ namespace CryptoAlgo
var i = 0;
while (i < plainTextString.Length)
{
var plainText = (int) plainTextString[i];
var plainText = (long) plainTextString[i];
table[0, i] = plainText;
var cypher = calcMod(plainText, e, n);
table[1, i] = cypher;
var encrypted = calcMod(plainText, e, n);
table[1, i] = encrypted;
table[2, i] = calcMod(cypher, d, n);
table[2, i] = calcMod(encrypted, d, n);
i++;
}
......@@ -90,7 +90,7 @@ namespace CryptoAlgo
Console.Write($" {table[0,j]}");
}
Console.Write("\nCypher: ");
Console.Write("\nEncrypted: ");
for (var j = 0; j < plainTextString.Length; j++)
{
Console.Write($" {table[1, j]}");
......@@ -117,17 +117,7 @@ namespace CryptoAlgo
y = Divide(n,x);
} while (!PrimeChecker(x) || !PrimeChecker(y) || y==1);
Console.WriteLine("2 Private keys are: X: {0}, Y: {1}", x,y);
}
static int calculateMod(int inputBase, int inputSecret, int inputModulus)
{
var returnMod = 1;
for (var i = 1; i <= inputSecret; ++i)
{
returnMod = (returnMod * inputBase) % inputModulus;
}
return returnMod;
Console.WriteLine("Private keys are: X: {0}, Y: {1}", x,y);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment