forked from infoaed/uduloor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uduloor.py
executable file
·133 lines (89 loc) · 2.21 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
#!/usr/bin/python3
# https://myaccount.google.com/lesssecureapps
import smtplib, ssl
import time, random
from collections import namedtuple
url = "smtp.gmail.com"
port = 465
username = "boamaod"
password = "secret123"
sender = "[email protected]"
message_template = """From: Uduloor <[email protected]>
To: %s
Subject: Uduloor
Sinu pseudonüüm hääletamisel on:
* %s
Hääletus toimub aadressil
* https://etherpad.wikimedia.org/p/wmee-juhatus
Siiralt "jne"
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
"""
pseudo_id = namedtuple('pseudo_id', ['pseudonym', 'code', 'cryptonym'])
voter_list = voters_in_text.strip().splitlines()
word_list = unique_words.strip().splitlines()
random_words = random.sample(word_list, len(voter_list))
random_keys = random.sample(range(100, 999), len(voter_list))
print("There is %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:
#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 % (receiver, pseudo[i].cryptonym)
print("*", pseudo[i].pseudonym)
#server.sendmail(sender, receiver, message.encode("utf8"))
time.sleep(1)
#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)