Crytpo - HW7

1601 days ago by bronoskek

#7-7-1 pow(3, 1234, 53047) 
       
8576
8576
 
       
#7-7-2 for i in range(0, 30): if(pow(3, i, 31) == 24): print "x = ", i #Verify to make sure its the correct answer pow(3, 13, 31) 
       
x =  13
24
x =  13
24
 
       
#9-7-2 nA = 171024704183616109700818066925197841516671277 nB = 839073542734369359260871355939062622747633109 eA = 1571 eB = 87697 pB = 98763457697834568934613 qB = 8495789457893457345793 m1 = 418726553997094258577980055061305150940547956 s1 = 749142649641548101520133634736865752883277237 phi = (pB-1)*(qB-1) dB = pow(eB, -1, phi) print "dB = ", dB m = pow(m1, dB, nB) print "Message received is ", m s = pow(s1, dB, nB) print "Signature received is ", s calculated_message = pow(s, eA, nA) print "Calculated message is ", calculated_message m = pow(m, 1, nA) if(calculated_message == m): print "Accept signature" else: print "Reject Signature" 
       
dB =  259959042568078902255663939554592635205071473
Message received is  19012507151504022505
Signature received is  150270996499036309478023705411245214416829627
Calculated message is  225098255962187053420063575751060505543625698
Reject Signature
dB =  259959042568078902255663939554592635205071473
Message received is  19012507151504022505
Signature received is  150270996499036309478023705411245214416829627
Calculated message is  225098255962187053420063575751060505543625698
Reject Signature
 
       
#9-7-3 pB2 = 7865712896579 qB2 = 8495789457893457345793 nB2 = pB2*qB2 print "The new nB = ", nB2 phi2 = (pB2-1)*(qB2-1) print "The new phi = ", phi2 dB2 = pow(eB, -1, phi2) print "The new dB = ", dB2 m2 = 14823765232498712344512418717130930 s2 = 43176121628465441340112418672065063 new_m = pow(m2, dB2, nB2) print "New message received is ", new_m new_s = pow(s2, dB2, nB2) print "New signature received is ", new_s new_calculated_message = pow(new_s, eA, nA) print "Calculated message is ", new_calculated_message if(new_calculated_message == new_m): print "Accept signature" else: print "Reject Signature" if(s > nB2): print "Signature is Bigger than nB" 
       
The new nB =  66825440705572478534950243249742147
The new phi =  66825440705563982745484484079499776
The new dB =  35505563584566789924693541805127793
New message received is  19012507151504022505
New signature received is  25749166731900300488114230630974268
Calculated message is  12771656666583769635582509511303555
Reject Signature
Signature is Bigger than nB
The new nB =  66825440705572478534950243249742147
The new phi =  66825440705563982745484484079499776
The new dB =  35505563584566789924693541805127793
New message received is  19012507151504022505
New signature received is  25749166731900300488114230630974268
Calculated message is  12771656666583769635582509511303555
Reject Signature
Signature is Bigger than nB
pow(s, eB, nB2) #This is supposed to be s2 but its not!!! 
       
749142649641548101520133634736865752883277237
749142649641548101520133634736865752883277237
pow(m, eB, nB2) #This should be m2 but its not either!! 
       
418726553997094258577980055061305150940547956
418726553997094258577980055061305150940547956