Please keep this type of in-depth video coming! I learned a tremendous amount from your clear explanations, and am able to implement my own programs based on your clear, and logical, step-by-step walk through. Please, more like this!!! 😃
here is the code if you are lazy to write: import random import math # n= p.q #phi(n) = phi(p.q)=phi(p).phi(q) = (p-1). (q-1) #phi(n) = (p-1.q-1) def is_prime (number): if number < 2: return False for i in range (2, number // 2 +1): if number % i == 0: return False return True def generate_prime (min_value, max_value): prime = random.randint (min_value, max_value) while not is_prime(prime): prime = random.randint(min_value, max_value) return prime def mod_inverse(e, phi): for d in range (3, phi): if (d * e) % phi == 1: return d raise ValueError ("Mod_inverse does not exist!") p, q = generate_prime(1000, 50000), generate_prime ( 1000, 50000) while p==q: q= generate_prime(1000, 50000) n = p * q phi_n = (p-1) * (q-1) e = random.randint (3, phi_n-1) while math.gcd(e, phi_n) != 1: #gcd=greater common denometer != not equal e = random.randint (3, phi_n - 1) d = mod_inverse(e, phi_n) message = input("Enter your message to Encrypt ") print ("Prime number P: ", p) print ("Prime number q: ", q) print ("Public Key: ", e) print ("Private Key: ", d) print ("n: ", n) print ("Phi of n: ", phi_n, " Secret") message_encoded = [ord(ch) for ch in message] print ("Message in ASCII code: ", message_encoded) # (m ^ e) mod n = c ciphertext = [pow(ch, e, n) for ch in message_encoded] print (message," Ciphered in: ", ciphertext) Decodemsg= [pow(ch, d, n) for ch in ciphertext] print ("back to ASCII: ", Decodemsg) msg = "".join (chr(ch) for ch in Decodemsg) print("from ASCII to TEXT: ", msg)
A year late to the party, but thanks for the great explanation and the fantastic demo in Python. I'm familiar with the concepts of RSA already, but it's always good to have it explained clearly for folk who haven't looked at the concepts and logic behind it and your explanation was great.
Good one. Yes, thorough explanation covering Maths and all is much beneficial than just demonstration of using some libraries. There are tons of people out there who would follow the second approach. And that makes you standout.
I really like these more in depth videos. For me, learning the fundamental principles of how something works is by far the best way to understand it. Definitely do what has been suggested elsewhere: watch the theory then try and implement it in Python before seeing how it's done! More of these please, if you can!
Exactly. I often do this in my lessons (flipped classroom principle): watching a video at home, ironing out diffuculties in class and them implementing it in the lessons so as to figure out if the theory has been understood.
thanks i really like this being on the cyber security side of things i have to teach myself coding basically so these videos are great on stuff like this and now i have an understanding of how rsa works mathematically so thanks!
I like such videos a lot. I'll definitely use this video in my upper sixth computer science course here in Germany since RSA is a topics on the curriculum. The implementaion will be in JAVA, though, since this is the language used in Years 11-13.
Doesn’t this leave itself open to frequency analysis because all the letters are just given (effectively for our purposes) random numbers? Why is this better than just any other mono-alphabetical code?
nice work but where you selected 7, and that part i did not get it completely how did you come up with 7. I have wachted that part again and it was not clear for me. but still your explanation was very good. thank you. keep up the good work.
29:01 so how hard brute force private key if we know s n and m. bob can do s=m^d mod n too mean try every thing 141=15^d mod 143 why we sign using d and n when we should sign using phi_n alices=m^d mod phi_n-1 bobs=alices^m mod e = 1 if message and sign match at least all test i calculated LOL now bob cant brute force alice d... or i have formula for that do its same simple LOL but u made tutorial i say dont do s=m^d mod n you give away private key. he knows all but one. you need have atleast 2 unkown number in equation to make it harder
26:26 bob know e n and he make c. and m=c^d mod n r we clear yet? how hard is find out d? bob know all but d. we can brute force private key so long as we get our original m=15 alice public key need hold something its e and n alice privet key have to have some number and p q. n and phi we can calculate and e is just mod inverse d so how hard brute force m=c^d mod n. if we know all but not d xD
Hey hope you are doing alright just I wanna say that GOD loved the world so much he sent his only begotten son Jesus to die a brutal death for us so that we can have eternal life and we can all accept this amazing gift this by simply trusting in Jesus, confessing that GOD raised him from the dead, turning away from your sins and forming a relationship with GOD.