Beispiel #1
0
        /// <summary>
        ///     Obfuscate the specified number.
        /// </summary>
        /// <param name="value">
        ///     Non-negative integer to obfuscate.
        /// </param>
        /// <returns>
        ///     The obfuscated string of the specified number.
        /// </returns>
        public string Obfuscate(int value)
        {
            if (value < 0)
            {
                throw new InvalidOperationException("Negative values are not supported.");
            }

            var baseValue = BaseConverter.ConvertToBase(value);

            return(ObfuscatorHelper.AddDummyCharacters(baseValue, Strategy, Seed));
        }
Beispiel #2
0
        /// <summary>
        ///     Obfuscate the specified number.
        /// </summary>
        /// <param name="value">
        ///     Non-negative integer to obfuscate.
        /// </param>
        /// <returns>
        ///     The obfuscated string of the specified number.
        /// </returns>
        public string Obfuscate(Int64 value)
        {
            /*if (value < 0)
             *  throw new InvalidOperationException("Negative values are not supported.");*/

            // var baseValue =  AnyBaseConvert.ConvertToBase(value);
            var baseValue = AnyBaseConvert.Convert(value.ToString(), AnyBaseConvert.BaseCharSet.Base10,
                                                   AnyBaseConvert.BaseCharSet.Base66_Url_Safe_Custom);

            return(ObfuscatorHelper.AddDummyCharacters(baseValue, Strategy, Seed));
        }
        public void TestAddDummyCharacters(ObfuscationStrategy strategy)
        {
            var validCharacters = Settings.ValidCharacterSet;
            var dummyCharacters = Settings.DummyCharacterSet;

            // Generate valid input by taking first 3 characters of validCharacters.
            string validInput = new string(validCharacters.Dictionary.Select(x => x.Value).Take(3).ToArray());

            /* Perform operation under test with constant strategy, */
            var obfuscator = ObfuscatorFactory.NewInstance;
            int seed       = obfuscator.Seed;
            var testResult = ObfuscatorHelper.AddDummyCharacters(validInput, strategy, seed);

            // Remove all valid characters from result.
            var dummyResult = testResult.ToCharArray().ToList();

            dummyResult.RemoveAll(x => validCharacters.ContainsValue(x));

            // Ensure result only contains dummy characters.
            Assert.True(dummyResult.All(x => dummyCharacters.Contains(x)));
        }