def cribDragging1(ct, keyword): wordlist = encode_es(keyword) ctlist = [] if len(ct) >= len(wordlist): for i in range(len(ct) - len(wordlist)): ct2 = [] for j, c in enumerate(wordlist): ct2.append(ct[i + j] ^ c) ctlist.append(ct2) return [decode_es(ct) for ct in ctlist]
def testPos(ct, pos, wordlist): res = [] for word in wordlist: word_code = encode_es(word) xor_product = [ ct[pos + i] ^ word_pos for i, word_pos in enumerate(word_code) ] xor_product_str = decode_es(xor_product) if not any([ x in xor_product_str for x in ['1', '2', '3', '4', ' ', '..', ' .'] ]): prob = ngramtree.evaluateLogProb( xor_product, ngram_length) / (len(xor_product) - ngram_length) if not isinf(prob) and not isnan(prob) and prob < 0: res.append((word, xor_product_str, prob)) res.sort(key=lambda tup: tup[2], reverse=True) return res
T1 = np.zeros(shape=(stateCount, obsCount)) # store probability of the most likely path so far T2 = np.zeros(shape=(stateCount, obsCount), dtype='uint32') # store previous most likely state in the path # initialize matrices with first n letters print('j: 0') for i in range(stateCount): T1[i,0] = unigram[charset[i]] T2[i,0] = 0 print('j: 1') for i in range(stateCount): # get transition probabilities probs = [] for k in range(stateCount): str1 = decode_es([k, i]) str2 = decode_es([k^ct[0], i^ct[1]]) if str1 not in bigram or str2 not in bigram: prob = -inf else: prob = log(T1[k, 0]) + \ log(bigram[str1]/unigram[str1[0]]) + \ log(bigram[str2]/unigram[str2[0]]) probs.append(prob) T1[i,1] = max(probs) if isneginf(T1[i,1]): logger.debug('Got -inf prob at j: %d, str1: %s, str2: %s' % (1, str1, str2)) T2[i,1] = int(np.array(probs).argmax()) for j in range(2, obsCount):