forked from Aksaykanthan/trustless-examination-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulateit.py
More file actions
45 lines (34 loc) · 1.21 KB
/
simulateit.py
File metadata and controls
45 lines (34 loc) · 1.21 KB
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
import random
import json
import datetime
from create_ledger import *
from RSA import decrypt_with_key
def simulate_exam():
question_bank = Questions("data/QuestionPaper.json",10)
# Setting Start Time and End Time
startTime = datetime.datetime.now()
endTime = startTime + datetime.timedelta(minutes=30)
#Initializing Ledger
ledger = Ledger(startTime,endTime)
students = Students("data/students.json")
# Simulating Exam
for i in range(10):
student = random.choice(students.students)
question = random.choice(question_bank.questions)
option = random.choice(question["options"])
response = Response(student["id"],question["questionId"],option["optionId"])
ledger.addResponse(response,students,question_bank)
with open("ledger.json",'w') as f:
json.dump(ledger.ledger,f)
def decrypting_ledger():
with open("data/ledger.json",'r') as f:
ledger = json.load(f)
l = []
for response in ledger:
r = Response.decrypt(response)
l.append(r)
with open("data/decrypted_ledger.json",'w') as f:
json.dump(l,f)
if __name__ == '__main__':
# simulate_exam()
decrypting_ledger()