RSA Encryption From Scratch - Math & Python Code

  Рет қаралды 28,271

NeuralNine

NeuralNine

Күн бұрын

Today we learn about RSA. We take a look at the theory and math behind it and then we implement it from scratch in Python.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
Timestamps:
(0:00) Intro
(0:25) Mathematical Theory
(29:15) Python Implementation
(42:30) Outro

Пікірлер: 57
@_base_2
@_base_2 Жыл бұрын
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!!! 😃
@Peacfull
@Peacfull 9 ай бұрын
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)
@tanzir3678
@tanzir3678 Жыл бұрын
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.
@efox29
@efox29 Жыл бұрын
I havent watched the video yet, but title alone and topic. Thumbs up.
@Radical9535
@Radical9535 Жыл бұрын
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!
@huliang9001
@huliang9001 7 ай бұрын
I really like these more theory based videos explained from scratch. In this way, I really learned something deep.
@borisakelovic9930
@borisakelovic9930 3 ай бұрын
This "from the scratch" is sooo well done , Bravo
@sl3262
@sl3262 6 ай бұрын
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!
@paulthomas1052
@paulthomas1052 Жыл бұрын
Thanks - another really useful lecture and practical demo. Cheers 😃
@micleh
@micleh Жыл бұрын
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.
@aritraghosh999
@aritraghosh999 Ай бұрын
Please make more videos like this it helps us code by understanding the concepts
@Abomin81onVlog
@Abomin81onVlog Жыл бұрын
I enjoyed this video greatly.
@cawkcheck
@cawkcheck Жыл бұрын
amazing video. we need more of these
@lintop3908
@lintop3908 Жыл бұрын
Yeah, I really wanted you to release a video on this topic from scratch
@nicolamombelli2149
@nicolamombelli2149 Жыл бұрын
Great explanation and nice example in Python. Thanks.
@TritdawG
@TritdawG 8 ай бұрын
Great video; thank you for sharing.. super helpful!
@silentkille4
@silentkille4 6 ай бұрын
loving the content its helping me alot
@aryanlivi3553
@aryanlivi3553 5 ай бұрын
Great Explanation!!
@bartektrybaa3922
@bartektrybaa3922 Жыл бұрын
I found this usefull for my studies. Thanks :D
@harsharya828
@harsharya828 Жыл бұрын
Thanks for this knowledge.
@cpp705
@cpp705 Жыл бұрын
thanks i needed it
@lennuard_6998
@lennuard_6998 Жыл бұрын
coding challange: only watch the math part and (try to) implement it yourself before watching the coding part
@micleh
@micleh Жыл бұрын
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.
@certitolla202
@certitolla202 Жыл бұрын
Done 😸✅✅
@Ungerlogik
@Ungerlogik Жыл бұрын
I live the mix of these kind of videos and cool usefull stuff (like pomodoro). 😊
@salahtamimy5322
@salahtamimy5322 3 ай бұрын
Thank you 👍
@huliang9001
@huliang9001 7 ай бұрын
Really awesome! Thanks bro!😀
@khairysuleiman4
@khairysuleiman4 7 ай бұрын
Thanks Mr. Best!
@chyldstudios
@chyldstudios Жыл бұрын
awesome, thanks for making this video,.
@JO06
@JO06 10 ай бұрын
Thank you brother
@ghAmputeeAtheist
@ghAmputeeAtheist Жыл бұрын
you can get the inverse of e mod phi with pow(e,-1,phi)
@prosodyspeaks4036
@prosodyspeaks4036 8 ай бұрын
yeah! more like this!
@seeesh_
@seeesh_ Жыл бұрын
Hi, I would like to ask some Pandera tutorial to do data quality, doing some advance transformation on data. That's possible?
@tcgvsocg1458
@tcgvsocg1458 Жыл бұрын
really interesting these day i look in aes 256 bits encry^tion i don t know whitch is best but both are really interresting
@piotrmazgaj
@piotrmazgaj Жыл бұрын
Very nice.
@nejathakan5521
@nejathakan5521 Жыл бұрын
Keep this kind of videos please.
@PawitSahare
@PawitSahare Жыл бұрын
And awesome video bro
@RajapuRishitha-jc6xy
@RajapuRishitha-jc6xy 2 ай бұрын
If n is known, since n can be written as the product of p and q only(given p and q are prime numbers), we can find p and q right?
@DroughtBee
@DroughtBee 2 ай бұрын
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?
@bhagyalakshmi1053
@bhagyalakshmi1053 Жыл бұрын
How to create vlu ?
@danielw8620
@danielw8620 Жыл бұрын
May I ask what your educational background is? Are you self taught, did you go to college for a Math degree/CS degree? Thanks
@Peacfull
@Peacfull 9 ай бұрын
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.
@WahranRai
@WahranRai 9 ай бұрын
27:43 Which calculator did you use
@garydunken7934
@garydunken7934 4 ай бұрын
Microsoft Windows calculator
@WahranRai
@WahranRai 4 ай бұрын
@@garydunken7934 Thank you, i already found it !
@CthRage8946
@CthRage8946 12 күн бұрын
You can make someone very rich!
@JarppaGuru
@JarppaGuru 5 ай бұрын
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
@Andr_e_y
@Andr_e_y Ай бұрын
It's a shame there's no salt here. Thank you😊
@JarppaGuru
@JarppaGuru 5 ай бұрын
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
@raspberryPi1337
@raspberryPi1337 Жыл бұрын
Hello, how old are you?
@heptex8989
@heptex8989 Жыл бұрын
What kind of question is that lmfao
@zstar8397
@zstar8397 8 ай бұрын
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.
@PawitSahare
@PawitSahare Жыл бұрын
Don't reply this comment
@iamperoplayer2121
@iamperoplayer2121 6 ай бұрын
ok
@PawitSahare
@PawitSahare 6 ай бұрын
@@iamperoplayer2121 ok thanks
Breaking RSA - Computerphile
14:50
Computerphile
Рет қаралды 356 М.
Diffie-Hellman Key Exchange: How to Share a Secret
9:09
Spanning Tree
Рет қаралды 137 М.
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 11 МЛН
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 21 МЛН
🤔Какой Орган самый длинный ? #shorts
00:42
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 40 МЛН
"Only Carlsen Could Play Such A Move And Not Feel Like A Fool"
12:38
Public Key Cryptography: RSA Encryption Algorithm
16:31
Art of the Problem
Рет қаралды 930 М.
Encrypted File Transfer via Sockets in Python
19:54
NeuralNine
Рет қаралды 21 М.
Properly Load & Manage API Keys in Python
7:58
NeuralNine
Рет қаралды 22 М.
Prime Numbers & RSA Encryption Algorithm - Computerphile
15:06
Computerphile
Рет қаралды 173 М.
How does RSA Cryptography work?
19:40
Tom Rocks Maths
Рет қаралды 63 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 284 М.
Makefiles in Python For Professional Automation
13:43
NeuralNine
Рет қаралды 40 М.
The RSA Encryption Algorithm (2 of 2: Generating the Keys)
11:55
Xiaomi SU-7 Max 2024 - Самый быстрый мобильник
32:11
Клубный сервис
Рет қаралды 513 М.
Tag her 🤭💞 #miniphone #smartphone #iphone #samsung #fyp
0:11
Pockify™
Рет қаралды 73 МЛН
НОВЫЕ ФЕЙК iPHONE 🤯 #iphone
0:37
ALSER kz
Рет қаралды 278 М.