本文整理汇总了C#中BigInteger类的典型用法代码示例。如果您正苦于以下问题:C# BigInteger类的具体用法?C# BigInteger怎么用?C# BigInteger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BigInteger类属于命名空间,在下文中一共展示了BigInteger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Console.Write("vavedi N:");
int numberN = int.Parse(Console.ReadLine());
Console.Write("vavedi K:");
int numberK = int.Parse(Console.ReadLine());
if (numberN > 1 && numberK > numberN)
{
var factorialN = new BigInteger(1);
for (var i = 1; i <= numberN; i++)
{
factorialN *= i;
}
Console.WriteLine("Factorial n = {0}", factorialN);
var factorialK = new BigInteger(1);
for (var j = 1; j <= numberK; j++)
{
factorialK *= j;
}
Console.WriteLine("Factorial k = {0}", factorialK);
var nAndK = new BigInteger(1);
nAndK = factorialN/factorialK;
Console.WriteLine("N!/K!={0}", nAndK);
}
else
{
Console.WriteLine("N > 1 and K > N");
}
}
示例2: RsaPublicBcpgKey
/// <param name="n">The modulus.</param>
/// <param name="e">The public exponent.</param>
public RsaPublicBcpgKey(
BigInteger n,
BigInteger e)
{
this.n = new MPInteger(n);
this.e = new MPInteger(e);
}
示例3: IsPrime
static bool IsPrime(BigInteger n)
{
bool isPrime = true;
if(n==0||n==1)
{
return false;
}
else if(n==2||n==3)
{
return true;
}
else if(n<100&&n>3)
{
for(int s=2;s<n;s++)
{
if (n % s == 0)
isPrime = false;
}
return isPrime;
}
else
{
for (BigInteger i = 3; (i * i) <= n; i+=2)
{
if (n%i==0)
{
isPrime = false;
break;
}
}
return isPrime;
}
}
示例4: GenerateSearchBase
protected override BigInteger GenerateSearchBase (int bits, object Context)
{
if (Context == null) throw new ArgumentNullException ("Context");
BigInteger ret = new BigInteger ((BigInteger)Context);
ret.setBit (0);
return ret;
}
示例5: ShamirsTrick
/*
* "Shamir's Trick", originally due to E. G. Straus
* (Addition chains of vectors. American Mathematical Monthly,
* 71(7):806-808, Aug./Sept. 1964)
*
* Input: The points P, Q, scalar k = (km?, ... , k1, k0)
* and scalar l = (lm?, ... , l1, l0).
* Output: R = k * P + l * Q.
* 1: Z <- P + Q
* 2: R <- O
* 3: for i from m-1 down to 0 do
* 4: R <- R + R {point doubling}
* 5: if (ki = 1) and (li = 0) then R <- R + P end if
* 6: if (ki = 0) and (li = 1) then R <- R + Q end if
* 7: if (ki = 1) and (li = 1) then R <- R + Z end if
* 8: end for
* 9: return R
*/
public static ECPoint ShamirsTrick(ECPoint p, BigInteger k, ECPoint q, BigInteger l)
{
if (!p.Curve.Equals(q.Curve))
throw new ArgumentException("P and Q must be on same curve");
return ImplShamirsTrick(p, k, q, l);
}
示例6: SetupCrypto
public void SetupCrypto(BigInteger key)
{
byte[] ServerDecryptionKey =
{
0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5,
0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE
};
byte[] ServerEncryptionKey =
{
0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA,
0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57
};
HMACSHA1 decryptHMAC = new HMACSHA1(ServerDecryptionKey);
HMACSHA1 encryptHMAC = new HMACSHA1(ServerEncryptionKey);
var decryptHash = decryptHMAC.ComputeHash(key.GetBytes());
var encryptHash = encryptHMAC.ComputeHash(key.GetBytes());
const int dropN = 1024; //1000 before WoTLK, 1024 now
var buf = new byte[dropN];
ClientConnection.Decrypt = new ARC4(decryptHash);
ClientConnection.Encrypt = new ARC4(encryptHash);
ClientConnection.Decrypt.Process(buf, 0, buf.Length);
ClientConnection.Encrypt.Process(buf, 0, buf.Length);
}
示例7: AdditionIsCommutative
public void AdditionIsCommutative()
{
var a = new BigInteger("2342452452435235098091834098018");
var b = new BigInteger("102938209095450980895402985098560727234098123345");
Assert.AreEqual(a + b, b + a);
}
示例8: SetPublic
public void SetPublic(string modulus, string exponent)
{
if (string.IsNullOrEmpty(modulus) || string.IsNullOrEmpty(exponent))
throw new Exception("Invalid RSA public key");
Modulus = new BigInteger(modulus, 16);
Exponent = new BigInteger(exponent, 16);
}
示例9: CalculateScore
private static BigInteger CalculateScore(int heigth, int width, int[] moves, BigInteger[][] matrix)
{
BigInteger sumVisited = 0;
int coeficient = Math.Max(heigth, width);
int posX = 0;
int posY = heigth - 1;
for (int i = 0; i < moves.GetLength(0); i++)
{
int moveToX = moves[i] % coeficient;
int moveToY = moves[i] / coeficient;
int walkXFrom = Math.Min(moveToX, posX);
int walkXTo = Math.Max(moveToX, posX);
for (int j = walkXFrom; j <= walkXTo; j++)
{
sumVisited += matrix[posY][j];
matrix[posY][j] = 0;
}
posX = moveToX;
int walkYFrom = Math.Min(moveToY, posY);
int walkYTo = Math.Max(moveToY, posY);
for (int j = walkYFrom; j <= walkYTo; j++)
{
sumVisited += matrix[j][posX];
matrix[j][posX] = 0;
}
posY = moveToY;
}
return sumVisited;
}
示例10: BitCount
/// <summary>
/// Returns the number of bits in the binary representation of this which differ from the sign bit.
/// <para>Use BitLength(0) if you want to know the length of the binary value in bits.
/// If this is positive the result is equivalent to the number of bits set in the binary representation of this.
/// If this is negative the result is equivalent to the number of bits set in the binary representation of -this - 1.</para>
/// </summary>
internal static int BitCount(BigInteger Value)
{
int bCount = 0;
if (Value._sign == 0)
return 0;
int i = Value.FirstNonzeroDigit; ;
if (Value._sign > 0)
{
for (; i < Value._numberLength; i++)
bCount += IntUtils.BitCount(Value._digits[i]);
}
else
{
// this digit absorbs the carry
bCount += IntUtils.BitCount(-Value._digits[i]);
for (i++; i < Value._numberLength; i++)
bCount += IntUtils.BitCount(~Value._digits[i]);
// We take the complement sum:
bCount = (Value._numberLength << 5) - bCount;
}
return bCount;
}
示例11: Main
static void Main()
{
Console.WriteLine("How many digits will contain the first number ?");
int lengthOne = int.Parse(Console.ReadLine());
BigInteger[] numberOne = new BigInteger[lengthOne];
Console.WriteLine("Enter the digits of the number");
for (int i = lengthOne - 1; i > -1; i--)
{
numberOne[i] = BigInteger.Parse(Console.ReadLine());
}
Console.WriteLine("How many digits will contain the second number ?");
int lengthTwo = int.Parse(Console.ReadLine());
BigInteger[] numberTwo = new BigInteger[lengthTwo];
Console.WriteLine("Enter the digits of the number");
for (int i = lengthTwo - 1; i > -1; i--)
{
numberTwo[i] = BigInteger.Parse(Console.ReadLine());
}
BigInteger[] sum = SumNumber(numberOne, numberTwo);
Console.WriteLine();
foreach (BigInteger i in sum)
{
Console.Write(i);
}
}
示例12: DHParameters
public DHParameters(
BigInteger p,
BigInteger g,
BigInteger q)
: this(p, g, q, 0)
{
}
示例13: CheckNumForNull
private static void CheckNumForNull(BigInteger[] array, int targetIndex)
{
if (array[targetIndex] < 0)
{
array[targetIndex] = 0;
}
}
示例14: Multiply
/**
* D.3.2 pg 101
* @see org.bouncycastle.math.ec.multiplier.ECMultiplier#multiply(org.bouncycastle.math.ec.ECPoint, java.math.BigInteger)
*/
public ECPoint Multiply(ECPoint p, BigInteger k, PreCompInfo preCompInfo)
{
// TODO Probably should try to add this
// BigInteger e = k.Mod(n); // n == order of p
BigInteger e = k;
BigInteger h = e.Multiply(BigInteger.Three);
ECPoint neg = p.Negate();
ECPoint R = p;
for (int i = h.BitLength - 2; i > 0; --i)
{
R = R.Twice();
bool hBit = h.TestBit(i);
bool eBit = e.TestBit(i);
if (hBit != eBit)
{
R = R.Add(hBit ? p : neg);
}
}
return R;
}
示例15: ArrToNumber
//converts an array, whose index 0 is the last digit of a number, to the number.
static BigInteger ArrToNumber(BigInteger[] arr)
{
Array.Reverse(arr);
string numberString = string.Join("", arr);
BigInteger result = BigInteger.Parse(numberString);
return result;
}