public static List <QualifiedSubset> ExpandPersonPaths(QualifiedSubset qualifiedPersons, List <Trustee> allpersons) { //TODO: do not expand more than longest subset in the access structure if (qualifiedPersons == null) { qualifiedPersons = new QualifiedSubset(); } List <QualifiedSubset> result = new List <QualifiedSubset>(); foreach (Trustee item in allpersons) { //don't add same party twice if (qualifiedPersons.Parties.Contains(item)) { continue; } QualifiedSubset qs = new QualifiedSubset(); //List<Trustee> ls = new List<Trustee>(); qs.Parties.AddRange(qualifiedPersons.Parties); qs.Parties.Add(item); result.Add(qs); //expand the list except current item var nextExpansion = allpersons.Where(po => po.partyId != item.partyId).ToList(); //if(!result.Contains(qs)) result.AddRange(ExpandPersonPaths(qs, nextExpansion)); } return(result); }
public static bool IsQualifiedSubset(QualifiedSubset subsetToTest, AccessStructure miniamlAccess) { foreach (var qualifiedSet in miniamlAccess.Accesses) { if (!(qualifiedSet is QualifiedSubset)) continue; HashSet<int> a = new HashSet<int>(subsetToTest.Parties.Select(x => x.GetPartyId())); var qs = (QualifiedSubset)qualifiedSet; HashSet<int> b = new HashSet<int>(qs.Parties.Select(x => x.GetPartyId())); if (b.IsProperSubsetOf(a) || b.IsSubsetOf(a)) return true; } return false; }
public static List <ThresholdSubset> findFixedConcatThreshold(IEnumerable <QualifiedSubset> candidateSets, int k, int allparties, int NRSFT) { int allsentences = candidateSets.Count(); if (allsentences < 2) { return(null); } //fixed element normal case : just a fixed element in front of threshold candidates var fixedIntersection = candidateSets.Select(po => po.Parties).Aggregate((first, second) => first.Intersect(second).ToList()); //add trace fixedAttemptTrace.Add(string.Format("Set:{0}, Attempted fixed item:{1} + threshold:({2},{3})", QualifiedSubset.DumpElementsIntoSingleString(candidateSets) , new QualifiedSubset(fixedIntersection).ToString(), k, allparties)); if (fixedIntersection.Count > 0) { var smallerQS = new List <QualifiedSubset>(); //remove fixed part from parties and try to find normal threshold foreach (var qs in candidateSets) { var withoutFixedParties = qs.Parties.Except(fixedIntersection); if (withoutFixedParties.Count() > 0) { var tempqs = new QualifiedSubset(withoutFixedParties); smallerQS.Add(tempqs); } } var smallerQSinvolvedParties = QualifiedSubset.GetAllInvolvedParties(smallerQS).Parties.Count; var smallerK = k - fixedIntersection.Count; if (nCr(smallerQSinvolvedParties, smallerK) == allsentences) { var threshold = findThreshold(smallerQS, smallerK, smallerQSinvolvedParties, NRSFT, false); if (threshold != null) //now add the fixed part to the threshold { foreach (var th in threshold) { th.fixedParties = fixedIntersection; } return(threshold); } } } return(new List <ThresholdSubset>()); }
public static IEnumerable <QualifiedSubset> ExploreAllSubsets(ThresholdSubset threshold) { var comb = threshold.thresholdParties.Combinations(threshold.K).Select(po => new QualifiedSubset(po)); if (threshold.fixedParties != null && threshold.fixedParties.Count() > 0) { List <QualifiedSubset> largerQS = new List <QualifiedSubset>(); foreach (var qs in comb) { QualifiedSubset lqs = new QualifiedSubset(threshold.fixedParties.Union(qs.Parties)); largerQS.Add(lqs); } return(largerQS); } return(comb); }
public static QualifiedSubset GetAllInvolvedParties(IEnumerable<QualifiedSubset> elements) { var sum = new QualifiedSubset(); foreach (var qs in elements) { foreach (var party in qs.Parties) { if (!sum.Parties.Contains(party)) { sum.Parties.Add(party); } } } return sum; }
public AccessStructure(String minimalPath) { this.Accesses = new List<ISubset>(); try { string[] qualifiedsubsets = minimalPath.Split(','); foreach (var qs in qualifiedsubsets) { QualifiedSubset qualifiedssObj = new QualifiedSubset(qs); this.Accesses.Add(qualifiedssObj); } } catch { throw new Exception("Invalid access structure example of valid access: 1^2,3^2,2^3^4,2^5^6"); } }
public static QualifiedSubset GetAllInvolvedParties(IEnumerable <QualifiedSubset> elements) { var sum = new QualifiedSubset(); foreach (var qs in elements) { foreach (var party in qs.Parties) { if (!sum.Parties.Contains(party)) { sum.Parties.Add(party); } } } return(sum); }
public override String ToString() { //todo: fix hack tostring from QS QualifiedSubset qs = new QualifiedSubset(); qs.Parties.AddRange(this.thresholdParties); QualifiedSubset qss = new QualifiedSubset(); qss.Parties.AddRange(this.fixedParties); if (!String.IsNullOrEmpty(qss.ToString())) { return String.Format("{0} Threshold({1},{2})[{3}]", qss.ToString(), K, N, qs.ToString()); } else { return String.Format("Threshold({0},{1})[{2}]", K, N, qs.ToString()); } }
public AccessStructure(String minimalPath) { this.Accesses = new List <ISubset>(); try { string[] qualifiedsubsets = minimalPath.Split(','); foreach (var qs in qualifiedsubsets) { QualifiedSubset qualifiedssObj = new QualifiedSubset(qs); this.Accesses.Add(qualifiedssObj); } } catch { throw new Exception("Invalid access structure example of valid access: 1^2,3^2,2^3^4,2^5^6"); } }
public override String ToString() { //todo: fix hack tostring from QS QualifiedSubset qs = new QualifiedSubset(); qs.Parties.AddRange(this.thresholdParties); QualifiedSubset qss = new QualifiedSubset(); qss.Parties.AddRange(this.fixedParties); if (!String.IsNullOrEmpty(qss.ToString())) { return(String.Format("{0} Threshold({1},{2})[{3}]", qss.ToString(), K, N, qs.ToString())); } else { return(String.Format("Threshold({0},{1})[{2}]", K, N, qs.ToString())); } }
public static bool IsQualifiedSubset(QualifiedSubset subsetToTest, AccessStructure miniamlAccess) { foreach (var qualifiedSet in miniamlAccess.Accesses) { if (!(qualifiedSet is QualifiedSubset)) { continue; } HashSet <int> a = new HashSet <int>(subsetToTest.Parties.Select(x => x.GetPartyId())); var qs = (QualifiedSubset)qualifiedSet; HashSet <int> b = new HashSet <int>(qs.Parties.Select(x => x.GetPartyId())); if (b.IsProperSubsetOf(a) || b.IsSubsetOf(a)) { return(true); } } return(false); }
public static List<QualifiedSubset> ExpandPersonPaths(QualifiedSubset qualifiedPersons, List<Trustee> allpersons) { //TODO: do not expand more than longest subset in the access structure if (qualifiedPersons == null) qualifiedPersons = new QualifiedSubset(); List<QualifiedSubset> result = new List<QualifiedSubset>(); foreach (Trustee item in allpersons) { //don't add same party twice if (qualifiedPersons.Parties.Contains(item)) continue; QualifiedSubset qs = new QualifiedSubset(); //List<Trustee> ls = new List<Trustee>(); qs.Parties.AddRange(qualifiedPersons.Parties); qs.Parties.Add(item); result.Add(qs); //expand the list except current item var nextExpansion = allpersons.Where(po => po.partyId != item.partyId).ToList(); //if(!result.Contains(qs)) result.AddRange(ExpandPersonPaths(qs, nextExpansion)); } return result; }
public override bool Equals(Object obj) { // no "override" here if (obj == null || GetType() != obj.GetType()) { return(false); } QualifiedSubset p = (QualifiedSubset)(obj); if (this.Parties.Count == p.Parties.Count) { foreach (Trustee var in p.Parties) { if (!this.Parties.Contains(var)) { return(false); } } return(true); } return(false); }
public static List <ThresholdSubset> findThreshold(IEnumerable <QualifiedSubset> candidateSets, int k, int allparties, int NRSFT, bool findIntersection = true) { int allsentences = candidateSets.Count(); //add trace attemptTrace.Add(string.Format("Set:{0}, Attempted threshold:({1},{2})", QualifiedSubset.DumpElementsIntoSingleString(candidateSets), k, allparties)); // normal case List <ThresholdSubset> thresholds = new List <ThresholdSubset>(); var ncr = nCr(allparties, k); if (ncr == allsentences) { ThresholdSubset th = new ThresholdSubset(allparties, k, new List <Trustee>(), QualifiedSubset.GetAllInvolvedParties(candidateSets).Parties); thresholds.Add(th); } /// if the candidate set is larger than nCr then probably some sets don't belong to the threshold /// Here we recusrively rotate parties and select all possible combinations to see which ones are /// building threshold for e.g. p1p2p3 p2p3p4 p1p3p4 p1p2p4 p2p4p5 else if (allsentences < ncr) { if (NRSFT > allsentences) { NRSFT = GetNumberOfRequiredSetsForThreshold(allparties, k, allsentences); } if (NRSFT == 1) { return(thresholds); } //all possible candidate sets must be generated and recursively called var smallersetcombinations = candidateSets.Combinations(NRSFT); var subsetsAlreadyHaveThreshold = new List <QualifiedSubset>(); foreach (var smallerset in smallersetcombinations) { var newallparties = QualifiedSubset.GetAllInvolvedParties(smallerset).Parties.Count; List <ThresholdSubset> foundthresholds = new List <ThresholdSubset>(); //add trace attemptTrace.Add(string.Format("Set:{0}, Attempted threshold:({1},{2})", QualifiedSubset.DumpElementsIntoSingleString(smallerset), k, newallparties)); if (nCr(newallparties, k) == smallerset.Count() && k < newallparties)//not interested in k=n thresholds { foundthresholds = findThreshold(smallerset, k, newallparties, NRSFT, findIntersection); if (foundthresholds.Count > 0) { subsetsAlreadyHaveThreshold.AddRange(smallerset); } } ///try filtering the fixed sets maybe find a threshold if (foundthresholds.Count == 0 && findIntersection) { foundthresholds = findFixedConcatThreshold(smallerset, k, newallparties, NRSFT); } if (foundthresholds != null) { thresholds.AddRange(foundthresholds); } } if (--NRSFT > 1) { #if filterThresholds var minusAlreadyFoundSets = candidateSets.Except(subsetsAlreadyHaveThreshold); var minusSentences = minusAlreadyFoundSets.Count(); if (minusSentences < allsentences) { var minusInvolvedParties = QualifiedSubset.GetAllInvolvedParties(minusAlreadyFoundSets).Parties.Count; //calculate new NRSFT //NRSFT = GetNumberOfRequiredSetsForThreshold(minusInvolvedParties, k, minusAlreadyFoundSets.Count()); //if (NRSFT == 1) return thresholds; } thresholds.AddRange(findThreshold(minusAlreadyFoundSets, k, allparties, NRSFT, findIntersection)); #else thresholds.AddRange(findThreshold(candidateSets, k, allparties, NRSFT, findIntersection)); #endif } } return(thresholds); }
public static IEnumerable<QualifiedSubset> ExploreAllSubsets(ThresholdSubset threshold) { var comb = threshold.thresholdParties.Combinations(threshold.K).Select(po => new QualifiedSubset(po)); if (threshold.fixedParties != null && threshold.fixedParties.Count() > 0) { List<QualifiedSubset> largerQS = new List<QualifiedSubset>(); foreach (var qs in comb) { QualifiedSubset lqs = new QualifiedSubset(threshold.fixedParties.Union(qs.Parties)); largerQS.Add(lqs); } return largerQS; } return comb; }
public static List<ThresholdSubset> findFixedConcatThreshold(IEnumerable<QualifiedSubset> candidateSets, int k, int allparties,int NRSFT) { int allsentences = candidateSets.Count(); if (allsentences < 2) return null; //fixed element normal case : just a fixed element in front of threshold candidates var fixedIntersection = candidateSets.Select(po => po.Parties).Aggregate((first, second) => first.Intersect(second).ToList()); //add trace fixedAttemptTrace.Add(string.Format("Set:{0}, Attempted fixed item:{1} + threshold:({2},{3})", QualifiedSubset. DumpElementsIntoSingleString(candidateSets) , new QualifiedSubset(fixedIntersection).ToString(), k, allparties)); if (fixedIntersection.Count > 0) { var smallerQS = new List<QualifiedSubset>(); //remove fixed part from parties and try to find normal threshold foreach (var qs in candidateSets) { var withoutFixedParties = qs.Parties.Except(fixedIntersection); if (withoutFixedParties.Count() > 0) { var tempqs = new QualifiedSubset(withoutFixedParties); smallerQS.Add(tempqs); } } var smallerQSinvolvedParties = QualifiedSubset.GetAllInvolvedParties(smallerQS).Parties.Count; var smallerK = k - fixedIntersection.Count; if (nCr(smallerQSinvolvedParties, smallerK) == allsentences) { var threshold = findThreshold(smallerQS, smallerK,smallerQSinvolvedParties, NRSFT, false); if (threshold != null) //now add the fixed part to the threshold { foreach (var th in threshold) { th.fixedParties = fixedIntersection; } return threshold; } } } return new List<ThresholdSubset>(); }