public void IntMathPower() { Aver.AreEqual(1024, IntMath.Pow(2, 10)); Aver.AreEqual(2187, IntMath.Pow(3, 7)); Aver.AreEqual(390625, IntMath.Pow(5, 8)); Aver.AreEqual(0, IntMath.Pow(0, 0)); Aver.AreEqual(0, IntMath.Pow(0, 1)); Aver.AreEqual(1, IntMath.Pow(1, 0)); Aver.AreEqual(1, IntMath.Pow(100, 0)); Aver.AreEqual(100, IntMath.Pow(100, 1)); }
protected virtual IEnumerable <PasswordRepresentation> DoGeneratePassword(PasswordFamily family, PasswordRepresentationType type, PasswordStrengthLevel level) { if (family != PasswordFamily.Text && family != PasswordFamily.PIN) { yield break; } if ((type & PasswordRepresentationType.Text) != 0) { if (family == PasswordFamily.Text) { int score = 0; while (true) { using (var password = ExternalRandomGenerator.Instance.NextRandomWebSafeSecureBuffer(getMinLengthForLevel(family, level), getMaxLengthForLevel(family, level))) { score = CalculateStrenghtScore(family, password); if (score >= getMinScoreForLevel(family, level)) { var content = password.Content; var length = content.Length; var reprContent = new byte[length]; Array.Copy(content, reprContent, length); yield return(new PasswordRepresentation(PasswordRepresentationType.Text, "plain/text", reprContent)); break; } } } } if (family == PasswordFamily.PIN) { var min = getMinLengthForLevel(family, level); var max = getMaxLengthForLevel(family, level); var minValue = (int)IntMath.Pow(10, min - 1); var maxValue = (int)IntMath.Pow(10, max) - 1; var value = (uint)ExternalRandomGenerator.Instance.NextScaledRandomInteger(minValue, maxValue); var content = value.ToString(); var reprContent = new byte[content.Length]; for (int i = 0; i < content.Length; i++) { reprContent[i] = (byte)content[i]; } yield return(new PasswordRepresentation(PasswordRepresentationType.Text, "plain/text", reprContent)); } } }