博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
身份证号、姓名按照某个规则加密
阅读量:2119 次
发布时间:2019-04-30

本文共 2262 字,大约阅读时间需要 7 分钟。

1、身份证号加密
规则如下:
出生月份+1,如果超出12则变01;倒数第2、3位+1,如果超出99则变01,最后还要重新计算最后一位的校验码,计算规则如下:
(1)身份证号码前17位数分别乘以不同的系数并相加 7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2
(2)用第1步的结果除以11,余数只可能有0 1 2 3 4 5 6 7 8 9 10这11个数字中,分别对应身份证的最后一位1 0 X 9 8 7 6 5 4 3 2
       

例:110101198808083034 加密后为 110101198808083034

/// /// 证件加密:出生月份+1,如果超出12则变01;倒数第2、3位+1,如果超出99则变01,重计最后一位校验码/// /// /// 
public static string GetEncryptIdNo(string idno){ string tempIdno = "", newIdno = ""; if (idno.Length != 18) return idno; string head = idno.Substring(0, 10); string month = AddNumerOne(idno.Substring(10, 2), 12); string end = idno.Substring(12, 3) + AddNumerOne(idno.Substring(15, 2), 99); tempIdno = head + month + end; int[] Wi = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 }; string[] arrVerifyCode = { "1", "0", "x", "9", "8", "7", "6", "5", "4", "3", "2" }; int ret = 0; for (int i = 0; i < 17; i++) ret += int.Parse(tempIdno.Substring(i, 1)) * Wi[i]; newIdno = tempIdno.Substring(0, 17) + arrVerifyCode[ret %= 11]; return newIdno;}/// /// 对传进来的数加1,如果超过则减去参数v/// /// /// ///
private static string AddNumerOne(string s, int v){ int result = Convert.ToInt32(s) + 1; if (result > v) result = result - v; return result.ToString().PadLeft(2, '0');}
2、姓名的姓加密
规则如下:先获取系统所有的姓集合,保存为字典,根据传进来的参数姓,查找字典中对应的KEY值,替换为下一个KEY的姓,如果参数姓为最后一个,则替换为第一个KEY的姓。
例:传入姓名“何必”,则结果为“董必”。

/// /// 姓加密:根据传进来的参数姓,查找字典中对应的KEY值,替换为下一个KEY的姓,如果参数姓为最后一个,则替换为第一个KEY的姓,找不到则默认第一个KEY的姓/// /// /// 
public static string GetEncryptName(string name) { string result = ""; if (name.Length == 0) return ""; Dictionary
dict = new Dictionary
() { {1,"叶"},{2,"魏"},{3,"洪"},{4,"孙"},{5,"何"},{6,"董"},{7,"饶"},{8,"邵"},{9,"赖"},{10,"夏"}, {11,"肖"},{12,"付"},{13,"徐"},{14,"范"},{15,"孟"},{16,"柯"},{17,"任"},{18,"欧"},{19,"温"},{20,"邓"} //太多了。。这里省略不写 }; result = name.Substring(0, 1); int key = dict.FirstOrDefault(d => d.Value == result).Key + 1; if (key > dict.Keys.Count) key = key - dict.Keys.Count; result = dict.FirstOrDefault(d => d.Key == key).Value; return result + name.Substring(1); }

转载地址:http://hezrf.baihongyu.com/

你可能感兴趣的文章
行为型模式之策略模式(Strategy)
查看>>
行为型模式之模板方法模式(TemplateMethod)
查看>>
行为型模式之访问者模式(Visitor)
查看>>
大小端详解
查看>>
source insight使用方法简介
查看>>
<stdarg.h>头文件的使用
查看>>
C++/C 宏定义(define)中# ## 的含义 宏拼接
查看>>
Git安装配置
查看>>
linux中fork()函数详解
查看>>
C语言字符、字符串操作偏僻函数总结
查看>>
Git的Patch功能
查看>>
分析C语言的声明
查看>>
TCP为什么是三次握手,为什么不是两次或者四次 && TCP四次挥手
查看>>
C结构体、C++结构体、C++类的区别
查看>>
进程和线程的概念、区别和联系
查看>>
CMake 入门实战
查看>>
绑定CPU逻辑核心的利器——taskset
查看>>
Linux下perf性能测试火焰图只显示函数地址不显示函数名的问题
查看>>
c结构体、c++结构体和c++类的区别以及错误纠正
查看>>
Linux下查看根目录各文件内存占用情况
查看>>