Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.math.BigInteger;
import java.nio.ByteBuffer;

import java.util.ArrayList;

import android.util.Log;

public class Main {
    public static BigInteger getZ(ArrayList<byte[]> c1, ArrayList<byte[]> c2, BigInteger p) {
        BigInteger z = BigInteger.ZERO;

        //TODO: make sure c1 and c2 are of the same size
        int size = c1.size();
        if (size > c2.size()) {
            size = c2.size();
        }

        for (int i = 0; i < size; i++) {
            BigInteger c1BI = new BigInteger(1, c1.get(i));
            BigInteger c2BI = new BigInteger(1, c2.get(i));
            BigInteger exp = new BigInteger(1, ByteBuffer.allocate(8).putLong((long) Math.pow(2, i)).array());

            z = z.add((c1BI.multiply(c2BI)).modPow(exp, p));
            Log.d("CeCk", "z calculation " + i + "/" + size + " round");
        }
        return z.mod(p);
    }
}