手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>C/C++>列表

用c#实现由15位身份证号升级到18位的算法_c#应用

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
1using System;
2using System.Collections;
3
4public class MyClass
5{
6 public static void Main()
7 {
8 Console.WriteLine(per15To18("429005811009091"));
9 RL();
10 }
11
12 public static string per15To18(string perIDSrc)
13 {
14 int iS = 0;
15
16 //加权因子常数
17 int[] iW=new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
18 //校验码常数
19 string LastCode="10X98765432";
20 //新身份证号
21 string perIDNew;
22
23 perIDNew=perIDSrc.Substring(0,6);
24 //填在第6位及第7位上填上‘1’,‘9’两个数字
25 perIDNew = "19";
26
27 perIDNew = perIDSrc.Substring(6,9);
28
29 //进行加权求和
30 for( int i=0; i<17; i )
31 {
32 iS = int.Parse(perIDNew.Substring(i,1)) * iW[i];
33 }
34
35 //取模运算,得到模值
36 int iY = iS;
37 //从LastCode中取得以模为索引号的值,加到身份证的最后一位,即为新身份证号。
38 perIDNew = LastCode.Substring(iY,1);
39
40 return perIDNew;
41 }
42
43
44
45
46 Helper methods#region Helper methods
47
48 private static void WL(object text, params object[] args)
49 {
50 Console.WriteLine(text.ToString(), args);
51 }
52
53 private static void RL()
54 {
55 Console.ReadLine();
56 }
57
58 private static void Break()
59 {
60 System.Diagnostics.Debugger.Break();
61 }
62
63 #endregion
64}
http://www.cnblogs.com/goody9807/archive/2006/11/13/559378.html

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!