setup = ThresholdEncryptionSetUp(cryptosystem, len(trustees), election["trustee_threshold"])

# Add trustee commitments
for trustee in xrange(0, len(trustees)):
	def to_ciphertext(idx):
		ciphertext = Ciphertext(nbits, PublicKey(cryptosystem, long(trustees[idx]["public_key"]["y"])).get_fingerprint())
		
		for i in xrange(0, len(trustees[trustee]["commitment"]["encrypted_partial_private_keys"][idx])):
			ciphertext.append(long(trustees[trustee]["commitment"]["encrypted_partial_private_keys"][idx][i]["alpha"]), long(trustees[trustee]["commitment"]["encrypted_partial_private_keys"][idx][i]["beta"]))
		
		return ciphertext
	
	setup.add_trustee_commitment(trustee, ThresholdEncryptionCommitment(
		cryptosystem, len(trustees), election["trustee_threshold"],
		[long(x) for x in trustees[trustee]["commitment"]["public_coefficients"]],
		[to_ciphertext(idx) for idx in range(0, len(trustees))]
	))

threshold_key = setup.generate_private_key(number, secret)

print(json.dumps({
	"public_key": {
		"g": str(threshold_key.cryptosystem.get_generator()),
		"p": str(threshold_key.cryptosystem.get_prime()),
		"q": str((threshold_key.cryptosystem.get_prime() - 1) / 2),
		"y": str(threshold_key.public_key._key)
	},
	"x": str(threshold_key._key)
}))
                len(trustees[trustee]["commitment"]
                    ["encrypted_partial_private_keys"][idx])):
            ciphertext.append(
                long(trustees[trustee]["commitment"]
                     ["encrypted_partial_private_keys"][idx][i]["alpha"]),
                long(trustees[trustee]["commitment"]
                     ["encrypted_partial_private_keys"][idx][i]["beta"]))

        return ciphertext

    setup.add_trustee_commitment(
        trustee,
        ThresholdEncryptionCommitment(
            cryptosystem, len(trustees), election["trustee_threshold"], [
                long(x)
                for x in trustees[trustee]["commitment"]["public_coefficients"]
            ], [to_ciphertext(idx) for idx in range(0, len(trustees))]))

threshold_key = setup.generate_private_key(number, secret)

print(
    json.dumps({
        "public_key": {
            "g": str(threshold_key.cryptosystem.get_generator()),
            "p": str(threshold_key.cryptosystem.get_prime()),
            "q": str((threshold_key.cryptosystem.get_prime() - 1) / 2),
            "y": str(threshold_key.public_key._key)
        },
        "x": str(threshold_key._key)
    }))