本文整理汇总了C#中Mono.Math.BigInteger类的典型用法代码示例。如果您正苦于以下问题:C# BigInteger类的具体用法?C# BigInteger怎么用?C# BigInteger使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BigInteger类属于Mono.Math命名空间,在下文中一共展示了BigInteger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DSAPrivateKeySpec
public DSAPrivateKeySpec (BigInteger x, BigInteger p, BigInteger q, BigInteger g)
{
this.x = x;
this.p = p;
this.q = q;
this.g = g;
}
示例2: Bitwise_Base
public Bitwise_Base()
{
N = new BigInteger(n);
expectedNls = new BigInteger(ExpectedNLeftShift);
expectedNrs = new BigInteger(ExpectedNRightShift);
shiftAmount = ShiftAmount;
}
示例3: ModPow_0_Even
public void ModPow_0_Even ()
{
BigInteger x = new BigInteger (1);
BigInteger y = new BigInteger (0);
BigInteger z = x.ModPow (y, 1024);
Assert.AreEqual ("1", z.ToString (), "1 pow 0 == 1");
}
示例4: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType != JsonToken.String) { return null; }
var decrypted = (MCrypto)base.ReadJson(reader, objectType, existingValue, serializer);
var rsa_privk = new BigInteger[4];
var bytes = decrypted.Value;
int startindex = 0;
for (var i = 0; i < 4; i++)
{
var l = ((bytes[startindex + 0] * 256 + bytes[startindex + 1] + 7) >> 3) + 2;
rsa_privk[i] = Converter.MpiToBigInt(bytes, startindex, l);
startindex += l;
}
if (bytes.Length - startindex < 16)
{
return new RSAKey
{
P = rsa_privk[0],
Q = rsa_privk[1],
D = rsa_privk[2],
U = rsa_privk[3],
N = BigInteger.Multiply(rsa_privk[0], rsa_privk[1])
};
}
else return null;
}
示例5: DSAPublicKeySpec
public DSAPublicKeySpec (BigInteger y, BigInteger p, BigInteger q, BigInteger g)
{
this.y = y;
this.p = p;
this.q = q;
this.g = g;
}
示例6: Main
static void Main(string[] args)
{
Datacenter datacenterController = new Datacenter();
var i = new BigInteger(8798782624624);
Console.WriteLine(i);
Console.ReadLine();
}
示例7: BarrettReduction
public void BarrettReduction(BigInteger x)
{
var n = mod;
uint k = n.length,
kPlusOne = k + 1,
kMinusOne = k - 1;
// x < mod, so nothing to do.
if (x.length < k) return;
BigInteger q3;
//
// Validate pointers
//
if (x.data.Length < x.length) throw new IndexOutOfRangeException("x out of range");
// q1 = x / b^ (k-1)
// q2 = q1 * constant
// q3 = q2 / b^ (k+1), Needs to be accessed with an offset of kPlusOne
// TODO: We should the method in HAC p 604 to do this (14.45)
q3 = new BigInteger(Sign.Positive, x.length - kMinusOne + constant.length);
Kernel.Multiply(x.data, kMinusOne, x.length - kMinusOne, constant.data, 0, constant.length, q3.data, 0);
// r1 = x mod b^ (k+1)
// i.e. keep the lowest (k+1) words
var lengthToCopy = x.length > kPlusOne ? kPlusOne : x.length;
x.length = lengthToCopy;
x.Normalize();
// r2 = (q3 * n) mod b^ (k+1)
// partial multiplication of q3 and n
var r2 = new BigInteger(Sign.Positive, kPlusOne);
Kernel.MultiplyMod2p32pmod(q3.data, (int) kPlusOne, (int) q3.length - (int) kPlusOne, n.data, 0,
(int) n.length, r2.data, 0, (int) kPlusOne);
r2.Normalize();
if (r2 <= x)
{
Kernel.MinusEq(x, r2);
}
else
{
var val = new BigInteger(Sign.Positive, kPlusOne + 1);
val.data[kPlusOne] = 0x00000001;
Kernel.MinusEq(val, r2);
Kernel.PlusEq(x, val);
}
while (x >= n)
Kernel.MinusEq(x, n);
}
示例8: SignedBigInteger
public SignedBigInteger(long a)
{
if (a < 0)
{
this.Negative = true;
a *= -1;
}
this.Number = new BigInteger((ulong)a);
}
示例9: WikipediaSanityChecks
public void WikipediaSanityChecks()
{
// http://en.wikipedia.org/wiki/RSA on 25 May 2009
var c = new BigInteger(855);
var d = new BigInteger(2753);
var n = new BigInteger(3233);
var m = c.ModPow(d, n);
Assert.AreEqual("123", m.ToString());
}
示例10: GenerateKeyPair
private void GenerateKeyPair()
{
// p and q values should have a length of half the strength in bits
int pbitlength = ((KeySize + 1) >> 1);
int qbitlength = (KeySize - pbitlength);
const uint uint_e = 17;
e = uint_e; // fixed
// generate p, prime and (p-1) relatively prime to e
for (; ; )
{
p = BigInteger.GeneratePseudoPrime(pbitlength);
if (p % uint_e != 1)
break;
}
// generate a modulus of the required length
for (; ; )
{
// generate q, prime and (q-1) relatively prime to e,
// and not equal to p
for (; ; )
{
q = BigInteger.GeneratePseudoPrime(qbitlength);
if ((q % uint_e != 1) && (p != q))
break;
}
// calculate the modulus
n = p * q;
if (n.BitCount() == KeySize)
break;
// if we get here our primes aren't big enough, make the largest
// of the two p and try again
if (p < q)
p = q;
}
BigInteger pSub1 = (p - 1);
BigInteger qSub1 = (q - 1);
BigInteger phi = pSub1 * qSub1;
// calculate the private exponent
d = e.ModInverse(phi);
// calculate the CRT factors
dp = d % pSub1;
dq = d % qSub1;
qInv = q.ModInverse(p);
keypairGenerated = true;
isCRTpossible = true;
if (KeyGenerated != null)
KeyGenerated(this, null);
}
示例11: ModRing_Base
public ModRing_Base()
{
A = new BigInteger( a );
B = new BigInteger( b );
N = new BigInteger( n );
abModN = new BigInteger( ExpectedABmodN );
aPowBmodN = new BigInteger( ExpectedApowBmodN );
mr = new BigInteger.ModulusRing(N);
}
示例12: PublicKeyOperation
/// <summary>
/// Performs the RSA operation Result = <paramref name="message"/>^<paramref name="exponent"/> (mod <paramref name="modulus"/>).
/// </summary>
/// <param name="message">The message to perform the operation on.</param>
/// <param name="exponent">The exponent value to raise the message by.</param>
/// <param name="modulus">The modulus to divide the results by.</param>
/// <returns>The value C, such that C = <paramref name="message"/>^<paramref name="exponent"/> (mod <paramref name="modulus"/>).</returns>
public static byte[] PublicKeyOperation(byte[] message, byte[] exponent, byte[] modulus)
{
var m = new BigInteger(message);
var e = new BigInteger(exponent);
var n = new BigInteger(modulus);
var c = m.ModPow(e, n);
var resultBytes = c.GetBytes();
return resultBytes;
}
示例13: DefaultRandom
public void DefaultRandom ()
{
// based on bugzilla entry #68452
BigInteger bi = new BigInteger ();
Assert.AreEqual (0, bi.BitCount (), "before randomize");
bi.Randomize ();
// Randomize returns a random number of BitCount length
// so in this case it will ALWAYS return 0
Assert.AreEqual (0, bi.BitCount (), "after randomize");
Assert.AreEqual (new BigInteger (0), bi, "Zero");
}
示例14: Power
public static BigInteger Power(this BigInteger a, BigInteger b)
{
BigInteger value = 1;
for (BigInteger count = 0; count < b; count += 1)
{
value *= a;
}
return value;
}
示例15: ModulusRing
public ModulusRing(BigInteger modulus)
{
mod = modulus;
// calculate constant = b^ (2k) / m
var i = mod.length << 1;
constant = new BigInteger(Sign.Positive, i + 1);
constant.data[i] = 0x00000001;
constant = constant/mod;
}