Skip to content

Instantly share code, notes, and snippets.

@borgle
Last active October 11, 2017 07:51
Show Gist options
  • Save borgle/7018240 to your computer and use it in GitHub Desktop.
Save borgle/7018240 to your computer and use it in GitHub Desktop.
在微博上看到无数次有人说火车票上身份证隐藏的四位用程序很容易跑出来,刚才验证了一下,确实很容易跑出来,不过你不知道具体是哪一个。因为有太多符合身份证规则的值了。以下是18位身份证验证的代码片段。
#!/usr/bin/python
# -*- coding: utf-8 -*-
dbstr = lambda x : x < 10 and '0' + str(x) or str(x)
ai = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
wi = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]
cardid = "522636%(y)s%(m)s%(d)s8735"
for y in range(1970, 2000):
for m in range(1, 13):
for d in range(1, 31):
v = {"y": dbstr(y), "m": dbstr(m), "d": dbstr(d)}
card = cardid % v
t, i = 0, 0
for char in card[: -1]:
t = t + int(char) * ai[i]
#print char, ai[i], t
i = i + 1
if wi[t % 11] == card[-1]:
print card
#break #ignore month
#break #ignore year
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment