def collisions(): ss_count,ltr,last_sid,collisions_chk = ( (SubSeedIdxRange.max_idx,'S','2788F26B',470), (49509,'L','8D1FE500',2) )[bool(opt.fast)] last_idx = str(ss_count) + ltr msg_r('Testing Seed ID collisions ({} subseed pairs)...'.format(ss_count)) seed_bin = bytes.fromhex('12abcdef' * 8) seed = Seed(seed_bin) seed.subseeds._generate(ss_count) ss = seed.subseeds assert seed.subseed(last_idx).sid == last_sid, seed.subseed(last_idx).sid for sid in ss.data['long']: # msg(sid) assert sid not in ss.data['short'] collisions = 0 for k in ('short','long'): for sid in ss.data[k]: collisions += ss.data[k][sid][1] assert collisions == collisions_chk, collisions vmsg_r('\n{} collisions, last_sid {}'.format(collisions,last_sid)) msg('OK')
def collisions(): ss_count,ltr,last_sid,collisions_chk = ( (SubSeedIdxRange.max_idx,'S','2788F26B',470), (49509,'L','8D1FE500',2) )[bool(opt.fast)] last_idx = str(ss_count) + ltr msg_r('Testing Seed ID collisions ({} subseed pairs)...'.format(ss_count)) seed_bin = bytes.fromhex('12abcdef' * 8) seed = Seed(seed_bin) seed.gen_subseeds(ss_count) ss = seed.subseeds assert seed.subseed(last_idx).sid == last_sid, seed.subseed(last_idx).sid for sid in ss['long']: # msg(sid) assert sid not in ss['short'] collisions = 0 for k in ('short','long'): for sid in ss[k]: collisions += ss[k][sid][1] assert collisions == collisions_chk, collisions msg_r('({} collisions) '.format(collisions)) msg('OK')
def basic_ops(): msg_r('Testing basic ops...') for a,b,c,d,e,f,h in ( (8,'4710FBF0','0C1B0615','803B165C','2669AC64',256,'10L'), (6,'9D07ABBD','EBA9C33F','20787E6A','192E2AA2',192,'10L'), (4,'43670520','04A4CCB3','B5F21D7B','C1934CFF',128,'10L'), ): seed_bin = bytes.fromhex('deadbeef' * a) seed = Seed(seed_bin) assert seed.sid == b, seed.sid subseed = seed.subseed('2s') assert subseed.sid == c, subseed.sid subseed = seed.subseed('3') assert subseed.sid == d, subseed.sid subseed = seed.subseed_by_seed_id(e) assert subseed.bitlen == f, subseed.bitlen assert subseed.sid == e, subseed.sid assert subseed.idx == 10, subseed.idx assert subseed.ss_idx == h, subseed.ss_idx seed2 = Seed(seed_bin) ss2_list = seed2.subseeds seed2.subseeds._generate(1) assert len(ss2_list) == 1, len(ss2_list) seed2.subseeds._generate(1) # do nothing seed2.subseeds._generate(2) # append one item seed2.subseeds._generate(5) assert len(ss2_list) == 5, len(ss2_list) seed2.subseeds._generate(3) # do nothing assert len(ss2_list) == 5, len(ss2_list) seed2.subseeds._generate(10) assert len(ss2_list) == 10, len(ss2_list) assert seed.ppformat() == seed2.ppformat() s = seed.subseeds.format(1,g.subseeds) s_lines = s.strip().split('\n') assert len(s_lines) == g.subseeds + 4, s a = seed.subseed('2L').sid b = [e for e in s_lines if ' 2L:' in e][0].strip().split()[1] assert a == b, b c = seed.subseed('2').sid assert c == a, c a = seed.subseed('5S').sid b = [e for e in s_lines if ' 5S:' in e][0].strip().split()[3] assert a == b, b s = seed.subseeds.format(g.subseeds+1,g.subseeds+2) s_lines = s.strip().split('\n') assert len(s_lines) == 6, s ss_idx = str(g.subseeds+2) + 'S' a = seed.subseed(ss_idx).sid b = [e for e in s_lines if ' {}:'.format(ss_idx) in e][0].strip().split()[3] assert a == b, b s = seed.subseeds.format(1,10) s_lines = s.strip().split('\n') assert len(s_lines) == 14, s vmsg_r('\n{}'.format(s)) msg('OK')
def basic_ops(): msg_r('Testing basic ops...') for a,b,c,d,e,f,h in ( (8,'4710FBF0','0C1B0615','803B165C','2669AC64',256,'10L'), (6,'9D07ABBD','EBA9C33F','20787E6A','192E2AA2',192,'10L'), (4,'43670520','04A4CCB3','B5F21D7B','C1934CFF',128,'10L'), ): seed_bin = bytes.fromhex('deadbeef' * a) seed = Seed(seed_bin) assert seed.sid == b, seed.sid subseed = seed.subseed('2s') assert subseed.sid == c, subseed.sid subseed = seed.subseed('3') assert subseed.sid == d, subseed.sid subseed = seed.subseed_by_seed_id(e) assert subseed.length == f, subseed.length assert subseed.sid == e, subseed.sid assert subseed.idx == 10, subseed.idx assert subseed.ss_idx == h, subseed.ss_idx seed2 = Seed(seed_bin) s2s = seed2.subseeds['short'] s2l = seed2.subseeds['long'] seed2.gen_subseeds(1) assert len(s2s) == 1, len(s2s) seed2.gen_subseeds(1) # do nothing seed2.gen_subseeds(2) # append one item seed2.gen_subseeds(5) assert len(s2s) == 5, len(s2s) seed2.gen_subseeds(3) # do nothing assert len(s2l) == 5, len(s2l) seed2.gen_subseeds(10) assert len(s2s) == 10, len(s2s) assert seed.pformat() == seed2.pformat() s = seed.fmt_subseeds(1,g.subseeds) s_lines = s.strip().split('\n') assert len(s_lines) == g.subseeds + 4, s a = seed.subseed('2L').sid b = [e for e in s_lines if ' 2L:' in e][0].strip().split()[1] assert a == b, b c = seed.subseed('2').sid assert c == a, c a = seed.subseed('5S').sid b = [e for e in s_lines if ' 5S:' in e][0].strip().split()[3] assert a == b, b s = seed.fmt_subseeds(g.subseeds+1,g.subseeds+2) s_lines = s.strip().split('\n') assert len(s_lines) == 6, s ss_idx = str(g.subseeds+2) + 'S' a = seed.subseed(ss_idx).sid b = [e for e in s_lines if ' {}:'.format(ss_idx) in e][0].strip().split()[3] assert a == b, b s = seed.fmt_subseeds(1,2) s_lines = s.strip().split('\n') assert len(s_lines) == 6, s msg('OK')