Find Gender and Birthday by NIC Number (Sri Lanka) [Lang: C++]
C++ program that can decode informations like gender and birthday, using Sri Lankan National Id Card Number. This Program works for both old(9 digits + v) and new(12 digits) NIC numbers.
10 Character NIC | Ex: 987654321V
- First 2 characters(98) give the last two digits of birth year(1900 + 98 = 1998)
- Next 3(765) characters give information about gender and birth month and day
- If value of 3rd character to 5th character is higher than 500 that means gender is female, if it less than 500 means gender is male
- If gender is female, have to substract 500 from 3rd character to 5th character(765 - 500), then take the month and day accoding to the number of days in each month(January: 31, February: 29, March: 31, April: 30, ...)
12 Character NIC | Ex: 199876543210
- First 4 characters(1998) give the birth year
- Next 3(765) characters give information about gender and birth month and day
- If value of 5th character to 8th character(765) is higher than 500 that means gender is female, if it less than 500 means gender is male
- If gender is female, have to substract 500 from value of 5th character to 8th chatacter(765 - 500), then take the month and day accoding to the number of days in each month(January: 31, February: 29, March: 31, April: 30, ...)
input: NIC, Output: Struct includes birthday and gender
- nic <- input NIC number(without v)
- if nic.length != 9 or nic.length != 12 exit and throw error "Wrong nic"
- if nic.length == 9 then year <- 1900 + str2int(nic[0:1]), temp <- nic[2:4] and goto step 5
- if nic.length == 12 the year <- str2int(nic[0:3]), temp <- nic[4:6] and goto step 5
- if temp > 500 then gender <- female else gender <- male
- if temp > 500 then temp <- temp - 500
- {month, day} <- monthAndDate(temp)
- return {{year, month, day}, gender}
For python implementation, please goto krypto-i9/nic-exec