Ejemplo n.º 1
0
 def decode_vault_size(self, lhs, cf):
     assert not lhs.startswith('L')
     cf %= self.G[lhs]['__total__']
     if cf == 0:
         return cf
     i = getIndex(cf, self.G[lhs].values())
     return i + 1
Ejemplo n.º 2
0
 def decode_vault_size(self, lhs, cf):
     assert not lhs.startswith('L')
     cf %= self.G[lhs]['__total__']
     if cf == 0:
         return cf
     i = getIndex(cf, self.G[lhs].values())
     return i+1
Ejemplo n.º 3
0
 def decode_vault_size(self, lhs, cf):
     assert not lhs.startswith('L')
     assert lhs in self.G, "lhs={} must be in G. I cannot find it in\nG.keys()={}" \
         .format(lhs, list(self.G.keys()))
     cf %= self.G[lhs]['__total__']
     if cf == 0:
         print_err("Grammar of size 0!!!!\nI don't think the decryption will "
                   "be right after this. I am sorry. Argument: (lhs: {}, cf: {})".format(lhs, cf))
     i = getIndex(cf, list(self.G[lhs].values()))
     return i + 1
Ejemplo n.º 4
0
 def decode_vault_size(self, lhs, cf):
     assert not lhs.startswith('L')
     assert lhs in self.G, "lhs={} must be in G. I cannot find it in\nG.keys()={}"\
         .format(lhs, self.G.keys())
     cf %= self.G[lhs]['__total__']
     if cf == 0:
         print_err("Grammar of size 0!!!!\nI don't think the decryption will "
                   "be right after this. I am sorry. Argument: (lhs: {}, cf: {})".format(lhs, cf))
     i = getIndex(cf, self.G[lhs].values())
     return i+1
Ejemplo n.º 5
0
def getGenerationAtRule(lhs, prob, grammar):
    """
    given a left hand side of a rule and the grammar it finds the exact rhs
    which has CP(cumulative Probability) in the ruleset just more than the given 
    `prob`
    :returns `('IloveYou',0,420)`
    """
    # REMEMBER: every array in grammar rule should have start with a
    # dummy entry('',0,0) and prob zero!!
    d = [0]

    d.extend([x[2] for x in grammar[lhs]])
    for i in range(1, len(d)):
        d[i] += d[i - 1];
    prob = prob % d[-1]
    t = getIndex(d, 0, len(d) - 1, prob) - 1;
    return grammar[lhs][t]
Ejemplo n.º 6
0
 def freq2key(f, T, A):
     i = getIndex(f, A)
     w = T.restore_key(i)
     return w, A[i]