Esempio n. 1
0
def report_finding(key,c,ks):
    k1, k2 = ks
    prtty = pretty(code=c, k1=k1, k2=k2)
    longest_found = k1 + k2
    full_code = bhash(key)
    response = [{"length": longest_found, "pretty": prtty, "key": key, "hash": full_code}]
    return response
Esempio n. 2
0
def mine_once(difficulty,count,quota):
    # Only one batch of 100,000 attempts
    keys         = [ binascii.b2a_hex(os.urandom(16)) for _ in range(100000) ]
    hashed_keys  = [bhash(key) for key in keys]
    short_codes  = [ hk[:difficulty]   for hk in hashed_keys ]
    longer_codes = [ hk[:difficulty+1] for hk in hashed_keys]
    candidates   = dict( zip(short_codes,keys) )
    long_candidates = dict( zip( longer_codes, keys) )

    if any( code in BCORPUS for code in short_codes ):
        for c,key in candidates.items():
            ks = BCORPUS.get(c)
            if ks is not None:
                report = report_finding(key=key,c=c,ks=ks)
                count = count+1
                if count==quota:
                    difficulty = difficulty+1
                    count = 0
    elif any( longer_code in BCORPUS for longer_code in longer_codes ):
        for c,key in long_candidates.items():
            ks = BCORPUS.get(c)
            if ks is not None:
                report = report_finding(key=key,c=c,ks=ks)
                difficulty = difficulty+1
                count = 1
    else:
        report = []
    return report, difficulty, count
Esempio n. 3
0
def animal(key):
    bkey = key if isinstance(key, bytes) else key.encode('ascii')
    code = bhash(bkey)
    return search(code)