package { import flash.display.Sprite; import flash.events.Event; /** * 猜解身份证号 * 存在的问题是后面不是x的推算准确 * 是x的有问题 * @author langxm 964683112@qq.com */ public class Main extends Sprite { /** * 余数数组 */ public var modArr:Array; /** * 身份证洗漱 */ public var modulusArr:Array; private var id:String; private var a:int=0, b:int=0, c:int=0, d:int=0; public function Main(InInput:String='53262819720718326x'):void { //this.id = InInput; this.id = InInput; if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e:Event = null):void { removeEventListener(Event.ADDED_TO_STAGE, init); // entry point //this.id = '370784198902283034'; this.modulusArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); this.modArr = new Array( 1,0, 10, 9, 8, 7, 6, 5, 4, 3, 2); var sum:int = 0; for (var index:int = 0; index < 17; index++) { if (this.id.charAt(index)!="*") { sum += (int(id.charAt(index))*this.modulusArr[index]); } } //sum-= //if (this.id.charAt(17) == "x") var modulus:int = this.id.charAt(17) == "x"?10:int(this.id.charAt(17)); sum -= this.modArr[modulus]; trace("余数-->"+this.modArr[modulus]); for (var j:int = 0; j < 2; j++) { //trace(j); for (var k:int = 0; k < 9; k++) { //trace(); for (var l:int = 0; l < 3; l++) { for (var m:int = 0; m < 9; m++) { if (j + k == 0) continue; if (j == 1 && k > 2) continue; if ((sum + 7 * j + 9 * k + 10 * l + 5 * m)%11==0) { //trace("A:" + sum + 7 * j + 9 * k + 10 * l + 5 * m); trace(j+"-"+k+"-"+l+"-"+m); } } } } } } } }
对车票上隐藏月日的身份证号很感兴趣,于是写了个逆推小算法,不过结尾是x的结果不准确,有待改进
不过得到的解不是唯一的,一般有十组解左右.