Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use bigint with C#?

Tags:

c#

biginteger

I work to implement an RSA key algorithm. But I couldn't use a 2048-bit value. How I can use it?

I want to use big integer.

like image 750
Ersin Gülbahar Avatar asked May 16 '12 18:05

Ersin Gülbahar


1 Answers

Here's using BigInteger. This method Prints Numbers in the Fibonacci Sequence up to n.

public static void FibonacciSequence(int n)
{
    /** BigInteger easily holds the first 1000 numbers in the Fibonacci Sequence. **/
    List<BigInteger> fibonacci = new List<BigInteger>();
    fibonacci.Add(0);
    fibonacci.Add(1);
    BigInteger i = 2;
    while(i < n)
    {                
        int first = (int)i - 2;
        int second = (int) i - 1;

        BigInteger firstNumber =  fibonacci[first];
        BigInteger secondNumber = fibonacci[second];
        BigInteger sum = firstNumber + secondNumber;
        fibonacci.Add(sum);
        i++;
    }         

    foreach (BigInteger f in fibonacci) { Console.WriteLine(f); }
}
like image 84
Sunil Chandurkar Avatar answered Oct 02 '22 00:10

Sunil Chandurkar