using System.Security.Cryptography;
public static void Main()
string[] subdomains = new[] { "customer1", "222", "blah", "longsubdomain", "longersubdomainstill" };
int[] randomIndex = new[] { 0, 5, 10, 20, 12 };
foreach (var index in randomIndex)
Console.WriteLine("index: " + index);
foreach (var subdomain in subdomains)
Console.WriteLine(subdomain);
Console.WriteLine("\tiscanary:" + IsCanaryUI(subdomain, index));
Console.WriteLine("-------");
private static bool IsCanaryUI(string customerId, int index)
var currentCanaryPercent = 38;
var customerMd5 = GetMd5(customerId);
var targetKey = customerMd5[index];
var hexKey = Convert.ToInt32("0x"+targetKey, 16);
Console.WriteLine("\tmd5: " + customerMd5);
Console.WriteLine("\ttarget: " + targetKey);
Console.WriteLine("\thexkey: " + hexKey);
var customerOptInPercent = Math.Floor(hexKey * 6.25);
Console.WriteLine("\tcustomerPercent:" + customerOptInPercent);
return customerOptInPercent < currentCanaryPercent;
private static string GetMd5(string customerId)
var hash = new StringBuilder();
var md5provider = new MD5CryptoServiceProvider();
byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(customerId));
for (int i = 0; i < bytes.Length; i++)
hash.Append(bytes[i].ToString("x2"));