private IEnumerable <string> SelectPasswords(IRandomNumberGenerator random, int length, int count) { length = Math.Min(length, MaxLength); count = Math.Min(count, MaxCount); if (count <= 0 || length <= 0) { yield break; } var sw = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < count; i++) { var bytes = random.GetRandomBytes(length); var result = String.Join("", bytes.Select(x => x.ToString("x2"))); yield return(result); } sw.Stop(); var bytesRequested = (int)((random as Terninger.Random.CypherBasedPrngGenerator)?.BytesRequested).GetValueOrDefault(); RandomService.LogPasswordStat("Hex", count, sw.Elapsed, bytesRequested, IPAddressHelpers.GetHostOrCacheIp(Request).AddressFamily, HttpContext.GetApiKeyId()); if (!IpThrottlerService.HasAnyUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request))) { RandomService.AddWebRequestEntropy(this.Request); } IpThrottlerService.IncrementUsage(IPAddressHelpers.GetHostOrCacheIp(this.HttpContext.Request), count); }
private IEnumerable <string> SelectPasswords(IRandomNumberGenerator random, int length, int count) { length = Math.Min(length, MaxLength); count = Math.Min(count, MaxCount); if (count <= 0 || length <= 0) { yield break; } var sw = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < count; i++) { var bytes = random.GetRandomBytes(length); var result = String.Join("", bytes.Select(x => x.ToString("x2"))); yield return(result); } sw.Stop(); PostSelectionAction("Hex", count, sw.Elapsed, random); }
private async Task FuzzGenerator(int iterations, int bytesPerRequestMin, int bytesPerRequestMax, IRandomNumberGenerator generator, string filename) { var rng = new StandardRandomWrapperGenerator(); using (var sw = new StreamWriter(filename + ".txt", false, Encoding.UTF8)) { await sw.WriteLineAsync($"{generator.GetType().FullName} - {iterations:N0} iterations"); for (int i = 0; i < iterations; i++) { var bytesToGet = rng.GetRandomInt32(bytesPerRequestMin, bytesPerRequestMax); var bytes = generator.GetRandomBytes(bytesToGet); if (bytes == null) { await sw.WriteLineAsync("<null>"); } else { await sw.WriteLineAsync(bytes.ToHexString()); } } } }
public void WriteRandom(string name, int size) { var buffer = rng.GetRandomBytes(size); WriteOutput(name, buffer); }
/// <summary> /// Creates a random counter using the generator supplied. /// </summary> public static CypherCounter CreateRandom(int blockSizeBytes, IRandomNumberGenerator rand) { return(new CypherCounter(blockSizeBytes, rand.GetRandomBytes(blockSizeBytes))); }