From: david-sarah Date: Fri, 7 Oct 2011 02:30:01 +0000 (-0700) Subject: misc/simulators/hashbasedsig.py: simplify by removing unnecessary local function... X-Git-Url: https://git.rkrishnan.org/simplejson/components/htmlfontify-example.html?a=commitdiff_plain;h=bbb6e5d25e62eaed396fb4ecbd780d13e769466b;p=tahoe-lafs%2Ftahoe-lafs.git misc/simulators/hashbasedsig.py: simplify by removing unnecessary local function that captured a variable declared in a for loop (this was not a bug, but the code was unclear). Also fix a pyflakes warning about an import. refs #1556 --- diff --git a/misc/simulators/hashbasedsig.py b/misc/simulators/hashbasedsig.py index 901c38f7..640331ae 100644 --- a/misc/simulators/hashbasedsig.py +++ b/misc/simulators/hashbasedsig.py @@ -19,7 +19,7 @@ cycles_per_byte = 15.8 # cost of hash Mcycles_per_block = cycles_per_byte * L_block / (8 * 1000000.0) -from math import floor, ceil, log, log1p, pow, e, sqrt +from math import floor, ceil, log, log1p, pow, e from sys import stderr from gc import collect @@ -138,17 +138,17 @@ def calculate(K, K1, K2, q_max, L_hash, trees): for x in xrange(1, j): lg_px[x] = lg_px[x-1] - lg(x) + lg_px_step - def find_min_q(): - for q in xrange(1, q_max+1): - lg_q = lg(q) - lg_pforge = [lg_px[x] + (lg_q*x - lg_K2)*q for x in xrange(1, j)] - if max(lg_pforge) < -L_hash + lg(j) and lg_px[j-1] + 1.0 < -L_hash: - #print "K = %d, K1 = %d, K2 = %d, L_hash = %d, lg_K2 = %.3f, q = %d, lg_pforge_1 = %.3f, lg_pforge_2 = %.3f, lg_pforge_3 = %.3f" \ - # % (K, K1, K2, L_hash, lg_K2, q, lg_pforge_1, lg_pforge_2, lg_pforge_3) - return q - return None - - q = find_min_q() + q = None + # Find the minimum acceptable value of q. + for q_cand in xrange(1, q_max+1): + lg_q = lg(q_cand) + lg_pforge = [lg_px[x] + (lg_q*x - lg_K2)*q_cand for x in xrange(1, j)] + if max(lg_pforge) < -L_hash + lg(j) and lg_px[j-1] + 1.0 < -L_hash: + #print "K = %d, K1 = %d, K2 = %d, L_hash = %d, lg_K2 = %.3f, q = %d, lg_pforge_1 = %.3f, lg_pforge_2 = %.3f, lg_pforge_3 = %.3f" \ + # % (K, K1, K2, L_hash, lg_K2, q, lg_pforge_1, lg_pforge_2, lg_pforge_3) + q = q_cand + break + if q is None or q == last_q: # if q hasn't decreased, this will be strictly worse than the previous candidate continue