According to Euclid's lemma , given two integers a & b , such that a >= b >= 0, then we can say that
According to euclid's lemma , for given 2 positive integers x and y , gcd(x,y) = gcd(y,x%y), where % is the mod operation.
proof of correctness:
The given hypothesis can easily be proven by the use of induction hypothesis.
a = (q_0)*(b) + r_0
b = (q_1)*(r_0) + r1
r_0 =( q_2)*(r_1) + r_2
...
...
...
r_k-1 = (q_k+1)*(r_k) + 0
Since remainder can be negative it'll surely reach 0 at some moment ( at r_k = 1 for sure ) , so the chain will have an end thus, if we go above the equations from the below , we could see that G.C.D of the numbers will be r_k , as if we go backward substituting the
remainders , we observe that r_k divides both a & b and is therefore a factor of them both.
why is it the greatest : we could see this from the fact that ,
r_k-2 = (q_k)*(r_k-1) + r_k ,if we say that ther's gcd of r_k-1 and r_k-2 c , this clearly implies the fact that c <= r_k or else r_k-2 wont be divisible by c. and also we've gcd(r_k-1,r_k) = r_k , and since c is the gcd of one step above c <= r_k maximum value c can have is r_k therefore it is the gcd of a & b.
if we assume a >= b >= 0 ( for no loss of generality , in other cases a & b could be simply swapped to get their gcd )
gcd_function(a,b){
if(b==0)
return a;
return gcd_function(b,a%b);
}
Theorem : if d divides both integers a & b such that d = ax + by , where x & y are integers then , d is gcd of a, b
d <= gcd(a,b) , by definition of gcd . Also d = ax + by , and as gcd(a,b) divides both a & b
then d >= gcd(a,b) , therefore this implies d = gcd(a,b).Pseduo-code :
gcd of a & b .extended_euclid(int a , int b){
if( b== 0)
return (1,0,a);
(x',y',d') = extended_euclid(b,a%b);
return (y',x' - (a/b)*(y'), d')
}

The main steps of the RSA encryption could be stated as :
Generating the Keys : we choose 2 large prime numbers p1 and p2 , so that factorising their product will be a herculean task.
toitent function defined as ϕ(n)=(p1−1)(p2−1)gcd(e,**ϕ(n)) = 1 to the toitent product , calculated in the previous step. The pair (n,e) makes up the public key.eucledian algorithm , the generated key d , becomes the decryption key.Encryption
For any given plain text p , to generate the cipher text c , we do the following operation
c = pow(p , e) mod n.
Decryption
For any given cipher text c , to generate the plain text p , we do the following operation
p = pow(c , d) mod n.