CoCalc Public FilesWienner Covert Channel.sagewsOpen with one click!
Authors: Liljana Babinkostova, Charles Burnell, William Unger
Views : 73
Compute Environment: Ubuntu 20.04 (Default)
def Wiener (n, s): M = 10101 E = M.powermod(s,n)#&^(M, s) % n cf = continued_fraction(n/s)# convert(n / s, confrac) m = len(cf) for i in range(0, m ): conv = cf.convergent(i) t = conv.numerator() #t = cf.quotient(i)#numtheory:-nthnumer(cf, i) d = E.powermod(t,n)#&^(E, t) % n #print d if d == M: print("k:= {0}".format(cf.convergent(i).denominator())) print("The totient of the modulus is {0}".format((s*t-1)/(cf.convergent(i).denominator()))) print("The private key is {0}".format(t)) return [t, (s*t-1)/(cf.convergent(i).denominator())] print("Private key not found") def WienerCovert (P): p = next_prime(ZZ.random_element(P^2)) q = next_prime(ZZ.random_element(P^2)) while(not((q<p) and (p<2*q))): p = next_prime(ZZ.random_element(P^2)) q = next_prime(ZZ.random_element(P^2)) n = p*q phin = (p-1)*(q-1) l = ZZ(floor((n^(1/4))/3)) for i in range(1000): d1 = l-i g = gcd(d1,phin) if (g == 1): s1 = 1/d1 % phin s2 = s1*P % n g1 = gcd(s2,phin) if(g1 == 1): d2 = 1/s2 % phin print "The modulus is: ", n print "The exponent is: ", s2 print "The key is: ", d2 return([n,s2,d2])
P = next_prime(983724836482) R = WienerCovert(P) print "end of creatiom of covert channel" S = R[1]/P % R[0] wienerAttackOutput = Wiener(R[0],S) print "after wieners attack" d = 1/R[1] % wienerAttackOutput[1] d if (R[2] == d): print "correct private key computed"
The modulus is: 162996458187706035673135889099890482856112226697 The exponent is: 94344369869984932236004780866259533022210541589 The key is: 56419832253583618233458429492162599992204825621 end of creatiom of covert channel k:= 22430205604 The totient of the modulus is 162996458187706035673135081204137668474884176916 The private key is 211798698559 after wieners attack 56419832253583618233458429492162599992204825621 correct private key computed