Python|Interestingly explain the mystery of ID number

Problem Description

As a citizen, everyone has a unique ID card with a unique ID number. Almost all our whereabouts and information are stored here, so there are many criminals who can carry out some criminal activities only through the ID number. However, it is easy to leak this information in life, such as bus tickets, etc. Although 4 digits are hidden, is it really safe?

solution

Through a simple query, it is not difficult for us to know that although the ID card number is unique, the rule of its generation is indeed fixed. Only through a formula can determine whether an ID card number is correct, and vice versa, it can also be confirmed by a correct but incomplete ID number to reverse the complete information.

I believe everyone understands the components of an ID card. The most important thing is the last check code, and the calculation of the check code is actually very simple:

Each of the first 17 digits corresponds to a coefficient, which is 7. 9 .10 .5. 8. 4. 2. 1. 6. 3. 7. 9. 10. 5. 8. 4. 2. The number obtained by multiplying the digit and the coefficient and the remainder divided by 11 must be within 0-10. Then there are 11 numbers of 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10. The corresponding last ID number is 1.0. X. 9. 8. 7. 6. 5. 4. 3. 2. In this way, you can get your own check code. Of course, readers can try it yourself Own ID number.

Although we know that even if we do calculations, there are only 366 attempts to get results, but learning the language is to simplify, so I wrote a code to judge whether the ID card is correct and roughly calculate the ID card number. Readers can try it by themselves is it effective.

Python code: Determine whether the ID number is true

def ID_Card_judgment(ID_num): list1 = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2] sums = 0 for i in range(len(list1)): new_num = int(ID_num[i]) * list1[i] sums += new_num check_code = [1,0,"X",9,8,7,6,5,4,3,2] num = sums % 11 if str(check_code[num]) == ID_num[-1]: return "True" else: return "False"

Roughly infer the complete ID number:

def ID_Card_calculation(ID_num): if ID_num[-1] == "X": new_ID_num = ID_num[:-1]+"10" else: new_ID_num = ID_num a = new_ID_num.split("") new_ID_card = "". join(a) front_code = [7,9,10,5,8,4,2,1,6,3,8,4,2] #Except the four-digit number of birthday parameters sums = 0 for i in range (len(front_code)): #len(new_ID_card) = 18-4-1 =13 nums = int(new_ID_card[i]) * front_code[i] sums += nums # print(sums) In addition to the four digits of birthday, others The sum of the product of the number and the corresponding parameter #7,9,10,5 Birthday four-digit parameter duiying = [1,0,10,9,8,7,6,5,4,3,2] times = 0 for a in range(0,2): for b in range(0,10): for c in range(0,4): for d in range(0,10): if (sums + (a7 + b* 9 + c10 + d5))% 11 == duiying[int(new_ID_num[17:])]: string = str(a)+str(b)+str(c)+str(d) if 0 <int(string[0:2]) <= 12 and 0 <int(string[2:4]) <= 31: times += 1 ID_Card_num = ID_num[0:10] + string + ID_num[14:18] print(ID_Card_num) print("%d cases in total."%times)

This code requires a string of digits whose birthday is ****, which also complies with the common rules for hiding ID numbers. Although it cannot be accurately inferred, there are only 20 or 30 results. You can easily get your information through some platforms on the existing network, plus other information such as your name and constellation.

Conclusion

There are too many private information stored on the ID card, so everyone must keep it properly. There are also discarded tickets and other numbers that seem to be able to protect our information, but they may all be the final "culprits." Although the other four digits may not be hidden, they can be obtained through the law. So the author reminds everyone that you must mosaic your ID number on the Internet to prevent criminals from having a chance.

END

Chief Editor | Wang Nanlan

Editor | Li Helong

** where2go team**


Recommended Posts

Python|Interestingly explain the mystery of ID number
What is the id function of python
Explain the implementation of Centos8 static IP configuration