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
            [{
Example #2
0
										AT = pow(long(ballot["choices"][block]["alpha"]), T, P)
										BFC = (long(proof["commitment"]["B"]) * pow(factor, C, P)) % P
				
										if AT != BFC:
											sc4.fail("alpha^t != B(factor)^c (mod p)")
										
										decryption_factor_combination *= factor
								
								# Check the claimed decryption
								decryption_factor_combination *= result[block]
								
								if (decryption_factor_combination % P) != (long(ballot["choices"][block]["beta"]) % P):
									sc3.fail("Claimed plaintext doesn't match decryption factors")
	else:
		# We need a ThresholdPublicKey
		tesu = ThresholdEncryptionSetUp(cryptosystem, len(trustees), trusteeThreshold)
		for trustee in xrange(0, len(trustees)):
			commitment = trustees[trustee]['commitment']
			
			def to_ciphertext(idx):
				ciphertext = Ciphertext(nbits, trustees[idx]['public_key_hash'])
				
				for i in xrange(0, len(commitment['encrypted_partial_private_keys'][idx])):
					ciphertext.append(long(commitment['encrypted_partial_private_keys'][idx][i]['alpha']), long(commitment['encrypted_partial_private_keys'][idx][i]['beta']))
				
				return ciphertext
			
			tesu.add_trustee_commitment(trustee, ThresholdEncryptionCommitment(
				cryptosystem, len(trustees), trusteeThreshold,
				[long(x) for x in commitment['public_coefficients']],
				[to_ciphertext(x) for x in xrange(0, len(commitment['encrypted_partial_private_keys']))]