本文整理汇总了Java中org.bouncycastle.pqc.math.linearalgebra.IntegerFunctions类的典型用法代码示例。如果您正苦于以下问题:Java IntegerFunctions类的具体用法?Java IntegerFunctions怎么用?Java IntegerFunctions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IntegerFunctions类属于org.bouncycastle.pqc.math.linearalgebra包,在下文中一共展示了IntegerFunctions类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encode
import org.bouncycastle.pqc.math.linearalgebra.IntegerFunctions; //导入依赖的package包/类
/**
* Encode a number between 0 and (n|t) (binomial coefficient) into a binary
* vector of length n with weight t. The number is given as a byte array.
* Only the first s bits are used, where s = floor[log(n|t)].
*
* @param n integer
* @param t integer
* @param m the message as a byte array
* @return the encoded message as {@link GF2Vector}
*/
public static GF2Vector encode(final int n, final int t, final byte[] m)
{
if (n < t)
{
throw new IllegalArgumentException("n < t");
}
// compute the binomial c = (n|t)
BigInteger c = IntegerFunctions.binomial(n, t);
// get the number encoded in m
BigInteger i = new BigInteger(1, m);
// compare
if (i.compareTo(c) >= 0)
{
throw new IllegalArgumentException("Encoded number too large.");
}
GF2Vector result = new GF2Vector(n);
int nn = n;
int tt = t;
for (int j = 0; j < n; j++)
{
c = c.multiply(BigInteger.valueOf(nn - tt)).divide(
BigInteger.valueOf(nn));
nn--;
if (c.compareTo(i) <= 0)
{
result.setBit(j);
i = i.subtract(c);
tt--;
if (nn == tt)
{
c = ONE;
}
else
{
c = (c.multiply(BigInteger.valueOf(tt + 1)))
.divide(BigInteger.valueOf(nn - tt));
}
}
}
return result;
}
开发者ID:Appdome,项目名称:ipack,代码行数:56,代码来源:Conversions.java
示例2: decode
import org.bouncycastle.pqc.math.linearalgebra.IntegerFunctions; //导入依赖的package包/类
/**
* Decode a binary vector of length n and weight t into a number between 0
* and (n|t) (binomial coefficient). The result is given as a byte array of
* length floor[(s+7)/8], where s = floor[log(n|t)].
*
* @param n integer
* @param t integer
* @param vec the binary vector
* @return the decoded vector as a byte array
*/
public static byte[] decode(int n, int t, GF2Vector vec)
{
if ((vec.getLength() != n) || (vec.getHammingWeight() != t))
{
throw new IllegalArgumentException(
"vector has wrong length or hamming weight");
}
int[] vecArray = vec.getVecArray();
BigInteger bc = IntegerFunctions.binomial(n, t);
BigInteger d = ZERO;
int nn = n;
int tt = t;
for (int i = 0; i < n; i++)
{
bc = bc.multiply(BigInteger.valueOf(nn - tt)).divide(
BigInteger.valueOf(nn));
nn--;
int q = i >> 5;
int e = vecArray[q] & (1 << (i & 0x1f));
if (e != 0)
{
d = d.add(bc);
tt--;
if (nn == tt)
{
bc = ONE;
}
else
{
bc = bc.multiply(BigInteger.valueOf(tt + 1)).divide(
BigInteger.valueOf(nn - tt));
}
}
}
return BigIntUtils.toMinimalByteArray(d);
}
开发者ID:Appdome,项目名称:ipack,代码行数:51,代码来源:Conversions.java
注:本文中的org.bouncycastle.pqc.math.linearalgebra.IntegerFunctions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论