#_*_coding:utf-8_*_
#@Time:     2019/3/31 10:10
#@Author:   xwg
#@FileName: xx11.py

from Crypto.PublicKey import DSA
from Crypto.Random import random
import socket
import time
from Crypto.Hash import MD5
from Crypto.Util import number
import gmpy2 as gm




c = socket.socket()
host = 'localhost'
port = 10087

#c.connect((host, port))

time.sleep(1)

p = 89884656743115795468144027484978714165232986440685807204562889992564167824646759723346809125312616021085697296172504286331475468975945075173117124827460562331871287151027448234306790984335670656070082848238519059914208605197295988808105680747955039631326901720086455490069513934384294923543968946456135257347

q = 1317281034892139494478309572356462108709017282239

g = 33534672874398919579510072421201721204694988253416673454353539576009989195698572145239782055882278117258245569769659687211490780161191184581631181848714545159657830191039973884834889526413862169558265727063726257007038469881527764693389063857892533037602510323113512734623637633924524456120935443559409588897

msg1 = "When I behold the violet past prime"

msg2 = "Born on the bier with white and bristly beard"

msg = "And nothing 'gainst Time's scythe can make defence"

# s1和s2和r需要手动输入

# When I behold the violet past prime
# (476285682163840111134589069951095433451762033212L, 750878836594769714218369688081048654723959920310L)

s1 = 695867118826234288019728061102190345510870577729L



# Born on the bier with white and bristly beard
# (476285682163840111134589069951095433451762033212L, 1024301092383298645166193780198072718145056142558L)

s2 = 1189095586470437230337352901845581329066775460494L

r = 72901494132238706242193413574196007501544879148L

m1 = number.bytes_to_long(MD5.new(msg1).digest())

m2 = number.bytes_to_long(MD5.new(msg2).digest())





x = (s2 * m1 - s1 * m2) * gm.invert(s1 * r - s2 * r, q) % q

y = gm.powmod(g,x,p)

key = DSA.generate(1024)

#k = random.getrandbits(50)
k = 517796658309687953755760389310

key.g = g
key.p = p
key.q = q
key.x = x
key.y = y

print key.g
print key.p
print key.q
print key.x
print key.y

print ''

en_msg = number.bytes_to_long(MD5.new(msg).digest())


sign = key.sign(en_msg, k)
print sign

