aufgabe 9.5

/* import of the libraries needed to use the class BigInteger */

import java.math.BigInteger;
import java.util.Random;

class Pedersen {
	/* setting up the constants */
	static final BigInteger p = new BigInteger("23");
	static final BigInteger q = new BigInteger("11");
	static final BigInteger g = new BigInteger("2");
	static final BigInteger h = new BigInteger("3");
	/* the method commit() is used to generate a commitment using the constants and the given message and a randomly generated number between 1 and q */
	static BigInteger commit(BigInteger r,BigInteger m) {
		BigInteger c = ((g.pow(m.intValue())).multiply(h.pow(r.intValue()))).mod(p);
		return c;
	/* the method verify() is used to find out if a commitmeng belongs to a message */
	static boolean verify(BigInteger r,BigInteger m,BigInteger c) {
		if(c.compareTo(commit(r,m))==0) return true;
		return false;

	public static void main (String[] args) {
		BigInteger m = new BigInteger("6"); // the message that has to be commited
		BigInteger r = new BigInteger(4, new Random());
		BigInteger min = new BigInteger("1");
		while(r.compareTo(min)==-1 || r.compareTo(q)==1) { // needed to filter out the r�s that are not between 1 and q (1 and 11)
			r = new BigInteger(3, new Random());

		BigInteger c = commit(r,m); // generation of a commitment
		boolean x = verify(r,m,c); // verifying a commitment

Leave a Reply