Python Forum
individual's ID card number in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
individual's ID card number in python
#1
Hello everyone,
How can I check the integrity of an individual's ID card number by typing 9 numbers by a user in python?
Reply
#2
well that depends - do you have algorithm (e.g. is there a check-sum number)? Note that you can check that it is correct based on algorithm, not that it is actually issued...
Or do you have access to a police/government database with valid ID numbers?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
You can search for already existing algorithms to generate checksums.
You can do also your own algorithm.

A very simple implementation:

def gen_checksum(number):
    return number * 123 % 99

def num2id(number):
    checksum = gen_checksum(number)
    return number * 100 + checksum

def get_checksum(id_number):
    number = id_number // 100
    checksum = id_number - number * 100
    return number, checksum

def check(id_number):
    number, checksum = get_checksum(id_number)
    return id_gen(number) == checksum

valid_numbers = [num2id(number) for number in range(1000, 1021)]
check(102027)
The modulo 99 limits the checksum to 99.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Access individual items of a dictionary by clicking a button AdeS 7 160 Mar-13-2026, 04:36 PM
Last Post: woooee
  How to expand and collapse individual parts of the code in Atom Lora 2 2,640 Oct-06-2022, 07:32 AM
Last Post: Lora
  Having strange results from an RFID HID card reader - I'm stuck orbisnz 1 2,984 Mar-28-2022, 08:20 AM
Last Post: Larz60+
  SQL wild card use hammer 3 2,543 Jan-07-2022, 02:17 PM
Last Post: hammer
  read individual nodes from an xml url using pandas mattkaplan27 5 5,404 Jul-05-2020, 10:06 PM
Last Post: snippsat
  Loop files - Extract List Data To Individual Columns in CSV dj99 5 5,606 May-19-2019, 10:29 AM
Last Post: dj99
  Slicing Python list of strings into individual characters Drone4four 5 6,847 Apr-17-2019, 07:22 AM
Last Post: perfringo
  Credit card number redacting script Drone4four 6 8,451 Jan-18-2019, 02:07 PM
Last Post: Drone4four
  Validating credit card frequency 8 6,631 Nov-05-2018, 07:36 PM
Last Post: frequency
  Extract Strings From Text File - Out Put Results to Individual Files dj99 8 7,530 Jun-28-2018, 10:41 AM
Last Post: dj99

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020