[OutputCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations(int?l) { IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), 1); // Return information about the number of combinations as a JSON object. var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var result = new JsonCombinationContainer(); result.combinations = Math.Pow(256, length); return(new JsonNetResult(result)); }
[OutputCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations(int?wc) { IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), 1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var wordCount = Math.Min(wc.HasValue ? wc.Value : DefaultWords, MaxWords); var dict = Dictionary.Value; result.combinations = Math.Pow(dict.Count, wordCount); return(new JsonNetResult(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations([FromQuery] int?sc) { IncrementUsage(1); var syllableCount = Math.Min(sc.HasValue ? sc.Value : DefaultSyllableCount, MaxSyllableCount); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); result.combinations = Math.Pow(ConsonantSounds.Length * VowelSounds.Length * (ConsonantSounds.Length * ProbabilityOfTwoConsonantsInOneSyllable), syllableCount); result.rating = _RatingService.Rate(result.combinations); return(Json(result)); }
[OutputCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations(int?sc) { IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), 1); var syllableCount = Math.Min(sc.HasValue ? sc.Value : DefaultSyllableCount, MaxSyllableCount); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); result.combinations = Math.Pow(ConsonantSounds.Length * VowelSounds.Length * (ConsonantSounds.Length * ProbabilityOfTwoConsonantsInOneSyllable), syllableCount); return(new JsonNetResult(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations([FromQuery] int?l, [FromQuery] string sym) { IncrementUsage(1); // Return information about the number of combinations as a JSON object. var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var result = new JsonCombinationContainer(); result.combinations = Math.Pow(256, length); result.rating = _RatingService.Rate(result.combinations); return(Json(result)); }
[OutputCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations(int?l) { IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), 1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); result.combinations = Math.Pow(Characters.Length, length); result.combinations -= (double)Blacklist.Value.Count(x => x.Length == l); // Remove blacklist entries. result.rating = PasswordRatingService.RatePin(result.combinations); return(new JsonNetResult(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public async Task <IActionResult> Combinations([FromQuery] int?wc) { IncrementUsage(1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var wordCount = Math.Min(wc.HasValue ? wc.Value : DefaultWords, MaxWords); var dict = await _DictionaryService.ReadPassphraseDictionary(); result.combinations = Math.Pow(dict.Count, wordCount); result.rating = _RatingService.Rate(result.combinations); return(Json(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public async Task <IActionResult> Combinations(int?l, string sym) { IncrementUsage(1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var blacklist = await _DictionaryService.ReadPinBlacklist(); result.combinations = Math.Pow(Characters.Length, length); result.combinations -= (double)blacklist.Count(x => x.Length == l); // Remove blacklist entries. result.rating = _RatingService.RatePin(result.combinations); return(Json(result)); }
[OutputCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations(int?l, string sym) { IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), 1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var symbols = sym.IsTruthy(DefaultSymbols); var charCount = symbols ? AllCharacters.Length : AlphanumericCharacters.Length; result.combinations = Math.Pow(charCount, length); return(new JsonNetResult(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations([FromQuery] int?l, [FromQuery] string sym) { IncrementUsage(1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var symbols = sym.IsTruthy(DefaultSymbols); var charCount = symbols ? AllCharacters.Length : AlphanumericCharacters.Length; result.combinations = Math.Pow(charCount, length); result.rating = _RatingService.Rate(result.combinations); return(Json(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations([FromQuery] int?l, [FromQuery] string bmp, [FromQuery] string asian) { IncrementUsage(1); var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var onlyFromBasicMultilingualPlane = bmp.IsTruthy(DefaultBmp); var includeEastAsianCharacters = asian.IsTruthy(DefaultAsian); var allowedCategories = includeEastAsianCharacters ? AsianCategories : DefaultCategories; var mask = onlyFromBasicMultilingualPlane ? 0x0000ffff : 0x001fffff; // This takes ~100ms to calculate on Murray's laptop, so we cache it. // Unless new unicode characters magically appear, the result will always be the same for our 3 inputs. var cacheKey = "UnicodeCombinations-" + (length | (onlyFromBasicMultilingualPlane ? 0x01000000 : 0) | (includeEastAsianCharacters ? 0x02000000 : 0)).ToString("x8"); int keyspace = _MemoryCache.GetOrCreate(cacheKey, ce => { var cacheKeyspace = Enumerable.Range(0, 0x001fffff & mask) .Where(cp => !(this.InvalidSurrogateCodePoints(cp) || this.InvalidMaxCodePoints(cp))) .Select(cp => Char.ConvertFromUtf32(cp)) .Where(s => allowedCategories.Contains(Char.GetUnicodeCategory(s, 0))) .Count(); ce.SetSlidingExpiration(TimeSpan.FromHours(24)) .SetValue(cacheKeyspace); return(cacheKeyspace); }); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); result.combinations = Math.Pow(keyspace, length); result.rating = _RatingService.Rate(result.combinations); return(Json(result)); }
[OutputCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations(int?l, string bmp, string asian) { IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), 1); var length = Math.Min(l.HasValue ? l.Value : DefaultLength, MaxLength); var onlyFromBasicMultilingualPlane = bmp.IsTruthy(DefaultBmp); var includeEastAsianCharacters = asian.IsTruthy(DefaultAsian); var allowedCategories = includeEastAsianCharacters ? AsianCategories : DefaultCategories; var mask = onlyFromBasicMultilingualPlane ? 0x0000ffff : 0x001fffff; // This takes ~100ms to calculate on Murray's laptop, so we cache it. // Unless new unicode characters magicly appear, the result will always be the same for our 3 inputs. var cacheKey = (length | (onlyFromBasicMultilingualPlane ? 0x01000000 : 0) | (includeEastAsianCharacters ? 0x02000000 : 0)).ToString("x8"); int keyspace = 0; var maybeKeyspace = MemoryCache.Default[cacheKey]; if (maybeKeyspace == null) { maybeKeyspace = Enumerable.Range(0, 0x001fffff & mask) .Where(cp => !(this.InvalidSurrogateCodePoints(cp) || this.InvalidMaxCodePoints(cp))) .Select(cp => Char.ConvertFromUtf32(cp)) .Where(s => allowedCategories.Contains(Char.GetUnicodeCategory(s, 0))) .Count(); MemoryCache.Default.Add(cacheKey, maybeKeyspace, DateTimeOffset.Now.AddHours(8)); } keyspace = (int)maybeKeyspace; // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); result.combinations = Math.Pow(keyspace, length); return(new JsonNetResult(result)); }
[ResponseCache(Duration = 60 * 60)] // Cache for one hour. #endif public ActionResult Combinations([FromQuery] int?gs, [FromQuery] int?ps) { IncrementUsage(1); // Return information about the number of combinations as a JSON object. var result = new JsonCombinationContainer(); var gridSize = Math.Min(gs.HasValue ? gs.Value : DefaultGridSize, MaxGridSize); var gridPoints = gridSize * gridSize; var points = Math.Min(Math.Min(ps.HasValue ? ps.Value : DefaultPoints, MaxPoints), gridPoints); // Can't use the nPr permutations formula, because the dots must be adjacent. // We calculate the approximate number of options available at each choice, and multiple them together. // For the standard 3x3 grid, this starts at 4.4 // As the grid size increases, this tends toward around 7 possibilities after the starting spot is chosen. double combinations; if (gridSize == 1) { combinations = 1; // 1x1 grid is a bit silly, and trivial. } else if (gridSize == 2) { combinations = 4 * 3 * 2 * 1; // 2x2 grid is very deterministic. } else { // Larger grids choose a random starting spot, then adjacent points, which limit possibilities. // The following isn't perfect, but a linear approximation of the probabilities involved: // First is always randomly chosen anywhere on the grid: possibilities = N² // Next follows this pattern: // 4 corners with 3 possible adjacent squares = 4 * 3 // 4 sides with 5 possible adjacent squares = (N-2) * 4 * 5 // Remainder in the middle have 8 adjacent squares = (N-2)² * 8 // Average possibilities = ((4*3) + ((N-2) * 4 * 5) + ((N-2)² * 8)) / N² // After that, we assume a linear decrease in average possibilities (which probably isn't quite right, but close enough). // We assume the last 2 are always 2, then 1. // So the "gap" or "step" between each point = (Average Possibilities - 1) / (N² - 2) double gridLengthMinusCorners = gridSize - 2; double total2ndChoiceOptions = (4 * 3) // Corners + (gridLengthMinusCorners * 4 * 5) // Sides + (gridLengthMinusCorners * gridLengthMinusCorners * 8); // Middle double avgOptions = total2ndChoiceOptions / gridPoints; // Average number of options for the total grid points. double availableOptions = avgOptions - 1; // The last value we accumulate should be ~1. double avgDiffPerStep = availableOptions / gridPoints; // This is the step we'll use when accumulating. combinations = gridPoints; // First choice is random between all points on the grid. var nextStepOptions = avgOptions; // Second choice is calculated above. if (points > 1) { combinations = combinations * nextStepOptions; // Accumulate. } for (int n = points - 2; n > 0; n--) { nextStepOptions = nextStepOptions - avgDiffPerStep; // Reduce each next step by the average. combinations = combinations * nextStepOptions; // And accumulate combinations. if (nextStepOptions <= 1) { nextStepOptions = 1; // Don't do dumb things with negative or small numbers in the calculation. } } } result.combinations = combinations; result.rating = _RatingService.RatePattern(result.combinations); return(Json(result)); }