From 6bd82e83ea8afa20a9f8e5f2d58cb66ea87faab9 Mon Sep 17 00:00:00 2001 From: relikd Date: Thu, 21 Jan 2021 02:49:57 +0100 Subject: [PATCH] add solved pages to interrupt db --- InterruptDB.py | 25 ++++++++++++++++--------- data/interruptDB.txt | 9 +++++++-- probability.py | 15 ++++++++++----- 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/InterruptDB.py b/InterruptDB.py index eeeebee..b971f3a 100755 --- a/InterruptDB.py +++ b/InterruptDB.py @@ -14,12 +14,15 @@ class InterruptDB(object): def make(self, keylen): def fn(x): return Probability.IC_w_keylen(x, keylen) - score, intrpts = self.iguess.sequential(fn, startAt=0, maxdepth=99) - # score, intrpts = self.iguess.genetic(fn, topDown=False, maxdepth=4) - # score, intrpts = fn(self.iguess.join()), [[]] # without interrupts - for i, skips in enumerate(intrpts): - intrpts[i] = self.iguess.to_occurrence_index(skips) - return score, intrpts + if keylen == 0: + keylen = 1 + score, skips = fn(self.iguess.join()), [[]] # without interrupts + else: + score, skips = self.iguess.sequential(fn, startAt=0, maxdepth=99) + # score, skips = self.iguess.genetic(fn, topDown=False, maxdepth=4) + for i, interrupts in enumerate(skips): + skips[i] = self.iguess.to_occurrence_index(interrupts) + return score, skips @staticmethod def load(): @@ -48,19 +51,20 @@ class InterruptDB(object): f.write(t) -def populate_db(irp_chars=range(1), startkeylen=1, maxkeylen=32): +def populate_db(irp_chars=range(1), startkeylen=1, maxkeylen=32, max_irp=20): oldDB = InterruptDB.load() oldValues = {k: set((a, b, c) for a, _, b, c, _ in v) for k, v in oldDB.items()} for name in [ - # '0_welcome', 'jpg107-167', '0_warning', '0_wisdom', + # '0_warning', '0_welcome', '0_wisdom', '0_koan_1', 'jpg107-167', + # '0_loss_of_divinity', 'jpg229', 'p56_an_end', 'p57_parable', 'p0-2', 'p3-7', 'p8-14', 'p15-22', 'p23-26', 'p27-32', 'p33-39', 'p40-53', 'p54-55' ]: fname = f'pages/{name}.txt' print('load:', fname) for irp in irp_chars: # interrupt rune index - data = load_indices(fname, irp, maxinterrupt=20) + data = load_indices(fname, irp, maxinterrupt=max_irp) db = InterruptDB(data, irp) irp_count = db.stop_count print('analyze interrupt:', irp, 'count:', irp_count) @@ -72,3 +76,6 @@ def populate_db(irp_chars=range(1), startkeylen=1, maxkeylen=32): print(f'{keylen}: {score:.4f}, solutions: {len(interrupts)}') for x in interrupts: InterruptDB.write(name, score, irp, irp_count, keylen, x) + + +# populate_db(startkeylen=0, maxkeylen=0, max_irp=None) diff --git a/data/interruptDB.txt b/data/interruptDB.txt index b38d7fb..3b2cf82 100644 --- a/data/interruptDB.txt +++ b/data/interruptDB.txt @@ -1,8 +1,13 @@ # file-name | number of interrupts | score | interrupt-rune (index) | key length | interrupts (starting with index 1 for first occurrence) -0_welcome|25|1.17420|0|1| -jpg107-167|5|1.13036|0|1| 0_warning|1|1.85685|0|1| +0_welcome|25|1.17420|0|1| 0_wisdom|5|1.52270|0|1| +0_koan_1|25|1.90479|0|1| +0_loss_of_divinity|8|1.77524|0|1| +jpg107-167|5|1.13036|0|1| +jpg229|2|1.66624|0|1| +p56_an_end|5|0.94230|0|1| +p57_parable|3|1.81859|0|1| p0-2|34|0.98839|0|1| p3-7|26|1.00438|0|1| p8-14|66|0.99935|0|1| diff --git a/probability.py b/probability.py index e289ad3..49cea6f 100755 --- a/probability.py +++ b/probability.py @@ -60,10 +60,15 @@ def break_cipher(fname, candidates, solver, key_fn): ######################################### for fname in [ - # '0_welcome', # V8 - # 'jpg107-167', # V13 - # '0_warning', # invert - # '0_wisdom', # plain + '0_warning', # invert + '0_welcome', # V8 + '0_wisdom', # plain + '0_koan_1', # invert + shift + '0_loss_of_divinity', # plain + 'jpg107-167', # V13 + 'jpg229', # plain + 'p56_an_end', # totient + 'p57_parable', # plain # 'p0-2', # ??? # 'p3-7', # ??? # 'p8-14', # ??? -> kl 11? or 12? @@ -72,7 +77,7 @@ for fname in [ # 'p27-32', # ??? # 'p33-39', # ??? # 'p40-53', # ??? - 'p54-55', # ??? + # 'p54-55', # ??? ]: # NGramShifter().guess(data, 'áš ') print()