nbits = ((int(math.log(long(trustees[0]["public_key"]["p"]), 2)) - 1)
             & ~255) + 256
    cryptosystem = EGCryptoSystem.load(
        nbits, long(trustees[0]["public_key"]["p"]),
        int(trustees[0]["public_key"]
            ["g"]))  # The generator might be a long if it's big? I don't know.

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

# Add trustee public keys
for i in xrange(0, len(trustees)):
    pk = PublicKey(cryptosystem, long(trustees[i]["public_key"]["y"]))
    setup.add_trustee_public_key(i, pk)

commitment = setup.generate_commitment()

print(
    json.dumps({
        "public_coefficients":
        [str(x) for x in commitment.public_coefficients],
        "encrypted_partial_private_keys": [
            # The partial private key is too big for one single (a, b) pair
            [{
                "alpha": str(x.gamma[i]),
                "beta": str(x.delta[i])
            } for i in xrange(0, x.get_length())]
            for x in commitment.encrypted_partial_private_keys
        ]
    }))
electionIn = sys.argv[1]
trusteesIn = sys.argv[2]

with open(electionIn, 'r') as electionFile:
	election = json.load(electionFile)

with open(trusteesIn, 'r') as trusteesFile:
	trustees = json.load(trusteesFile)
	
	nbits = ((int(math.log(long(trustees[0]["public_key"]["p"]), 2)) - 1) & ~255) + 256
	cryptosystem = EGCryptoSystem.load(nbits, long(trustees[0]["public_key"]["p"]), int(trustees[0]["public_key"]["g"])) # The generator might be a long if it's big? I don't know.

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

# Add trustee public keys
for i in xrange(0, len(trustees)):
	pk = PublicKey(cryptosystem, long(trustees[i]["public_key"]["y"]))
	setup.add_trustee_public_key(i, pk)

commitment = setup.generate_commitment()

print(json.dumps({
	"public_coefficients": [str(x) for x in commitment.public_coefficients],
	"encrypted_partial_private_keys": [
		# The partial private key is too big for one single (a, b) pair
		[{"alpha": str(x.gamma[i]), "beta": str(x.delta[i])} for i in xrange(0, x.get_length())]
		for x in commitment.encrypted_partial_private_keys
	]
}))