1313import time
1414import sys
1515import os
16+ import math
1617
1718RECV_SIZE = 1024
1819POW_LIMIT = 50_000_000
@@ -63,11 +64,14 @@ def usage(program_name: str):
6364 client .send (b'POST\r \n ' )
6465 check_response (client , b"OK\r \n " )
6566 print (f"{ host } :{ port } : server accepts POST" )
66- print (f"{ host } :{ port } : uploading lines..." )
6767
68- for line in content :
68+ bar_len = 30
69+ for (index , line ) in enumerate (content ):
70+ p = index / len (content )
71+ print ('\r uploading lines: ' + '#' * math .floor (p * bar_len ) + '.' * math .ceil ((1 - p )* bar_len ), end = '' )
6972 client .send ((line + '\r \n ' ).encode ())
7073 check_response (client , b"OK\r \n " )
74+ print ('\r uploading lines: ' + '#' * bar_len )
7175
7276 client .send (b'SUBMIT\r \n ' )
7377 response = check_response_prefix (client , b'CHALLENGE ' ).split ()
@@ -81,7 +85,12 @@ def usage(program_name: str):
8185 print (f"{ host } :{ port } : mining the solution with { leading_zeros } leading zeros in sha256 with { POW_LIMIT } iterations max" )
8286
8387 counter = 0
88+ spinner_period = 10000
89+ spinner = "-\\ |/"
8490 while counter < POW_LIMIT :
91+ if counter % spinner_period == 0 :
92+ print ('\r Solving Challenge: ' + spinner [counter // spinner_period % len (spinner )], end = '' )
93+
8594 prefix = b64encode (randbytes (randint (3 , 100 )))
8695 s = '\r \n ' .join ([prefix .decode ('utf-8' )] + content + [challenge .decode ('utf-8' ), "" ])
8796 h = hashlib .sha256 (str .encode (s )).hexdigest ()
@@ -90,6 +99,7 @@ def usage(program_name: str):
9099 while c < len (h ) and h [c ] == '0' :
91100 c += 1
92101 if c >= leading_zeros :
102+ print () # break spinner
93103 print (f"{ host } :{ port } : found prefix solution { prefix !r} and sha256 = { h !r} " )
94104 client .send (b'ACCEPTED ' + prefix + b'\r \n ' )
95105 post_id = check_response_prefix (client , b'SENT ' ).strip ().decode ('utf-8' )
@@ -99,4 +109,5 @@ def usage(program_name: str):
99109
100110 counter += 1
101111
112+ print () # break spinner
102113assert False , "Could not find the solution for the challenge..."
0 commit comments