Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 516b6f2

Browse files
committed
Filled out PermutationDecoder just a little.
1 parent 3a4f419 commit 516b6f2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,13 @@ def decode(self, ciphertext):
335335
"Search for a decoding of the ciphertext."
336336
self.ciphertext = ciphertext
337337
problem = PermutationDecoderProblem(decoder=self)
338-
return search.best_first_tree_search(problem, self.score)
338+
return search.best_first_tree_search(
339+
problem, lambda node: self.score(node.state))
339340

340-
def score(self, ciphertext, code):
341+
def score(self, code):
341342
"""Score is product of word scores, unigram scores, and bigram scores.
342343
This can get very small, so we use logs and exp."""
343-
text = decode(ciphertext, code)
344+
text = permutation_decode(self.ciphertext, code)
344345
logP = (sum([log(self.Pwords[word]) for word in words(text)]) +
345346
sum([log(self.P1[c]) for c in text]) +
346347
sum([log(self.P2[b]) for b in bigrams(text)]))

0 commit comments

Comments
 (0)