fix few small things

This commit is contained in:
relikd
2021-02-13 22:24:17 +01:00
parent e4b4ed4498
commit 8ae643126e
3 changed files with 3 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ class Probability(object):
self.prob = [0] * 29 self.prob = [0] * 29
for r in numstream: for r in numstream:
self.prob[r] += 1 self.prob[r] += 1
self.N = len(numstream) self.N = sum(self.prob)
def IC(self): def IC(self):
X = sum(x * (x - 1) for x in self.prob) X = sum(x * (x - 1) for x in self.prob)

View File

@@ -92,7 +92,7 @@ class RuneText(object):
def __invert__(self): def __invert__(self):
return RuneText([~x for x in self._data]) return RuneText([~x for x in self._data])
def __str__(self): def __repr__(self):
return f'RuneText<{len(self)}>' return f'RuneText<{len(self)}>'
@property @property

View File

@@ -39,7 +39,7 @@ def break_cipher(fname, candidates, solver, key_fn):
outfmt = 'IoC: {}, interrupt: {}, count: {}, solver: {}' outfmt = 'IoC: {}, interrupt: {}, count: {}, solver: {}'
for irp_count, score, irp, kl, skips in candidates: for irp_count, score, irp, kl, skips in candidates:
stops, upto = db_i.consider(fname, irp, irp_count) stops, upto = db_i.consider(fname, 28 - irp if INVERT else irp, irp_count)
print(outfmt.format(score, LP.RUNES[irp], len(stops), key_fn.__name__)) print(outfmt.format(score, LP.RUNES[irp], len(stops), key_fn.__name__))
testcase = data[:upto] testcase = data[:upto]
for x in reversed(skips): for x in reversed(skips):