本文整理汇总了Java中org.bouncycastle.util.Arrays.copyOf方法的典型用法代码示例。如果您正苦于以下问题:Java Arrays.copyOf方法的具体用法?Java Arrays.copyOf怎么用?Java Arrays.copyOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.Arrays
的用法示例。
在下文中一共展示了Arrays.copyOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sub
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Subtracts another polynomial which can have a different number of coefficients.
*
* @param b another polynomial
*/
public void sub(BigIntPolynomial b)
{
if (b.coeffs.length > coeffs.length)
{
int N = coeffs.length;
coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
for (int i = N; i < coeffs.length; i++)
{
coeffs[i] = Constants.BIGINT_ZERO;
}
}
for (int i = 0; i < b.coeffs.length; i++)
{
coeffs[i] = coeffs[i].subtract(b.coeffs[i]);
}
}
示例2: unpadBody
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public static byte[] unpadBody(byte[] body) {
int ind = body.length - 1;
while (body[ind] == (byte) 0xFF && ind > 0) {
ind--;
}
if (body[ind] == (byte) 0x7F) {
return Arrays.copyOf(body, ind);
} else {
return new byte[0];
}
}
示例3: getAesKey
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] getAesKey(ECPoint s) {
return Arrays.copyOf(
sha256.digest(
Arrays.concatenate(
"aes_key:".getBytes(Charset.forName("UTF-8")),
group.printable(s)
)
), this.k);
}
示例4: SparseTernaryPolynomial
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Constructs a new <code>SparseTernaryPolynomial</code> with a given set of coefficients.
*
* @param coeffs the coefficients
*/
public SparseTernaryPolynomial(int[] coeffs)
{
N = coeffs.length;
ones = new int[N];
negOnes = new int[N];
int onesIdx = 0;
int negOnesIdx = 0;
for (int i = 0; i < N; i++)
{
int c = coeffs[i];
switch (c)
{
case 1:
ones[onesIdx++] = i;
break;
case -1:
negOnes[negOnesIdx++] = i;
break;
case 0:
break;
default:
throw new IllegalArgumentException("Illegal value: " + c + ", must be one of {-1, 0, 1}");
}
}
ones = Arrays.copyOf(ones, onesIdx);
negOnes = Arrays.copyOf(negOnes, negOnesIdx);
}
示例5: toBinary
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Encodes the polynomial to a byte array writing <code>BITS_PER_INDEX</code> bits for each coefficient.
*
* @return the encoded polynomial
*/
public byte[] toBinary()
{
int maxIndex = 1 << BITS_PER_INDEX;
byte[] bin1 = ArrayEncoder.encodeModQ(ones, maxIndex);
byte[] bin2 = ArrayEncoder.encodeModQ(negOnes, maxIndex);
byte[] bin = Arrays.copyOf(bin1, bin1.length + bin2.length);
System.arraycopy(bin2, 0, bin, bin1.length, bin2.length);
return bin;
}
示例6: getNegOnes
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public int[] getNegOnes()
{
int N = coeffs.length;
int[] negOnes = new int[N];
int negOnesIdx = 0;
for (int i = 0; i < N; i++)
{
int c = coeffs[i];
if (c == -1)
{
negOnes[negOnesIdx++] = i;
}
}
return Arrays.copyOf(negOnes, negOnesIdx);
}
示例7: add
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Adds another polynomial which can have a different number of coefficients.
*
* @param b another polynomial
*/
public void add(IntegerPolynomial b)
{
if (b.coeffs.length > coeffs.length)
{
coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
}
for (int i = 0; i < b.coeffs.length; i++)
{
coeffs[i] += b.coeffs[i];
}
}
示例8: sub
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Subtracts another polynomial which can have a different number of coefficients.
*
* @param b another polynomial
*/
public void sub(IntegerPolynomial b)
{
if (b.coeffs.length > coeffs.length)
{
coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
}
for (int i = 0; i < b.coeffs.length; i++)
{
coeffs[i] -= b.coeffs[i];
}
}
示例9: mult
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Multiplies the polynomial with another, taking the indices mod N and the values mod 2048.
*/
public LongPolynomial2 mult(LongPolynomial2 poly2)
{
int N = coeffs.length;
if (poly2.coeffs.length != N || numCoeffs != poly2.numCoeffs)
{
throw new IllegalArgumentException("Number of coefficients must be the same");
}
LongPolynomial2 c = multRecursive(poly2);
if (c.coeffs.length > N)
{
if (numCoeffs % 2 == 0)
{
for (int k = N; k < c.coeffs.length; k++)
{
c.coeffs[k - N] = (c.coeffs[k - N] + c.coeffs[k]) & 0x7FF0007FFL;
}
c.coeffs = Arrays.copyOf(c.coeffs, N);
}
else
{
for (int k = N; k < c.coeffs.length; k++)
{
c.coeffs[k - N] = c.coeffs[k - N] + (c.coeffs[k - 1] >> 24);
c.coeffs[k - N] = c.coeffs[k - N] + ((c.coeffs[k] & 2047) << 24);
c.coeffs[k - N] &= 0x7FF0007FFL;
}
c.coeffs = Arrays.copyOf(c.coeffs, N);
c.coeffs[c.coeffs.length - 1] &= 2047;
}
}
c = new LongPolynomial2(c.coeffs);
c.numCoeffs = numCoeffs;
return c;
}
示例10: add
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Adds another polynomial which can have a different number of coefficients.
*
* @param b another polynomial
*/
private void add(LongPolynomial2 b)
{
if (b.coeffs.length > coeffs.length)
{
coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
}
for (int i = 0; i < b.coeffs.length; i++)
{
coeffs[i] = (coeffs[i] + b.coeffs[i]) & 0x7FF0007FFL;
}
}
示例11: sub
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Subtracts another polynomial which can have a different number of coefficients.
*
* @param b another polynomial
*/
private void sub(LongPolynomial2 b)
{
if (b.coeffs.length > coeffs.length)
{
coeffs = Arrays.copyOf(coeffs, b.coeffs.length);
}
for (int i = 0; i < b.coeffs.length; i++)
{
coeffs[i] = (0x0800000800000L + coeffs[i] - b.coeffs[i]) & 0x7FF0007FFL;
}
}
示例12: toBinary
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] toBinary()
{
byte[] f1Bin = f1.toBinary();
byte[] f2Bin = f2.toBinary();
byte[] f3Bin = f3.toBinary();
byte[] all = Arrays.copyOf(f1Bin, f1Bin.length + f2Bin.length + f3Bin.length);
System.arraycopy(f2Bin, 0, all, f1Bin.length, f2Bin.length);
System.arraycopy(f3Bin, 0, all, f1Bin.length + f2Bin.length, f3Bin.length);
return all;
}
示例13: getKnowledgeProofForX2s
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public BigInteger[] getKnowledgeProofForX2s()
{
return Arrays.copyOf(knowledgeProofForX2s, knowledgeProofForX2s.length);
}
示例14: keyValue
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
public byte[] keyValue() {
return Arrays.copyOf(keyValue, keyValue.length);
}
示例15: invertFq
import org.bouncycastle.util.Arrays; //导入方法依赖的package包/类
/**
* Computes the inverse mod <code>q; q</code> must be a power of 2.<br/>
* Returns <code>null</code> if the polynomial is not invertible.
*
* @param q the modulus
* @return a new polynomial
*/
public IntegerPolynomial invertFq(int q)
{
int N = coeffs.length;
int k = 0;
IntegerPolynomial b = new IntegerPolynomial(N + 1);
b.coeffs[0] = 1;
IntegerPolynomial c = new IntegerPolynomial(N + 1);
IntegerPolynomial f = new IntegerPolynomial(N + 1);
f.coeffs = Arrays.copyOf(coeffs, N + 1);
f.modPositive(2);
// set g(x) = x^N − 1
IntegerPolynomial g = new IntegerPolynomial(N + 1);
g.coeffs[0] = 1;
g.coeffs[N] = 1;
while (true)
{
while (f.coeffs[0] == 0)
{
for (int i = 1; i <= N; i++)
{
f.coeffs[i - 1] = f.coeffs[i]; // f(x) = f(x) / x
c.coeffs[N + 1 - i] = c.coeffs[N - i]; // c(x) = c(x) * x
}
f.coeffs[N] = 0;
c.coeffs[0] = 0;
k++;
if (f.equalsZero())
{
return null; // not invertible
}
}
if (f.equalsOne())
{
break;
}
if (f.degree() < g.degree())
{
// exchange f and g
IntegerPolynomial temp = f;
f = g;
g = temp;
// exchange b and c
temp = b;
b = c;
c = temp;
}
f.add(g, 2);
b.add(c, 2);
}
if (b.coeffs[N] != 0)
{
return null;
}
// Fq(x) = x^(N-k) * b(x)
IntegerPolynomial Fq = new IntegerPolynomial(N);
int j = 0;
k %= N;
for (int i = N - 1; i >= 0; i--)
{
j = i - k;
if (j < 0)
{
j += N;
}
Fq.coeffs[j] = b.coeffs[i];
}
return mod2ToModq(Fq, q);
}