import random
yushu=[x for x in range(0,11)]
ma=['1','0','X','9','8','7','6','5'陆饥做,'4','3','2','1']
def yanzheng(nid):
dicma=dict(zip(yushu,ma))
sum=0
for x,y in enumerate(nid[:-1]):
sum+=((2**(18-x-1))%11)*int(y) #17位对应系数相乘的和
if nid[-1]==dicma[sum%11]: #校验码对照
return '%s True'%nid
else:
return '%s False'%nid
def readfile(fname):
f=open(fname,'rb')
for line in f.readlines():
print yanzheng(line.strip())
f.close()
def randnum():
idstr=''
for i in range(17): #前17位随机
idstr+=str(random.randint(0,9))
idstr+=random.choice(ma) #最后一位从列表种随意一个,因为有X
return idstr
if __name__=="__main__":
nid=raw_input('Please enter your ID: ') #用户输入ID,没做任何验证
print yanzheng(nid) #验证身份z
readfile('id.txt') #从文件读出来 再验证
print yanzheng(randnum()) 肢册#随机一个 在验证
area={"11":"北京","12":"天津","13":"河北","14":"山西","15":"内蒙古","21":"辽宁","22":"吉林","23":"黑龙江","31":"上海","32":"江苏","33":"浙江","34":"安徽","35":"福建","36":"江西","37":"山东","41":"河南","42":"湖北","43":"湖南","44":"广东","45":"广西","46":"海南","50":"重庆","51":"四川","52":"贵州","53":"云南","54"裤段返:"西藏","61":"陕西","燃御62":"甘肃","63":"青海胡饥","64":"宁夏","65":"新疆","71":"台湾","81":"香港","82":"澳门","91":"国外"}
s=input('输入身份z号码:')
t=s[0]+s[1]
print(area[t])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)