コード例 #1
0
        // Function: sanitize_line
        // Description: Returns a sanitized version of the line passed in.
        // Uses Functions:
        // Parameters: Line from an ACH file.
        // Pre-Conditions: string
        // Post-Conditions: string
        // Return: Sanitized version of line.
        public static string sanitize_line(string line)
        {
            StringBuilder sanitizedLine = new StringBuilder(line); // Deal with line as a stringbuilder for convenience.

            if (line[0] == '6')                                    // Card numbers are only on lines that start with 6.
            {
                // Sanitize number.
                ulong number = UInt64.Parse(line.Substring(12, 16));
                sanitizedLine.Remove(12, 16);
                sanitizedLine.Insert(12, (CardFunctions.get_sanitized_number(number)).ToString());

                // Sanitize name.
                for (int i = 39; i < 78; i++)
                {
                    sanitizedLine[i] = char_randomizer(sanitizedLine[i]);
                }
            }
            else if (line[0] == '5')
            {
                // Sanitize name.
                for (int i = 53; i < 68; i++)
                {
                    sanitizedLine[i] = char_randomizer(sanitizedLine[i]);
                }
            }
            return(sanitizedLine.ToString());
        }
コード例 #2
0
        // Function: get_sanitized_number
        // Description: Returns sanitized version of card number.
        // Uses Functions: get_corrected_number
        // Parameters: Number to be sanitized.
        // Pre-Conditions: Valid card number.
        // Post-Conditions: Number retains first 5 digits then is all zeros, except for the check digit at the end that will pass the Luhn Algorithm.
        // Return: Sanitized number.
        public static ulong get_sanitized_number(ulong num)
        {
            ulong returnNum  = 0;
            int   checkDigit = CardFunctions.get_last_digit(num);

            int[] digits = num.ToString().Select(Convert.ToInt32).ToArray(); // Convert num into array of digits.

            for (int i = 0; i < 5; i++)                                      // Retain first 5 digits of the number, and zero the rest.
            {
                digits[i] -= 48;
                returnNum += Convert.ToUInt64(digits[i]) * Convert.ToUInt64(Math.Pow(10, digits.Length - i - 1));
            }

            return(get_corrected_number(returnNum)); // Return number with the correct check digit at the end.
        }