示例#1
0
        /// <summary>
        /// 获取校验码
        /// </summary>
        /// <param name="code">组织机构代码前八位,注意必须大写字母或数字,如超出8位也只取前8位</param>
        /// <returns></returns>
        public static char GetCheckBit(string code)
        {
            if (code == null || !Regex.IsMatch(code, @"^[0-9A-Z]{8,}$"))
            {
                throw new ArgumentException("Error code.");
            }
            var mod = (11 - ISO7064_1983.MOD_11_2(code.Select(c => CodeDictionary[c]).Take(8).ToArray(), WeightingFactors, 11)) % 11;

            return(CheckBits[mod]);
        }
示例#2
0
        private char GetCheckBit(string code)
        {
            var mod = (31 - ISO7064_1983.MOD_11_2(code.Select(c => CodeDictionary[c]).Take(17).ToArray(), WeightingFactors, 31)) % 31;

            return(CodeDictionary.First(kv => kv.Value == mod).Key);
        }
 public void MOD_11_2_Error()
 {
     Assert.Throws <ArgumentException>(() => ISO7064_1983.MOD_11_2(null, null, 10));
     Assert.Throws <ArgumentException>(() => ISO7064_1983.MOD_11_2(new int[] { 1, 2 }, null, 10));
     Assert.Throws <ArgumentException>(() => ISO7064_1983.MOD_11_2(new int[] { 1, 2 }, new int[] { 1, 2, 3 }, 10));
 }
示例#4
0
        private char GetCheckBit(string idNumber)
        {
            var mod = ISO7064_1983.MOD_11_2(idNumber.Select(c => (int)c - 48).Take(17).ToArray(), WeightingFactors, 11);

            return(CheckBits[mod]);
        }