2014年3月12日水曜日

忘れていた

ブログが三日坊主になっていたので更新
モジュラス103もそのうち更新するよてえい

電子タバコおいしいれす(^q^)

C#で9DSRの計算

  1. /// <summary>  
  2. /// 9DSR 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string Get9DSR(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.     return (ulong.Parse(Value) % 9 == 0 ? 0 : 9 - (int.Parse(Value) % 9)).ToString();  
  14. }  

C#でルーンズ(モジュラス10/ウェイト2)の計算

  1. /// <summary>  
  2. /// ルーンズ(モジュラス10/ウェイト2 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string GetModulus10Weight2Runes(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     long checkDigit = 0;  
  15.   
  16.     for (int i = 0; i < Value.Length; i++)  
  17.     {  
  18.         if (i % 2 == 0)  
  19.         {  
  20.             int x = int.Parse(Value.Substring(Value.Length - 1 - i, 1)) * 2;  
  21.             //10以上の場合、桁ごとに加算  
  22.             if (10 <= x) x = 1 + (x % 10);  
  23.   
  24.             checkDigit += x;  
  25.         }  
  26.         else  
  27.         {  
  28.             checkDigit += int.Parse(Value.Substring(Value.Length - 1 - i, 1));  
  29.         }  
  30.     }  
  31.   
  32.     checkDigit = 10 - (checkDigit % 10);  
  33.   
  34.     checkDigit = checkDigit == 10 ? 0 : checkDigit;  
  35.   
  36.     return checkDigit.ToString();  
  37. }  

C#で加重モジュラス11の計算

  1. /// <summary>  
  2. /// 加重モジュラス11 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string GetWeightedModulus11(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result || Value.Length > 12)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     int[] weight1 = { 2, 6, 3, 5, 4, 8, 7, 10, 9, 5, 3, 6, };  
  15.     int[] weight2 = { 9, 5, 8, 6, 7, 3, 4, 10, 2, 6, 8, 5, };  
  16.   
  17.     try  
  18.     {  
  19.         int checkDigit = 0;  
  20.         for (int i = 0; i < 2; i++)  
  21.         {  
  22.             checkDigit = 0;  
  23.             for (int j = 0; j < Value.Length; j++)  
  24.             {  
  25.                 checkDigit += int.Parse(Value.Substring(Value.Length - 1 - j, 1)) * (i == 0 ? weight1[j] : weight2[j]);  
  26.             }  
  27.             checkDigit = checkDigit % 11;  
  28.   
  29.             if (checkDigit == 0) return "0";  
  30.             if (checkDigit != 1) break;  
  31.         }  
  32.   
  33.         return (11 - checkDigit).ToString();  
  34.     }  
  35.     catch  
  36.     { }  
  37.     return null;  
  38. }  

C#でモジュラス10/ウェイト2の計算

  1. /// <summary>  
  2. /// モジュラス10/ウェイト2 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string GetModulus10Weight2(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     int checkDigit = 0;  
  15.   
  16.     for (int i = 0; i < Value.Length; i++)  
  17.     {  
  18.         checkDigit += int.Parse(Value.Substring(Value.Length - 1 - i, 1)) * (i % 2 == 0 ? 2 : 1);  
  19.     }  
  20.   
  21.     checkDigit = 10 - (checkDigit % 10);  
  22.   
  23.     checkDigit = checkDigit == 10 ? 0 : checkDigit;  
  24.   
  25.     return checkDigit.ToString();  
  26. }  

C#でモジュラス11の計算

  1. /// <summary>  
  2. /// モジュラス11 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string GetModulus11(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result || 6 > Value.Length)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     string val = Value.Substring(0, 6);  
  15.   
  16.     int checkDigit = 0;  
  17.     for (int i = 0; i < val.Length; i++)  
  18.     {  
  19.         checkDigit += int.Parse(val.Substring(i, 1)) * (7 - i);  
  20.     }  
  21.     checkDigit = checkDigit % 11;  
  22.   
  23.     if (checkDigit == 0)  
  24.     {  
  25.         return "1";  
  26.     }  
  27.     else if (checkDigit == 1)  
  28.     {  
  29.         return "0";  
  30.     }  
  31.     else  
  32.     {  
  33.         return (11 - checkDigit).ToString();  
  34.     }  
  35. }  

C#で9DRの計算

  1. /// <summary>  
  2. /// 9DR 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string Get9DR(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     return (ulong.Parse(Value) % 9).ToString();  
  15. }  

C#で7DSRの計算

  1. /// <summary>  
  2. /// 7DSR 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string Get7DSR(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     string value =(ulong.Parse(Value) % 7 == 0 ? 0 : 7 - (ulong.Parse(Value) % 7)).ToString();  
  15.   
  16.     return value;  
  17. }  

C#でモジュラス16の計算

  1. /// <summary>  
  2. /// モジュラス16 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string GetModulus16(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9|\-|$|:|/|・|+|A-D]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     long digit = 0;  
  15.     for (int i = 0; i < Value.Length; i++)  
  16.     {  
  17.         digit += Array.IndexOf(modulus16CharList, Value[i]);  
  18.     }  
  19.   
  20.     string value = modulus16CharList[(digit % 16) == 0 ? 0 : 16 - (digit % 16)].ToString();  
  21.   
  22.     return value;  
  23. }  

C#で7DRの計算

  1. /// <summary>  
  2. /// 7DR 計算  
  3. /// NW-7  
  4. /// </summary>  
  5. /// <param name="Value">/// <returns></returns>  
  6. public static string Get7DR(string Value)  
  7. {  
  8.     bool result = Regex.IsMatch(Value, @"^[0-9]+$");  
  9.     if (!result)  
  10.     {  
  11.         return null;  
  12.     }  
  13.   
  14.     string value = (ulong.Parse(Value) % 7).ToString();  
  15.   
  16.     return value;  
  17. }