Python 3.2.5 (default, May 15 2013, 23:07:10) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ #select a random prime number with exactly 10 bits >>> >>> p = find_prime(10) >>> p 809 >>> bin(p) '0b1100101001' >>> len(bin(p))-2 10 #Run Diffie-Hellman algorithm using the random p >>> g, a, b, x, y, key = DH_exchange(p) >>> g, a, b, x, y, key (481, 82, 689, 382, 69, 601) >>> pow(g, a, p) 382 >>> pow(g, a*b, p) 601 #Trying to find the value of "a" given: p, g, x # ...easy.... >>> crack_DH(p, g, x) 82 #select a random prime number with exactly 100 bits >>> p = find_prime(100) >>> p 911648372201638424796697967173 #Run DH algorithm >>> g, a, b, x, y, key = DH_exchange(p) >>> g, a, b, x, y, key (591725772861172054266486721388, 534714351109252397619887876727, 408791693816153646466621500819, 152646532869779907334523458742, 599625654496380889366596530697, 233697053670484276876223983138) #Trying to find the value of "a" given: p, g, x # .... no longer easy..... >>> crack_DH(p, g, x) 100000 200000 300000 400000 500000 Traceback (most recent call last): File "", line 1, in crack_DH(p, g, x) File "C:\Personal\Teaching\CS-intro\2015b\Recitations\7\m_07_primes.py", line 56, in crack_DH if a%100000==0: KeyboardInterrupt #How much time will it take us to find the value of "a"? #In seconds >>> a//100000 5347143511092523976198878 #In years >>> a//100000//60//60//24/365 1.6955680844408054e+17 >>> #TOO long! # OOP >>> >>> p = Point(3,4) >>> p <__main__.Point object at 0x00000000034A9D68> # adding __repr__ method: >>> ================================ RESTART ================================ >>> >>> p = Point(3,4) >>> p Point(3,4) #using the default parameters for x,y >>> ================================ RESTART ================================ >>> >>> p = Point(3,4) >>> q = Point() #Two (identical) ways for calling a method of a class: >>> p.is_origin() False >>> Point.is_origin(p) False >>> q.is_origin() True >>>