class oracle: def __init__(self): self.rsa = RSA() self.pub, self.private = self.rsa.keygen(l=512) def getPubKey(self): return self.pub def isEven(self, num): return ord(self.rsa.decrypt(num, self.private)[-1]) & 1 == 0
getcontext().prec = keylen * 8 #这里是设置精度 forge = "\x00\x01%s\x00%s" % ("\xff" * 8, dgst) # 填充过程 garbage = "\x00" * (keylen - 8 - len(dgst) - 13) whole = s2i(forge+garbage) cr = int(pow(whole,Decimal(1)/Decimal(3)))+1 #把我们得到的whole开3次方,得到的应该是我们伪造的加密sign return i2s(cr) #转换为字符串 if __name__ == "__main__": message = "hi mom" print 'msg is :'+message+'\n' re = RSA() pub1,priv1 = re.keygen(l=512,s=False) #通过c39里的函数获得密钥 rs = RSAsign() sign = rs.make(message,priv1) #调用函数算出sign的rsa加密之后的结果 print 'rsa sign is :'+''.join(sign)+'\n' if rs.verify(message,sign,pub1): #这个地方是验证如果成功就输出ok print "sign is correct \n" else: print 'sign is incorrect \n' signf = [ forging(message,pub1) ] #这个利用公钥和消息我们可以伪造出一个signf print 'signf is :'+''.join(signf)+'\n' if rs.verify(message,signf,pub1): #这个地方是验证 print "sign is correct \n" else: print 'sign is incorrect \n'
forge = "\x00\x01%s\x00%s" % ("\xff" * 8, dgst) # 填充过程 garbage = "\x00" * (keylen - 8 - len(dgst) - 13) whole = s2i(forge + garbage) cr = int(pow( whole, Decimal(1) / Decimal(3))) + 1 #把我们得到的whole开3次方,得到的应该是我们伪造的加密sign return i2s(cr) #转换为字符串 if __name__ == "__main__": message = "hi mom" print 'msg is :' + message + '\n' re = RSA() pub1, priv1 = re.keygen(l=512, s=False) #通过c39里的函数获得密钥 rs = RSAsign() sign = rs.make(message, priv1) #调用函数算出sign的rsa加密之后的结果 print 'rsa sign is :' + ''.join(sign) + '\n' if rs.verify(message, sign, pub1): #这个地方是验证如果成功就输出ok print "sign is correct \n" else: print 'sign is incorrect \n' signf = [forging(message, pub1)] #这个利用公钥和消息我们可以伪造出一个signf print 'signf is :' + ''.join(signf) + '\n' if rs.verify(message, signf, pub1): #这个地方是验证 print "sign is correct \n" else: print 'sign is incorrect \n'