13

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.

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
asked May 16, 2012 at 18:52
2
  • 1
    Usually RSA key algorithms work on 8 bits at a time. Your key would be placed in a byte array with 8 indexes. Commented May 16, 2012 at 18:54
  • 1
    not duplicate. ı do not want to use long or int64. they do not enough for me Commented May 16, 2012 at 18:54

5 Answers 5

31

You can use System.Numerics.BigInteger (add a reference to System.Numerics assembly). As mentioned in the comments this might not be the right approach though.

answered May 16, 2012 at 18:56

1 Comment

Indeed, BigInteger is the way to go. Minor note: it's only available in .NET 4.0 and higher.
10

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); }
}
AeroX
3,4732 gold badges28 silver badges40 bronze badges
answered Jan 3, 2013 at 16:00

Comments

8

Native support for big integers has been introduced in .NET 4.0. Just add an assembly reference to System.Numerics, add a using System.Numerics; declaration at the top of your code file, and you’re good to go. The type you’re after is BigInteger.

answered May 16, 2012 at 18:55

Comments

3

BigInteger is available in .NET 4.0 or later. There are some third-party implementations as well (In case you are using an earlier version of the framework).

answered May 16, 2012 at 18:56

Comments

1

Better use System.Numerics.BigInteger.

Peter Mortensen
31.5k22 gold badges110 silver badges134 bronze badges
answered May 16, 2012 at 19:10

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.