抠腚爱揉曼 Coding Iron Man

11Jan/113

原来身份证号是可以自我验证的

在Google Reader上别人share的文章看到的,二代身份证号码可以通过一种机制去验真。同样道理的也可以基于这种方式生成伪造的身份证号码,只不过也只能逃过本地验证,联网验证肯定还是死翘翘的。

蛋疼Groovy练手一段:

id = "787416969231782985"

factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] as int[]
results = [1, 0, "x", 9, 8, 7, 6, 5, 4, 3, 2] as String[]

sum = 0
factors.eachWithIndex { factor, i ->
    sum += (id[i] as int) * factor
}

id[17].toLowerCase() == results[sum%11]

各位如果和我一样蛋疼的也可以把id换成自己的身份证号码run一下看看是不是正确。另外附上同样蛋疼的生成脚本一段:

id = ""

factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] as int[]
results = [1, 0, "x", 9, 8, 7, 6, 5, 4, 3, 2] as String[]

sum = 0
random = new Random()
factors.each {
    ide = random.nextInt(10)
    id += ide
    sum += ide * it
}

id += results[sum%11]

Posted by Anson

Tagged as: Leave a comment
Comments (3) Trackbacks (0)

Leave a comment

(required)

No trackbacks yet.