public static List <PasswordEquivalenceClass> ToEquavalenceClasses(List <string> pwdList) { List <PasswordEquivalenceClass> pwdClassList = new List <PasswordEquivalenceClass>(); List <Password> pwdList_PasswordClass = new List <Password>(); char delimiter = ' '; string[] parts; foreach (var pwd_string in pwdList) { parts = pwd_string.Split(delimiter); var pwd_PasswordClass = new Password() { Frequency = int.Parse(parts[0]), Index = int.Parse(parts[1]) }; pwdList_PasswordClass.Add(pwd_PasswordClass); } var pwdClasses = from item in pwdList_PasswordClass group item by item.Frequency; foreach (var pwdClass in pwdClasses) { var pc = new PasswordEquivalenceClass() { NumberOfUsersSharingASpecificPassword = pwdClass.Key, PasswordOccurrence = pwdClass.Count() }; pwdClassList.Add(pc); } using (StreamWriter sr = new StreamWriter(@"/Users/wenjiebai/Projects/SketchCountTest/pwc.txt")) { foreach (var item in pwdClassList) { Console.WriteLine(item.NumberOfUsersSharingASpecificPassword + " " + item.PasswordOccurrence); } } return(pwdClassList); }
//private Dictionary<string, string> ClassifySampled_EC(List<Password> sampled_dist, double threshold1, double threshold2) //{ // Dictionary<string, string> dic = new Dictionary<string, string>(); // var q = from x in sampled_dist // group x by new { prob = x.ActualProbability} into g // orderby g.Key.frequency // select g; // foreach (var sampledPwd in sampled_dist) // { // if (sampledPwd.ActualProbability <= threshold1) // { // sampledPwd.Strength = "strong"; // } // else if (sampledPwd.ActualProbability <= threshold2) // { // sampledPwd.Strength = "medium"; // } // else // { // sampledPwd.Strength = "weak"; // } // dic.Add(sampledPwd.Name, sampledPwd.Strength); // } //var q = from x in sampled_dist // group x by new { frequency = x.UpdatedFrequency, strength = x.Strength } into g // orderby g.Key.frequency // select g; //int sum = 0; //using (StreamWriter sr = new StreamWriter(@"/Users/wenjiebai/Projects/SketchCountTest/OutputPEC_trained.txt")) //{ // foreach (var x in q) // { // sr.WriteLine(x.Key.frequency + " " + x.Key.strength + " " + x.Count()); // sum += x.Key.frequency * x.Count(); // } //} //Console.WriteLine("sanity check " + sum); // return dic; //} private List <PasswordEquivalenceClass> FakePasswords_To_EquivalenceClass(List <Password> pwd_user) { var pwd_dist = pwd_user.Distinct().ToList(); var q = from x in pwd_dist group x by x.UpdatedFrequency into g orderby g.Key descending select g; List <PasswordEquivalenceClass> sampled_pwdEC_List = new List <PasswordEquivalenceClass>(); foreach (var item in q) { Console.WriteLine(item.Key + " " + item.Count()); PasswordEquivalenceClass pwdEC = new PasswordEquivalenceClass() { NumberOfUsersSharingASpecificPassword = item.Key, PasswordOccurrence = item.Count() }; sampled_pwdEC_List.Add(pwdEC); } return(sampled_pwdEC_List); }