fromCrypto.Util.numberimport*fromCrypto.PublicKeyimportRSAfromhashlibimportsha256importrandom,os,signal,stringdefproof_of_work():random.seed(os.urandom(8))proof=''.join([random.choice(string.ascii_letters+string.digits)for_inrange(20)])_hexdigest=sha256(proof.encode()).hexdigest()print(f"sha256(XXXX+{proof[4:]}) == {_hexdigest}")print('Give me XXXX: ')x=input()iflen(x)!=4orsha256(x.encode()+proof[4:].encode()).hexdigest()!=_hexdigest:print('Wrong PoW')returnFalsereturnTrueifnotproof_of_work():exit(1)signal.alarm(10)print("Give me a bad RSA keypair.")try:p=int(input('p = '))q=int(input('q = '))assertp>0assertq>0assertp!=qassertp.bit_length()==512assertq.bit_length()==512assertisPrime(p)assertisPrime(q)n=p*qe=65537assertp%e!=1assertq%e!=1d=inverse(e,(p-1)*(q-1))except:print("Invalid params")exit(2)try:key=RSA.construct([n,e,d,p,q])print("This is not a bad RSA keypair.")exit(3)exceptKeyboardInterrupt:print("Hacker detected.")exit(4)exceptValueError:print("How could this happen?")fromsecretimportflagprint(flag)