Helios服务器(Helios是一个端到端可验证的投票系统)作为库
helios-lib的Python项目详细描述
Helios库
这是Helios-Server(helios是一个端到端可验证的投票系统。)作为库,
这个helios_lib版本完全独立于django。
安装
>>> pip install helios_lib
测试
>>> pytest --fulltrace -s helios_lib/
示例
fromhelios_lib.modelsimportHeliosElection,HeliosVoterfromhelios_lib.configimportELGAMAL_PARAMS# Create electionhelios_election=HeliosElection()# Add trusteetrustee_default=helios_election.generate_helios_trustee(ELGAMAL_PARAMS)helios_election.trustees.append(trustee_default)# Add questionsquestion=HeliosElection.create_question(answers_count=5,minimum=0,maximum=2,result_type='relative')helios_election.questions=[question]# Add votersvoters_count=4helios_election.voters=[HeliosVoter()for_inrange(voters_count)]# Freeze the electionhelios_election.freeze()# Cast votes, Encrypt votes of voters on the helios_lib sidehelios_election.voters[0].vote=helios_election.encrypt_ballot('[[0,4]]')helios_election.voters[1].vote=helios_election.encrypt_ballot('[[0]]')helios_election.voters[2].vote=helios_election.encrypt_ballot('[[1]]')helios_election.voters[3].vote=helios_election.encrypt_ballot('[[1,4]]')# Verify votes of votersforvinhelios_election.voters:v.vote.verify(helios_election)# Tally electionhelios_election.num_cast_votes=4helios_election.compute_tally(helios_election.voters)helios_trustee=helios_election.get_helios_trustee()helios_election.helios_trustee_decrypt(helios_trustee)helios_election.combine_decryptions()# Result of electionasserthelios_election.result==[[2,2,0,0,2]]
有关更复杂的示例,请参阅测试