Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions docker-images/challenge/pow.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@
def python_sloth_root(x, diff, p):
exponent = (p + 1) // 4
for i in range(diff):
if i % 100 == 0 or i == diff - 1:
progress = (i + 1) / diff
bar_len = 40
filled_len = int(round(bar_len * progress))
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stderr.write(f'\rSolving: [{bar}] {progress:.1%}')
sys.stderr.flush()
x = pow(x, exponent, p) ^ 1
sys.stderr.write('\n')
return x

def python_sloth_square(y, diff, p):
Expand All @@ -48,7 +56,15 @@ def python_sloth_square(y, diff, p):
def gmpy_sloth_root(x, diff, p):
exponent = (p + 1) // 4
for i in range(diff):
if i % 100 == 0 or i == diff - 1:
progress = (i + 1) / diff
bar_len = 40
filled_len = int(round(bar_len * progress))
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stderr.write(f'\rSolving: [{bar}] {progress:.1%}')
sys.stderr.flush()
x = gmpy2.powmod(x, exponent, p).bit_flip(0)
sys.stderr.write('\n')
return int(x)

def gmpy_sloth_square(y, diff, p):
Expand Down