Beispiel #1
0
        /// <summary>
        /// Fuzzes the passed in CCN
        /// </summary>
        /// <param name="creditCardNumber"></param>
        /// <param name="fuzzRules"></param>
        /// <param name="random"></param>
        /// <returns></returns>
        public String FuzzCreditCardNumber(String creditCardNumber, FuzzMethod fuzzMethod, Random random)
        {
            String       fuzzedCCN = null;
            StringFuzzer fuzzer    = new StringFuzzer(random);

            switch (fuzzMethod)
            {
            case (FuzzMethod.AdjacentCharactersSwapped):
            {
                // swap two adjacent/Unique characters (no fuzzRules yet)
                fuzzedCCN = fuzzer.SwapTwoUniqueAdjacentCharacters(creditCardNumber);
                break;
            }

            case (FuzzMethod.MissingRandomMiddleCharacter):
            {
                // simply remove a character from a random position within the CCN. The two end characters are preserved
                Char firstChar = creditCardNumber.First();
                Char lastChar  = creditCardNumber.Last();

                // delete a random character between the begining and end characters of the string
                String midCcn = fuzzer.DeleteRandomCharacter(creditCardNumber.Substring(1, creditCardNumber.Length - 2));

                // put the pieces back together again
                fuzzedCCN = String.Format("{0}{1}{2}", firstChar, midCcn, lastChar);
                break;
            }

            case (FuzzMethod.MissingFirstCharacter):
            {
                fuzzedCCN = creditCardNumber.Remove(0, 1);
                break;
            }

            case (FuzzMethod.MissingLastCharacter):
            {
                fuzzedCCN = creditCardNumber.Remove(creditCardNumber.Length - 1, 1);
                break;
            }

            case (FuzzMethod.RandomCharacterAdded):
            {
                fuzzedCCN = fuzzer.InsertRandomCharacter(creditCardNumber);
                break;
            }
            }

            return(fuzzedCCN);
        }
Beispiel #2
0
        /// <summary>
        /// Fuzz the passed in SSN string
        /// </summary>
        /// <param name="socialSecurityNumber"></param>
        /// <returns></returns>
        private string FuzzSocialSecurityNumber(String socialSecurityNumber, FuzzMethod fuzzMethod, Random random)
        {
            string fuzzedSsn = null;

            // if all the characters in the string are the same, this is essentially a no-op
            if (socialSecurityNumber.HasAllTheSameCharacters())
            {
                return(socialSecurityNumber);
            }

            // instance of the random class used for mixing up the list.
            if (random == null)
            {
                random = new Random(DateTime.Now.Millisecond);
            }

            // remove the dashes in the ssn
            char[] rawSsn = DataGenHelpers.GetRawSsn(socialSecurityNumber).ToCharArray();

            // Initialize string fuzzer
            StringFuzzer fuzzer = new StringFuzzer(random);

            // Fuzz Accordingly:
            switch (fuzzMethod)
            {
            case (FuzzMethod.AdjacentCharactersSwapped):
            {
                // Starting from a random position in a string, swap two unique and adjacent characters in that string.
                // If the string happens to have all the same characters, there is not much we can do
                fuzzer    = new StringFuzzer(random);
                fuzzedSsn = fuzzer.SwapTwoUniqueAdjacentCharacters(rawSsn);
                fuzzedSsn = DataGenHelpers.BuildFormattedSsn(fuzzedSsn);
                break;
            }

            case (FuzzMethod.MissingRandomMiddleCharacter):
            {
                // simply remove a character from a random position within the SSN. The two end characters are preserved
                Char firstChar = rawSsn.First();
                Char lastChar  = rawSsn.Last();

                // delete a random character between the begining and end characters of the string
                String midSsn = fuzzer.DeleteRandomCharacter(new String(rawSsn, 1, rawSsn.Length - 2));

                // put the pieces back together again
                fuzzedSsn = String.Format("{0}{1}{2}", firstChar, midSsn, lastChar);
                fuzzedSsn = DataGenHelpers.BuildFormattedSsn(fuzzedSsn);
                break;
            }

            case (FuzzMethod.MissingFirstCharacter):
            {
                fuzzedSsn = socialSecurityNumber.Remove(0, 1);
                break;
            }

            case (FuzzMethod.MissingLastCharacter):
            {
                fuzzedSsn = socialSecurityNumber.Remove(socialSecurityNumber.Length - 1, 1);
                break;
            }

            case (FuzzMethod.RandomCharacterAdded):
            {
                fuzzedSsn = fuzzer.InsertRandomCharacter(socialSecurityNumber);
                break;
            }
            }

            return(fuzzedSsn);
        }