Пример #1
0
    def test_phoebus_encoding(self):
        from phoebus import phoebus as ph

        sk = ph._default_secret_key
        pk = ph._default_public_key

        e = ph.Election(public_key=pk, candidates=range(6))
        b = ph.Ballot(election=e, answers=[1, 3, 3, 0, 1])
        b.encrypt()

        eb = b.encrypted_ballot
        bd = ph.Ballot.from_dict({
            'encrypted_ballot': {
                'a': eb['a'],
                'b': eb['b']
            },
            'public_key': pk,
            'nr_candidates': 6,
            'max_choices': 6
        })
        bd.decrypt(sk)

        for i in range(10):
            print ph.Ballot.mk_random(e)

        choice = [1, 3, 3, 1, 2, 1]
        self.assertEqual(
            ph.gamma_decode(ph.gamma_encode([1, 3, 3, 1, 2, 1], 6), 6), choice)
Пример #2
0
  def result_choices(self):
    from phoebus import phoebus
    print self.questions
    nr_cands = len(self.questions[0]['answers'])

    print self.result
    for result in self.result[0]:
      yield phoebus.to_absolute_answers(phoebus.gamma_decode(result, nr_cands), nr_cands)
Пример #3
0
  def result_choices(self, question=0):
    if self.questions[question]['choice_type'] == 'stv':
      from phoebus import phoebus
      print self.questions
      nr_cands = len(self.questions[question]['answers'])

      print self.result
      results = []
      for result in self.result[question]:
        results.append(phoebus.to_absolute_answers(phoebus.gamma_decode(result[0], nr_cands), nr_cands))
      return results
    else:
      results = []
      for result in self.result[question]:
        if 2 in result:
          results.append([result.index(2)])
        else:
          results.append([])
      
      return results
    def test_phoebus_encoding(self):
        from phoebus import phoebus as ph

        sk = ph._default_secret_key
        pk = ph._default_public_key

        e = ph.Election(public_key=pk, candidates=range(6))
        b = ph.Ballot(election=e, answers=[1, 3, 3, 0, 1])
        b.encrypt()

        eb = b.encrypted_ballot
        bd = ph.Ballot.from_dict({'encrypted_ballot':{
            'a': eb['a'], 'b': eb['b']},
            'public_key': pk, 'nr_candidates': 6, 'max_choices': 6})
        bd.decrypt(sk)

        for i in range(10):
            print ph.Ballot.mk_random(e)

        choice = [1,3,3,1,2,1]
        self.assertEqual(ph.gamma_decode(ph.gamma_encode([1,3,3,1,2,1], 6), 6),
                         choice)