Saturday, June 07, 2008

NUS Matriculation Number Checkdigit

Out of interest (or perhaps, boredom), I decided to reverse-engineer the scheme by which the checkdigit of the NUS matriculation number is generated. After spending a couple of hours intensely studying some matriculation numbers, I finally reversed the scheme.

For the benefit of those who have less knowledge, a checkdigit is (usually) a number or letter appended to a longer number. Like a checksum, the checkdigit allows people who know the algorithm to very quickly discover whether the number is valid (since a randomly generated checkdigit is more likely to be wrong than correct).

In the case of the NUS matriculation number, the checkdigit is the final letter of the matriculation number, for example W in the case of the number u012345W.

Armed with some knowledge of hashing (since most checkdigits are calcuated by basic hash functions), expertise with modulus mathematics, and finally a list of matriculation numbers and their checkdigits, I was able to uncover the scheme, which follows.

Assume the numerical digits of the matriculation number are 0,C1,C2,C3,C4,C5. From this, calculate the checksum value by the formula:
((C1,C2,C3,C4,C5)*(12,10,12,11,6))+12) % 13
where % is the modulus operator. Compare the checksum with the following table:


The above algorithm should be accurate for all matriculation numbers beginning with "u0". Due to a lack of matriculation numbers beginning with other headers, I was unable to determine the offset for those numbers.

The methods for determining the NUS matriculation number checkdigit algorithm can be applied to find, among other things, the checkdigits of any NRIC number. By the way, that problem has already been solved (just wiki NRIC).

*P.S.* I have since updated the scheme to account for new matriculation numbers prefixed with A**.


Anonymous said...

this is so cool :) i always wonder how the letter comes about.

Anonymous said...

Can you reverse engineer the new NUS matric number.. the one that starts with A