patterncsharpMinor
RSA calculating e in C#
Viewed 0 times
calculatingrsastackoverflow
Problem
I would like the have a second opinion on my code I've written to calculate
ee is an integer that you wherefore the following counts gcd(φ(n),e) = 1 with 1 < e < φ(n)public int calce()
{
do
{
e = priemgen.newKey(1, euler);
} while (GCD(euler, e) != 1);
return e;
}
private int GCD(int value1, int value2)
{
while (value1 != 0 && value2 != 0)
{
if (value1 > value2)
{
value1 %= value2;
}
else
value2 %= value1;
}
return Math.Max(value1, value2);
}
private int NewPrime(int lowerbound, int upperbound)
{
return priemgen.newKey(lowerbound, upperbound);
}Solution
There is not a huge amount of code to review here, just a few things:
-
You have a method
-
Braces are used inconsistently:
Should be same as the if block:
-
The naming conventions are inconsistent. Standard naming convention for C# for methods and fields is
-
If
-
What does
-
You have a method
NewPrime which I assume provides a prime number between the two bounds provided. Yet you do not use it and call priemgen.newKey directly in calce. You should either get rid of the wrapper method or use it consistently.-
Braces are used inconsistently:
else
value2 %= value1;Should be same as the if block:
else
{
value2 %= value1;
}-
The naming conventions are inconsistent. Standard naming convention for C# for methods and fields is
PascalCase and local variables and parameters are camelCase:calce->CalculateE
newKeyonpriemgenshould beNewKey
priemgen- I assume it's a field so should bePrimGenerator
lowerbound->lowerBound
upperbound->upperBound
GCD->Gcd
-
If
priemgen is what it sounds like then the name for nextKey should be NextPrime.-
What does
priemgen.newKey return if there is no prime within the given bounds?Code Snippets
else
value2 %= value1;else
{
value2 %= value1;
}Context
StackExchange Code Review Q#36726, answer score: 5
Revisions (0)
No revisions yet.