![]() |
【转帖】通用函数 身份证号码升位 - 精华帖集合
通用函数 身份证号码升位 - 精华帖集合
www.dimcax.com 通用函数 身份证号码升位 , , , ;;;======================================================== ;;;功能:通用函数 由15或17位身份证号码计算其效验码 ;;;参数:id ----15或17位长度字符串表示的身份证号码 ;;;返回:效验码字符 ,或nil ;;;日期:zml84 于 2007-12-17 (defun getk (id / lst_id i lst_w tmp) (if (or (= (strlen id) 15) (= (strlen id) 17) ) (progn ;;如果是15位,则年份添加19 (if (= (strlen id) 15) (setq id (strcat (substr id 1 6) "19" (substr id 7))) ) ;;化为数字表 (setq lst_id '() i 17 ) (repeat 17 (setq lst_id (cons (atoi (substr id i 1)) lst_id)) (setq i (1- i)) ) ;;加权因子 (setq lst_w '(7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2)) ;;计算和 (setq tmp 0 i 0 ) (repeat 17 (setq tmp (+ tmp (* (nth i lst_id) (nth i lst_w)))) (setq i (1+ i)) ) ;;取模 (setq tmp (rem tmp 11)) ;;查表得效验码 (substr "10x98765432" (1+ tmp) 1) ) ) ) ;;;============================================================ ;;;功能:身份证号码由15位或17升为18位 ;;;参数:id ----长度15或17字符串表示的身份证号码 ;;;返回:升位后的18位身份证号码 ,或nil ;;;日期:zml84 于 2007-12-17 (defun test1 (id / k) (if (or (= (strlen id) 15) (= (strlen id) 17) ) (progn ;;如果是15位,则年份添加19 (if (= (strlen id) 15) (setq id (strcat (substr id 1 6) "19" (substr id 7))) ) ;;获取效验码 (setq k (getk id)) ;;返回 (strcat id k) ) ) ) ;;;============================================================ ;;;功能:18位身份证号码验证 ;;;参数:id ----长度18字符串表示的身份证号码 ;;;返回:若正确返回t,否则nil ;;;日期:zml84 于 2007-12-17 (defun test2 (id / k) (and (= (strlen id) 18) ;;获取效验码 (setq k (getk (substr id 1 17))) ;;返回 (= k (strcase (substr id 18))) ) ) ;;;============================================================ [ ] 楼主辛苦了 赛,这算法怎么得到的? 书山有路勤为径,学海无涯苦作舟! 这就叫强,哈哈,看了许多遍,就一个字,强! impossible is nothing 厉害,顶起 |
所有的时间均为北京时间。 现在的时间是 11:49 AM. |