本文整理汇总了C#中Org.BouncyCastle.Math.BigInteger.DivideAndRemainder方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.DivideAndRemainder方法的具体用法?C# BigInteger.DivideAndRemainder怎么用?C# BigInteger.DivideAndRemainder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Math.BigInteger
的用法示例。
在下文中一共展示了BigInteger.DivideAndRemainder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: H1hash
public static BigInteger H1hash(string ID, BigInteger p)
{
// H1 je sha256(ID) mod p
SHA256Managed crypt = new SHA256Managed();
StringBuilder hash = new StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(ID), 0, Encoding.UTF8.GetByteCount(ID));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
BigInteger hsh = new BigInteger(hash.ToString(), 16);
// hash mod p
BigInteger x = hsh.DivideAndRemainder(p)[1];
return x;
}
示例2: H2hash
public static string H2hash(BigInteger qid, BigInteger p)
{
// H2 je RiPEMD-120: točka iz polja -> niz bita mod p
string tocka = qid.ToString();
RIPEMD160Managed crypt = new RIPEMD160Managed();
StringBuilder hash = new StringBuilder();
byte[] crypto = crypt.ComputeHash(Encoding.UTF8.GetBytes(tocka), 0, Encoding.UTF8.GetByteCount(tocka));
foreach (byte theByte in crypto)
{
hash.Append(theByte.ToString("x2"));
}
BigInteger hsh = new BigInteger(hash.ToString(), 16);
// hash mod n
BigInteger c = hsh.DivideAndRemainder(p)[1];
return c.ToString();
}
示例3: Encode
public string Encode(byte[] input)
{
// Decode byte[] to BigInteger
BigInteger intData=new BigInteger(1,input);
// Encode BigInteger to Base string
string result=string.Empty;
while(intData.CompareTo(0)>0)
{
BigInteger[] divide=intData.DivideAndRemainder(Base);
intData=divide[0];
result=Alphabet[divide[1].IntValue]+result;
}
// Append `1` for each leading 0 byte
for(int i=0;i<input.Length && input[i]==0;i++)
{ result=Alphabet[0]+result; }
return result;
}
示例4: TestDivideAndRemainder
public void TestDivideAndRemainder()
{
// TODO More basic tests
BigInteger n = new BigInteger(48, random);
BigInteger[] qr = n.DivideAndRemainder(one);
Assert.AreEqual(n, qr[0]);
Assert.AreEqual(zero, qr[1]);
for (int rep = 0; rep < 10; ++rep)
{
BigInteger a = new BigInteger(100 - rep, 0, random);
BigInteger b = new BigInteger(100 + rep, 0, random);
BigInteger c = new BigInteger(10 + rep, 0, random);
BigInteger d = a.Multiply(b).Add(c);
BigInteger[] es = d.DivideAndRemainder(a);
Assert.AreEqual(b, es[0]);
Assert.AreEqual(c, es[1]);
}
// Special tests for power of two since uses different code path internally
for (int i = 0; i < 100; ++i)
{
int shift = random.Next(64);
BigInteger a = one.ShiftLeft(shift);
BigInteger b = new BigInteger(64 + random.Next(64), random);
BigInteger bShift = b.ShiftRight(shift);
BigInteger bMod = b.And(a.Subtract(one));
string data = "shift=" + shift +", b=" + b.ToString(16);
qr = b.DivideAndRemainder(a);
Assert.AreEqual(bShift, qr[0], data);
Assert.AreEqual(bMod, qr[1], data);
qr = b.DivideAndRemainder(a.Negate());
Assert.AreEqual(bShift.Negate(), qr[0], data);
Assert.AreEqual(bMod, qr[1], data);
qr = b.Negate().DivideAndRemainder(a);
Assert.AreEqual(bShift.Negate(), qr[0], data);
Assert.AreEqual(bMod.Negate(), qr[1], data);
qr = b.Negate().DivideAndRemainder(a.Negate());
Assert.AreEqual(bShift, qr[0], data);
Assert.AreEqual(bMod.Negate(), qr[1], data);
}
}