Skip to content

nzx9/SL-NIC-Decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SL-NIC-Decoder

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.


Info about NIC

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, ...)

Pseudocode

Algorithm NIC-Decoder(NIC)
input: NIC, Output: Struct includes birthday and gender
  1. nic <- input NIC number(without v)
  2. if nic.length != 9 or nic.length != 12 exit and throw error "Wrong nic"
  3. if nic.length == 9 then year <- 1900 + str2int(nic[0:1]), temp <- nic[2:4] and goto step 5
  4. if nic.length == 12 the year <- str2int(nic[0:3]), temp <- nic[4:6] and goto step 5
  5. if temp > 500 then gender <- female else gender <- male
  6. if temp > 500 then temp <- temp - 500
  7. {month, day} <- monthAndDate(temp)
  8. return {{year, month, day}, gender}

Other Implementations

For python implementation, please goto krypto-i9/nic-exec

Releases

No releases published

Packages

No packages published

Languages