当前位置: 首页>>代码示例>>Java>>正文


Java BigIntUtils类代码示例

本文整理汇总了Java中org.bouncycastle.pqc.math.linearalgebra.BigIntUtils的典型用法代码示例。如果您正苦于以下问题:Java BigIntUtils类的具体用法?Java BigIntUtils怎么用?Java BigIntUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BigIntUtils类属于org.bouncycastle.pqc.math.linearalgebra包,在下文中一共展示了BigIntUtils类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import org.bouncycastle.pqc.math.linearalgebra.BigIntUtils; //导入依赖的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.BigIntUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。