コード例 #1
0
ファイル: FiniteFieldMult.java プロジェクト: jneely1/dimple
  private final FiniteFieldNumber finiteFieldProduct(
      FiniteFieldNumber input1, FiniteFieldNumber input2) {
    int x = input1.intValue();
    int y = input2.intValue();
    int n = input1.getN();
    int prim_poly = input1.getPrimativePolynomial();
    int z = 0;

    /* Convolve x and y as bit strings mod 2 */
    for (int i = 0; i < n; i++) if ((1 & (x >> i)) == 1) z ^= (y << i);

    /* Take any "extra" bits located at bit n or higher and fold it back down */
    for (int i = 2 * n; i >= n; i--) if ((1 & (z >> i)) == 1) z ^= (prim_poly << (i - n));

    return input1.cloneWithNewValue(z);
  }
コード例 #2
0
ファイル: FiniteFieldMult.java プロジェクト: jneely1/dimple
 @Override
 public final void evalDeterministic(Object[] arguments) {
   // Allow one constant input
   Object arg1 = arguments[1];
   Object arg2 = arguments[2];
   FiniteFieldNumber input1 =
       (arg1 instanceof FiniteFieldNumber)
           ? (FiniteFieldNumber) arg1
           : ((FiniteFieldNumber) arg2).cloneWithNewValue(FactorFunctionUtilities.toInteger(arg1));
   FiniteFieldNumber input2 =
       (arg2 instanceof FiniteFieldNumber)
           ? (FiniteFieldNumber) arg2
           : ((FiniteFieldNumber) arg1).cloneWithNewValue(FactorFunctionUtilities.toInteger(arg2));
   if (!input1.isCompatible(input2))
     throw new DimpleException("Primitive polynomials must match.");
   arguments[0] = finiteFieldProduct(input1, input2); // Replace the output value
 }
コード例 #3
0
 @Override
 public final void evalDeterministic(Value[] arguments) {
   // Allow one constant input
   final Value arg1Value = arguments[1];
   final Value arg2Value = arguments[2];
   final Object arg1 = requireNonNull(arg1Value.getObject());
   final Object arg2 = requireNonNull(arg2Value.getObject());
   final FiniteFieldNumber input1 =
       (arg1 instanceof FiniteFieldNumber)
           ? (FiniteFieldNumber) arg1
           : ((FiniteFieldNumber) arg2).cloneWithNewValue(arg1Value.getInt());
   final FiniteFieldNumber input2 =
       (arg2 instanceof FiniteFieldNumber)
           ? (FiniteFieldNumber) arg2
           : ((FiniteFieldNumber) arg1).cloneWithNewValue(arg2Value.getInt());
   if (!input1.isCompatible(input2))
     throw new DimpleException("Primitive polynomials must match.");
   arguments[0].setFiniteField(finiteFieldProduct(input1, input2)); // Replace the output value
 }
コード例 #4
0
ファイル: FiniteFieldMult.java プロジェクト: jneely1/dimple
  @Override
  public double evalEnergy(Value[] values) {
    // Allow one constant input
    FiniteFieldNumber result = (FiniteFieldNumber) values[0].getObject();
    Object arg1 = values[1].getObject();
    FiniteFieldNumber input1 =
        (arg1 instanceof FiniteFieldNumber)
            ? (FiniteFieldNumber) arg1
            : result.cloneWithNewValue(FactorFunctionUtilities.toInteger(arg1));
    Object arg2 = values[2].getObject();
    FiniteFieldNumber input2 =
        (arg2 instanceof FiniteFieldNumber)
            ? (FiniteFieldNumber) arg2
            : result.cloneWithNewValue(FactorFunctionUtilities.toInteger(arg2));

    if (!result.isCompatible(input1) || !result.isCompatible(input2))
      throw new DimpleException("Primitive polynomials must match.");

    FiniteFieldNumber computedResult = finiteFieldProduct(input1, input2);

    return (computedResult.isEqual(result)) ? 0 : Double.POSITIVE_INFINITY;
  }
コード例 #5
0
  @Override
  public final double evalEnergy(Value[] arguments) {
    // Allow one constant input
    final FiniteFieldNumber result = requireNonNull((FiniteFieldNumber) arguments[0].getObject());
    final Value arg1 = arguments[1];
    final FiniteFieldNumber input1 =
        (arg1 instanceof FiniteFieldValue)
            ? arg1.getFiniteField()
            : result.cloneWithNewValue(arg1.getInt());
    final Value arg2 = arguments[2];
    final FiniteFieldNumber input2 =
        (arg2 instanceof FiniteFieldValue)
            ? arg2.getFiniteField()
            : result.cloneWithNewValue(arg2.getInt());

    if (!result.isCompatible(input1) || !result.isCompatible(input2))
      throw new DimpleException("Primitive polynomials must match.");

    final FiniteFieldNumber computedResult = finiteFieldProduct(input1, input2);

    return (computedResult.isEqual(result)) ? 0 : Double.POSITIVE_INFINITY;
  }