-
Notifications
You must be signed in to change notification settings - Fork 1
/
uduloor.py
executable file
·160 lines (107 loc) · 3.16 KB
/
uduloor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/python3
# https://myaccount.google.com/lesssecureapps
from random import SystemRandom
import smtplib, ssl
import time
from collections import namedtuple
sender = "[email protected]"
bulletin = "https://etherpad.wikimedia.org/p/psephos-demosia"
message_template = """From: Uduloor <%s>
To: %s
Subject: Your pseudonym for voting at the upcoming election
Your pseudonym for voting at the upcoming election is:
* %s
Voting takes place at:
* %s
Guidelines in nutshell:
* To cast your vote, please write down your pseudonym followed by your choice at the election.
* Make sure you write this information on a separate line at the bulletin board to avoid any confusion.
* To preserve your anonymity in this secret election you *should not* log in to the bulletin board.
* For extra caution you can use the private mode of your web browser or even special anonymity preserving browser.
* Before voting is closed, please make sure your vote is still correctly displayed at the bulletin board.
* After voting is closed you (or actually anyone) can tally the votes to make sure everything was done correctly.
Happy voting!
Sincereley "etc"
Uduloor
"""
voters_in_text = """[email protected]
"""
unique_words = """narcissus
taraxacum
tulipa
rhododendron
papaver
mimosa
iris
asparagus
anemone
alcea
hepatica
trollius
ranunculus
caltha
rosa
trifolium
melampyrum
syringa
solanum
ligularia
curcuma
antirrhinum
"""
code_range = range(100, 999)
DRY_RUN = True
url = "smtp.gmail.com"
port = 465
username = "boamaod"
password = "secret123"
pseudo_id = namedtuple('pseudo_id', ['pseudonym', 'code', 'cryptonym'])
voter_list = voters_in_text.strip().splitlines()
word_list = unique_words.strip().splitlines()
random = SystemRandom()
random_words = random.sample(word_list, len(voter_list))
random_keys = random.sample(code_range, len(voter_list))
print("There are %d voters in upcoming election:\n" % len(voter_list))
for voter in voter_list:
print(voter)
random.shuffle(voter_list)
print()
print("Distributing pseudonyms...\n")
pseudo = []
for i in range(len(voter_list)):
current = pseudo_id(random_words[i], str(random_keys[i]), random_words[i] + str(random_keys[i]))
pseudo.append(current)
i = -1
try:
if not DRY_RUN:
server = smtplib.SMTP_SSL(url, port, context=ssl.create_default_context())
server.login(username, password)
for i in range(len(voter_list)):
receiver = voter_list[i].split()[0]
message = message_template % (sender, receiver, pseudo[i].cryptonym, bulletin)
print("*", pseudo[i].pseudonym)
if not DRY_RUN:
server.sendmail(sender, receiver, message.encode("utf8"))
time.sleep(1)
if not DRY_RUN:
server.quit()
print()
print("Delivered %d pseudonyms." % (i+1))
except Exception as e:
print("Delivered %d pseudonyms." % (i+1))
print("ERROR:", e)
print()
print("Write 'end' to close voting and publish audit information.")
print()
while(input("> ") != "end"):
pass
print()
print("Cryptonyms:")
print()
for i in range(len(voter_list)):
print("*", pseudo[i].cryptonym)
print()
print("Thanks for taking digital democracy seriously!")