Commit ca225e68 authored by Olivier's avatar Olivier
Browse files

M2: modify hash function to work with email input, not matriculation

The code in this commit is contributed by Germán Santa Maria.

The hash function is modified to use the email address as input,
instead of the matriculation number. It also outputs two code
numbers (one for submission, one for grading) instead of one.
This commit goes together with commit 4e0f1000
parent 72105c95
......@@ -4,28 +4,35 @@ Author: German Santa Maria
Script: Hash Function
This script takes a matriculation number (for example:123456)
and uses a cryptographic hash function and that generates an eight-digit
anonymous ID to identify the assignments submitted by the students.
Based on the matriculation number, the script also generates an array
This script takes an email address (for example:
and uses a cryptographic hash function and that generates two nine-digit
anonymous IDs to identify the student assignment and grade respectively.
Based on the input email address, the script also generates an array
with six random numbers that take values from 0 to 1.
def hash_function(matrikel_num):
def hash_function(student_email):
import hashlib
salt = "insert_your_salt_here" # Salt for the hash function
hash_input = salt + str(matrikel_num) # Input for hash function
hash_input = salt + str(student_email) # Input for hash function
hf = hashlib.md5(hash_input.encode('utf-8')).hexdigest() # Digest hash
hf = str(int(hf,16)) # Convert from hexadecimal to integer string
custom_ID = hf[1:9] # Custom ID for student
# Generate Custom ID #1 for the student assignment
custom_ID_A = hf[1:9]
custom_ID_A = "A"+str(custom_ID_A)
# Generate Custom ID #2 for the student grade
custom_ID_G = hf[10:18]
custom_ID_G = "G"+str(custom_ID_G)
rand_n = [hf[9:12],hf[12:15],hf[15:18],hf[18:21],hf[21:24],hf[24:27]]
rand_n = list(map(int, rand_n)) # Random numbers from list to number
for i in range(len(rand_n)): # Turn random numbers into values from 0 to 1
rand_n[i] = rand_n[i]*0.001
return [custom_ID, rand_n]
return [custom_ID_A, custom_ID_G, rand_n]
# End of script
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment