banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

使用 Python 可以計算身份證號碼

開工。
先看看李大偉的朋友圈中發的圖片。

圖片
車票中暴露的個人信息為:

3302211993****4914 李大偉

只缺少月份日期四位。

那麼也就是一共 365 種可能。

科普時間:#

圖片
根據李大偉的身份證信息的前 6 位 “330221”

輕易可得:

圖片
浙江省寧波人,1993 年滴
那先用 python 生成 1993 年的所有日期吧.

import time

#生成出生當年所有日期
def dateRange(year):
    fmt = '%Y-%m-%d'
    bgn = int(time.mktime(time.strptime(year+'-01-01',fmt)))
    end = int(time.mktime(time.strptime(year+'-12-31',fmt)))
    list_date = [time.strftime(fmt,time.localtime(i)) for i in range(bgn,end+1,3600*24)]
    return [i.replace('-','') for i in list_date]

data_time  = dateRange('1993')

成功得到日期列表。

圖片

再用剛才的校驗碼計算規則反向驗證哪個日期符合囉!自己寫計算規則?
太麻煩!
給大家隆重介紹一個庫:id-validator
安裝:pip install id-validator
可以用來驗證身份證號合法性、獲取身份證號信息、生成可通過校驗的假數據、身份證升級。

圖片
那麼我們利用 id-validator 來依次校驗剛才生成的身份證號碼。完整代碼如下:

from id_validator import validator
import time

#生成出生當年所有日期
def dateRange(year):
    fmt = '%Y-%m-%d'
    bgn = int(time.mktime(time.strptime(year+'-01-01', fmt)))
    end = int(time.mktime(time.strptime(year+'-12-31', fmt)))
    list_date = [time.strftime(fmt, time.localtime(i))for i in range(bgn, end+1, 3600*24)]
    return [i.replace('-', '') for i in list_date]

#遍歷所有日期,print通過校驗的身份證號碼
def vali_dator(id1, id2, id3):
    for i in dateRange(id2):
        theid = id1 + i + id3
        if validator.is_valid(theid):
            print(theid)

vali_dator('330221','1993','4914')

運行結果:

圖片

如何在 33 個日期中挑出來李大偉的真實出生日期呢?
接下來就要通過身份證號碼和姓名是否匹配來篩選最終的結果。以往的解決方案是:通過 12306 查詢,在 12306 添加聯繫人,若身份證和姓名一致,就會顯示校驗通過。若不能通過,則說明身份證和姓名不一致。但現在這種方法已經不能用了。

然後我這裡又找到了阿里雲的實名認證接口,根據身份證姓名和身份證號碼核對是身份信息是否一致。但只有企業用戶才能使用,個人是沒法用了,所以就不嘗試了。

圖片

總結#

用 python 計算身份證號碼的具體流程大概就是這樣。當然出生月份和日期很多人都會在 QQ 或其它社交軟件裡面公開,一找就能找到。

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。