private static int CalculateChecksum(int[] weights, StringNumber number, bool tverrsum)
        {
            int checksum = 0;

            for (int i = 0; i < weights.Length; i++)
            {
                int weight        = weights[i];
                int currentNumber = number.GetAt(weights.Length - 1 - i);
                int product       = weight * currentNumber;

                if (tverrsum)
                {
                    if (product > 9)
                    {
                        checksum += product - 9;
                    }
                    else
                    {
                        checksum += product;
                    }
                }
                else
                {
                    checksum += product;
                }
            }
            return(checksum);
        }
        protected static int CalculateMod10CheckSum(int[] weights, StringNumber number)
        {
            int checksum = CalculateChecksum(weights, number, true)%10;

            if (checksum == 0)
                return 0;
            else
                return 10 - checksum;
        }
 protected static int[] GetMod11Weights(StringNumber k)
 {
     var weights = new int[k.GetLength() - 1];
     for (int i = 0; i < weights.Length; i++)
     {
         int j = i%BaseMod11Weights.Length;
         weights[i] = BaseMod11Weights[j];
     }
     return weights;
 }
        protected static int CalculateMod11CheckSum(int[] weights, StringNumber number)
        {
            int c = CalculateChecksum(weights, number, false) % 11;

            if (c == 1)
            {
                throw new ArgumentException(ERROR_INVALID_CHECKSUM + number);
            }
            return(c == 0 ? 0 : 11 - c);
        }
        protected static int CalculateMod11CheckSum(int[] weights, StringNumber number)
        {
            int checksum = CalculateChecksum(weights, number, false)%11;
            if (checksum == 1)
                throw new ArgumentException(InvalidChecksumErrorMessage + number);

            if (checksum == 0)
                return 0;
            else
                return 11 - checksum;
        }
        protected static int[] GetMod11Weights(StringNumber k)
        {
            var weights = new int[k.GetLength() - 1];

            for (int i = 0; i < weights.Length; i++)
            {
                int j = i % BaseMod11Weights.Length;
                weights[i] = BaseMod11Weights[j];
            }
            return(weights);
        }
 protected static int[] GetMod10Weights(StringNumber k)
 {
     var weights = new int[k.GetLength() - 1];
     for (int i = 0; i < weights.Length; i++)
     {
         if ((i%2) == 0)
             weights[i] = 2;
         else
             weights[i] = 1;
     }
     return weights;
 }
        protected static int CalculateMod10CheckSum(int[] weights, StringNumber number)
        {
            int checksum = CalculateChecksum(weights, number, true) % 10;

            if (checksum == 0)
            {
                return(0);
            }
            else
            {
                return(10 - checksum);
            }
        }
        protected static int[] GetMod10Weights(StringNumber k)
        {
            var weights = new int[k.GetLength() - 1];

            for (int i = 0; i < weights.Length; i++)
            {
                if ((i % 2) == 0)
                {
                    weights[i] = 2;
                }
                else
                {
                    weights[i] = 1;
                }
            }
            return(weights);
        }
        protected static int CalculateMod11CheckSum(int[] weights, StringNumber number)
        {
            int checksum = CalculateChecksum(weights, number, false) % 11;

            if (checksum == 1)
            {
                throw new ArgumentException(InvalidChecksumErrorMessage + number);
            }

            if (checksum == 0)
            {
                return(0);
            }
            else
            {
                return(11 - checksum);
            }
        }
예제 #11
0
        private static int CalculateChecksum(int[] weights, StringNumber number, bool tverrsum)
        {
            int checkSum = 0;

            for (int i = 0; i < weights.Length; i++)
            {
                int product = weights[i] * number.GetAt(weights.Length - 1 - i);
                if (tverrsum)
                {
                    checkSum += (product > 9 ? product - 9 : product);
                }
                else
                {
                    checkSum += product;
                }
            }
            return(checkSum);
        }
        private static int CalculateChecksum(int[] weights, StringNumber number, bool tverrsum)
        {
            int checksum = 0;
            for (int i = 0; i < weights.Length; i++)
            {
                int weight = weights[i];
                int currentNumber = number.GetAt(weights.Length - 1 - i);
                int product = weight*currentNumber;

                if (tverrsum)
                {
                    if (product > 9) checksum += product - 9;
                    else checksum += product;
                }
                else
                {
                    checksum += product;
                }
            }
            return checksum;
        }
예제 #13
0
        protected static int CalculateMod10CheckSum(int[] weights, StringNumber number)
        {
            int c = CalculateChecksum(weights, number, true) % 10;

            return(c == 0 ? 0 : 10 - c);
        }