Click here to Skip to main content
16,012,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI i am a newbee in coding with c#. presently coding RSA-1024 algorithm using BigInteger class from System.Numerics.BigInteger, where now i need a function to generate random prime numbers. i am using visual studio 4.0. i have the BigInteger class but no defintion for the generating prime. i have a function defintion for it, all i need is to add into that BigInteger class in System.Numerics

can anyone help with this
thanks in advance
Posted

1 solution

You cannot directly modify the base Biginteger class.

But, you can create an extension method on this class ; this way:
C#
using System.Numerics;

public static class Extensions
{
   public static int GenerateRandomPrimeNumber(this Biginteger bi)
   {
      // Your logic goes here
   }
}

For the usage:
C#
Biginteger bi = BigInteger.Zero;
int myPrime = bi.GenerateRandomPrimeNumber();


Warning: extension methods work on instances, that's why I had to declare a BigInteger variable to get access to the GetRandomPrimeNumber() extension method. You cannot create a static method on the class itself if you do not have the original source code and can recompile.
 
Share this answer
 
Comments
code_shines 21-Nov-13 4:38am    
thanks a ton. I got the idea now.
phil.o 21-Nov-13 7:46am    
You're welcome :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900