Mathematics of RSA Encryption Algorithm

Search for a command to run...

No comments yet. Be the first to comment.
Transferring files between your local machine and a virtual machine (VM) is one of the most common tasks in tech. We often use scp because it comes natively installed and has similar utilization to ssh, but it is the clunkiest tool for the job. In th...

Alias Alchemy is a Deno-powered server that fetches aliases from a GitHub repository based on your query. Think of it as your instant alias spellbook, perfect for setting up new environments in seconds. ⚡ Usage: $ alias-alchemy.ra101.dev/?q=py,shell,...

Reader discretion is advised!A good Sus-Saturday to all. In this article, I drag and drown you with my paranoia about AI. Let the mass psychosis begin! What are AI hallucinations?AI hallucinations are incorrect or misleading results that AI models ge...

I recently joined a company, that follows squash-rebase flow here, and as my Git KT was going on, I figured I should build these commands before actually starting development, now that I have started development, these turned out to be quite handy! ...

Aim: To create an iterable blockchain, which could work with an extendable transaction class. Here the link GitHub repo! Blockchain in Brief: Blockchain is fundamentally a ledger maintaining records of transaction, This ledger is publicly distribute...

The Rivest-Shamir-Adleman (RSA) is an asymmetric encryption algorithm. Asymmetric Encryption is when a box(data) can be locked by one key and unlocked by other. locking key cannot unlock the box and vice-versa. The locking key is the public key and the unlocking key is the private key, Public key is called so, because it is publicly distributed, so anyone/everyone would send the user an encrypted msg, and the user can unlock it in private with the private key. By keeping private to the user-self, no hacker can get a method of unlocking it.
We need a mathematical function such that
f: public key function ,g: private key function
f-1(f(msg)) != msg
g(g-1(msg)) != msg
g(f(msg)) == msg
Digital Signature is the by-product of Asymmetric Encryption, In most asymmetric encryption algorithms (including RSA), public and private are just names, one can simply interchange them for locking and unlocking. Here is how to sign a document:
How to sign:
digest by performing the decryption function with the private key on that hash.How to Verify:
for g and f should be such that g must relatively harder to perform so that it could not be cracked by brute force.
First, let's get this straight. Every string data can be represented as numbers or chunks of numbers, which can happen via ASCII or change it to binary then to decimal. So mathematical operation can be used on any and every data.
Consider m as the message. say m is 10, now we have to find 2 functions, one that will change it some else and the other that can change back!
Multiplication/Division:
let so now we have to distributef(key, m) = key * mfandkeybut same key can be used to change it back!Addition/Subtraction:
let so now we have to distributef(key, m) = key + mfandkeybut same key can be used to change it back!Trigonometry:
let Here the problem is the decimal nature of output, can have different result at different machines!f(..., m) = sin(... m)
Modulus: For those who are new to modulus function, it is the reminder of integer division.
for example: x mod y=>ky - xwhereky>x7/5 = 1and2 = 7 mod 5Here is the catch, for
So a hacker with 2 = m mod 5mcan be2, 7, 12... 5*(x) + 22(encrypted msg) and5cannot decode them, but so can't we.Let us try one more trick
So a hacker with 3mmod 5 = x
for ifmis0, 1, 2, 3, 4 ...x is1, 3, 4, 2, 1 ...respectively,mis uniformly distributed in 1 to 4.x(encrypted msg),5and3cannot decode them, but still so can't we. Another major point to be noted is, if3 < 5exists, thenx == 3for somemandx < 5exists always.Now Let us merge both tricks.
Let there be another equation memod n = x,m < n--> eq 1
m: message,e,n: some constants,x: encrypted messagexdmod n = m--> eq 2
x: encrypted message,d,n: some constants,m: message
Let us substitutexineq 2witheq 1
in other words: (mdmod n)emod n = m
me * dmod n = m
m: message,e,d,n: some constants,x: encrypted messagee->public_keyandd->private_keyAll we need is do is define those constants and we are good to go!Now Lets take a dive into history,
Introducing the
Totientfunction aka Euler's phi functionphi(n) = m,mis the count of integers b/w[1, n], which are coprime(relatively prime) ton
for example,phi(8) = 2as,gcd(6, n) == 1holds true only for1and5.
- Interestingly enough,
phi(prime)is alwaysprime - 1, as all the numbers before prime gave theirgcdas1, given the definition of prime is exactly that.- Another Observation is
phi(p1 * p2) = phi(p1) * phi(p2)Let's cook with the ingredients we have.
phi(n) = Set of all the co-primes3emod 5 = x,
for ifeis0, 1, 2, 3, 4 ...x is1, 3, 4, 2, 1 ...respectively,eis uniformly distributed in 1 to 4.- Let there be
ak, such thatak= 1 mod n- Since, is
kone of the uniformly distributed power, it must be withinphi(n), thereforephi(n) = kc, therecis some constant.- Now if raise both side with power for
c- It becomes:
akc= aphi(n)= 1 mod nThis isFermat–Euler TheoremMerge both the discoveries:
a * aphi(n)mod n = aedmod n
a * aphi(n) * c= aedmod n
(phi(n) * c) + 1 = e * d
ifnis product of big prime number then phi(n) easy to calculate andnitself hard to find (prime factorization would take a lot of time)d = (c * phi(n) + 1) / e
wherecis calculated such thatdbecomes an integer(n, e): public key,(n, d): private key
RSA Brief: https://www.youtube.com/watch?v=wXB-V_Keiu8
Khan Academy: https://www.khanacademy.org/computing/computer-science/cryptography/modern-crypt/v/intro-to-rsa-encryption
Proof of Fermat–Euler Theorem: https://www.youtube.com/watch?v=5pswKNgVZSg
RSA SIgning: https://www.cs.cornell.edu/courses/cs5430/2015sp/notes/rsa_sign_vs_dec.php