from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from base64 import b64encode
import gmpy2





message = b"Codito ergo sum. I code therefore I am."
m = int(message.hex(),16)
p = 37538771092038550170119625558616493135644092937540451858370750326435458452960334875445208333994137791394075003986015780546677682326985517998410672951259
g = 32769391017688930466178758104680913254958907932279225382460689492666988096822183410017376483995819591563910367020738247587237232528287203996063880810190
pk = 2112157042810269608670956960710495470793949418830844289847276305374152484072094547290308856587807722555112502191046618112590565762143
gm = pow(g,m,p)

r1 = 34509848765724502418312895874292203630804311399769087340610633583414558506068513247412905019416264610084508765604133240793437383683684098377700417893853
s1 = 13491041442324628103071798827364675079120145773008025976989115013066852042788276482575168016874950870471026633133348132068982634862019614958895855224982
r2 = 20899255405184389764486326336455450821508223308674564833168819155612259005703497048513057512780957618411693538356107021081007144523946198564236748102873
s2 = 18144296338268544682133790094273396141223924234777397156203389790960828610707518655767083425679291432950975225402231881105349559369916819650914810953707
r3 = 37081487164928529942583229280097815531048235609431127744770783642884041994861230182706541300047934993100723645701429990946554045611965849420315217084843
s3 = 17892403018838849545398802660548983111471231321286540003866582515975985918181484125034196777786380983195144863700464423455199278786548338502582874197816
r4 = 21596022636199385119397184051905662430580987824115497149520531786663769363164474761378449374130531275695824499900986088143079715172291440586045137611476
s4 = 3609582031138881320946465178394435752911592988648966159499195364726369067497355245252101216582765723751479350647770993570067703581


def checking (r,s):
    check = pow(pow(pk,r,p)*pow(r,s,p),1,p)
    if check == gm:
        print("yes")
    else:
        print(check)
        print(gm)
        print("no")


for i in range (1,5):
    if i == 1:
        checking(r1,s1)
    if i == 2:
        checking(r2,s2)
    if i == 3:
        checking(r3,s3)
    if i == 4:
        checking(r4,s4)
















""" 
p = 39115786165058146707346692230666459588893674529522577556813668006150856903157
g = 16617894212308406314833773803889051882694274443847375319072009507363829310973
A = 25968195348269542112808138166137117126195318946697617769246151664102486311177
B = 20342743754305668265654427111543933936772007084988102775837310543061197148284
m = 12820193088289487877301364604383729923707263012276518254497683446776730489157
gm = pow(g,m,p)

alice = pow(A,m,p)
bob = pow(B,m,p)

print(alice)
print(bob)
 """

""" 
blocksize = bytes(16)
blocksize = 32

m1 = b"I asked my French friend if she likes to play video games. She said Wii."
m2 = b"What did one wall say to the other? I'll meet you at the corner."
t1 = "a6fcb29a309ac850f878cd098c7f53eb"

m2b1 = m2.hex()[:32]
restofm2 = m2.hex()[32:]
newm2b1 = int(t1,16) ^ int(m2b1,16)
newm2 = hex(newm2b1)[2:] + restofm2



newm1 = "492061736b6564206d79204672656e636820667269656e6420696620736865206c696b657320746f20706c617920766964656f2067616d65732e205368652073616964205769692e0808080808080808"

print(newm1 + newm2)
 """



""" 
m1 = b"Alice pays Bob 100"
m2 = b"Alice pays Eve 100"
ct1 = "8f05b90adecf460859827d9316d75d9dddf1"

key = int(ct1,16) ^ int(m1.hex(),16)
ct2 = key ^ int(m2.hex(), 16)
print(hex(ct2))
 """

""" 
# the birthday attack formula is prob = 1-(totalComb-1/totalComb)^(n*(n-1)/2)

from itertools import combinations
import math
import cmath

prob = 0.5
k = 32
totalCombinations = pow(2,k)
oneMinusProb = 1 - prob
logOneMinusProb = math.log(oneMinusProb)
remainingCombinations = totalCombinations-1
probRemainingCombinations = remainingCombinations / totalCombinations
logProbRemainingCombinations = math.log(probRemainingCombinations)

def quadratic(a, b, c):
    # calculate the discriminant
    d = (b**2) - (4*a*c)

    # find two solutions
    sol1 = (-b-cmath.sqrt(d))/(2*a)
    sol2 = (-b+cmath.sqrt(d))/(2*a)
    print('The solution are {0} and {1}'.format(sol1,sol2))
quadratic(1, -1, -2*(logOneMinusProb/logProbRemainingCombinations)) """