如何将bigint与C#一起使用?
我致力于实现一个密钥算法。但我不能使用2048位的值。我如何使用它如何将bigint与C#一起使用?,c#,biginteger,C#,Biginteger,我致力于实现一个密钥算法。但我不能使用2048位的值。我如何使用它 我想使用大整数。在.NET 4.0中引入了对大整数的本机支持。只需将程序集引用添加到System.Numerics,使用System.Numerics添加声明放在代码文件的顶部,就可以开始了。您要查找的类型是。您可以使用System.Numerics.BigInteger(添加对System.Numerics assembly的引用)。正如评论中提到的,这可能不是正确的方法。在.NET 4.0或更高版本中提供。(如果您使用的是早
我想使用大整数。在.NET 4.0中引入了对大整数的本机支持。只需将程序集引用添加到
System.Numerics
,使用System.Numerics添加代码>声明放在代码文件的顶部,就可以开始了。您要查找的类型是。您可以使用System.Numerics.BigInteger
(添加对System.Numerics assembly的引用)。正如评论中提到的,这可能不是正确的方法。在.NET 4.0或更高版本中提供。(如果您使用的是早期版本的框架)。最好使用System.Numerics.BigInteger
以下是使用BigInteger
。此方法以Fibonacci序列打印最大为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); }
}
publicstaticvoidfibonaccisequence(intn)
{
/**BigInteger很容易保存斐波那契序列中的前1000个数字**/
列表斐波那契=新列表();
斐波那契加法(0);
斐波那契加(1);
大整数i=2;
而(i
通常RSA密钥算法一次工作8位。您的密钥将放置在一个具有8个索引的字节数组中。不重复。ı不希望使用long或int64。它们对我来说还不够,大整数才是出路。次要说明:它仅在.NET4.0及更高版本中可用。