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]]

有关更复杂的示例,请参阅测试

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在GlassFish v2中同时使用两个EntityManager时出现java错误   java中字符串生成器到字符串数组   Java中的引用传递值   java无法在Motox中查看日期和时间   java rest web服务中的默认http方法是什么   java向Android视图添加一些自定义事件/Linstener,如ListView   java试图在系统中实现变量Int。出来总体安排   java为什么这些可调用函数永远无法完成?   javacom。mysql。jdbc。MysqlDataTruncation:数据截断:第1行“DATE”列的数据太长   java如何从底部工作表对话框类使用onActivityResult   意外的Vaadin会话已过期,并行spring引导应用程序   如何在Java中比较和排序两个ArrayList   使用Grunt任务运行java自动化测试   java多线程WebSocket   组上的java JPA标准API空检查   java合并ArryList并另存为arraylist与in arraylist   mongodb Java如何从MongoDatabase类中获取DB对象作为MongoClient。getDB(dbName)已被弃用   用Java绘制JFreeChart的折线图   java如何将Springbean从spring上下文外部注册到spring上下文中?