1 NET 311D INFORMATION SECURITY Networks and Communication Department TUTORIAL 3 : Asymmetric Ciphers (RSA)
A Symmetric-Key Cryptography (Public-Key Cryptography) Asymmetric-key (public key cryptography) uses two keys: one private and one public. There are two algorithms: RSA ELGAMAL
RSA The most common public key algorithm is RSA, named for its inventors Rivest, Shamir, and Adelman. It uses two numbers: e public key d private
RSA Step 1:selecting keys 1. Choose two very large prime numbers p and q 2. Find n n=p x q 3. Calculates another number ф = (p -1) X (q -1) 4. Choose random encryption number e, 1< e< ф gcd(e, ф)=1 (coprime) (You can use Euclidian algorithm to help you find correct e) 5. Calculate d so that d X e mod ф = 1 (using table method) Note : Announce e and n to the public; keep ф and d secret.
RSA Step 2: Encryption (Sender) Where P : plain text n= pxq C : cipher text e: public key Restriction P < n, if not, the plaintext needs to be divided into blocks to make P less than n.
RSA Step 3: Decryption (Receiver) Where P : plain text n= pxq C : cipher text d: private key
RSA: Example 1 Perform encryption and decryption using the RSA algorithm, for the following: p = 3; q = 11, e = 7; M = 5
RSA Step 1:selecting keys 1. p=3 ; q =11 2. n=p x q = 3 x 11 =33 n=33 3. ф = (p -1) X (q -1) = (3-1) x (11-1)= 2 x10 = 20 ф = 20 4. e (which is mentioned in question ) e=7 1< e< ф gcd(e, ф)=1 (coprime) (You can use Euclidian algorithm to help you find correct e) 5. Calculate d so that d X e mod ф = 1 (using table method) Note : Announce e and n to the public; keep ф and d secret.
Euclidian algorithm 2 7 20 14 6 1 7 6 1 1. Divide the ф by e 1 6 6 0 STOP 2. Divide the divisor of the previous division by the reminder of the previous division 3. Repeat step 2 until the reminder become 0
Euclidian algorithm cont. Rewrite the previous operations as the following: Dividend= (divisor x quotient )+ Reminder 20=(7 x 2) + 6 7= (6 x 1) + 1 6=(6 x 1) +0 This is the gcd(20,7)
Table method Row # a b c g 1 1 0 20-2 0 1 7 2 1. As default in all situations, put the values of a 1 and b 0 in 1 st row and the values of a 0 and b 1in 2 nd row 2. 1 st row : c= ф and g= empty 3. 2 nd row : c= e and g= (c1 /c2) (take only the integer part) (20/7)=2.8 2
Table method cont. Row # a b c g 1 1 0 20-2 0 1 7 2 3 1-2 6 1 3. 3 rd row: In row n column n = column n 2 column n 1 x g n 1 except g n = c n 1 / c n (take only the integer part) a3= a1-a2*g2 1-0*2=1 b3= b1-b2*g2 0-1*2=-2 c3= c1-c2*g2 20-7*2=6 ( it s the reminder of 20/7) g3= (c2 /c3) (take only the integer part) (7/6)=1.16 1
Table method cont. Row # a b c g 1 1 0 20-2 0 1 7 2 3 1-2 6 1 4-1 3 1 6 4. 4 th row: In row n column n = column n 2 column n 1 x g n 1 except g n = c n 1 / c n (take only the integer part) a4= a2-a3*g3 0-1*1=-1 b4= b2-b3*g3 1-(-2)*1=3 c4= c2-c3*g3 7-6*1=1 ( it s the reminder of 7/6) g4= (c3 /c4) (take only the integer part) (6/1)=6
Table method cont. Row # a b c g 1 1 0 20-2 0 1 7 2 3 1-2 6 1 4-1 3 1 6 Stop when the value of c become 1 Then the latest value of b is the value of d d=3 Important notes : 1. If the value of b is negative d= ф + b 2. If the value of b> ф d= b mod ф To confirm your answer: a*ф + b*e = gcd (ф,e) In our example : -20 + 21 = 1 1=1 it s correct
RSA Step 1:selecting keys 1. p=3 ; q =11 2. n=33 3. ф = 20 4. e=7 5. d=3 Note : Announce e and n to the public; keep ф and d secret.
RSA Step 2: Encryption (Sender) P=M= 5, e=7,n=33 C = 5 7 mod (33) C = [(5 4 mod 33) * (5 2 mod 33) * (5 1 mod 33)] mod 33 C = (31 * 25 * 5) mod 33 C = 3875 mod 33 C=14
RSA Step 3: Decryption (Receiver) C=14, d=3,n=33 P=14 3 mod 33 P = [(14 2 mod 33)*(14 1 mod 33)] mod 33 P= 434 mod 33 P=5
RSA: Example 2 Encrypt the following message YES By Using RSA algorithm. Assume that p=5, q =11, e= 3 Each character will be encoded according to this algorithm (A - Z) (00 25) Find d, then encrypt each character individually
RSA Step 1:selecting keys 1. p=5 ; q =11 2. n=p x q = 5 x 11 =55 55 3. ф = (p -1) X (q -1) = (5-1) x (11-1)= 4 x10 = 40 ф = 40 4. e (which is mentioned in question ) e=3 1< e< ф gcd(e, ф)=1 (coprime) (You can use Euclidian algorithm to help you find correct e) 5. Calculate d so that d X e mod ф = 1 (using table method) Note : Announce e and n to the public; keep ф and d secret.
Euclidian algorithm 13 3 40 39 1 3 3 3 0 STOP 1. Divide the ф by e 2. Divide the divisor of the previous division by the reminder of the previous division 3. Repeat step 2 until the reminder become 0
Euclidian algorithm cont. Rewrite the previous operations as the following: Dividend= (divisor x quotient )+ Reminder 40=(13x 3) + 1 3= (3 x 1) + 0 This is the gcd(40,3)
Table method Row # a b c g 1 1 0 40-2 0 1 3 13 1. As default in all situations, put the values of a 1 and b 0 in 1 st row and the values of a 0 and b 1in 2 nd row 2. 1 st row : c= ф and g= empty 3. 2 nd row : c= e and g= (c1 /c2) (take only the integer part) (40/3)=13.3 13
Table method cont. Row # a b c g 1 1 0 40-2 0 1 3 13 3 1-13 1 3 3. 3 rd row: In row n column n = column n 2 column n 1 x g n 1 except g n = c n 1 / c n (take only the integer part) a3= a1-a2*g2 1-0*13=1 b3= b1-b2*g2 0-1*13=-13 c3= c1-c2*g2 40-3*13=1 ( it s the reminder of 40/3) g3= (c2 /c3) (take only the integer part) (3/1)=3
Table method cont. Row # a b c g 1 1 0 40-2 0 1 3 13 3 1-13 1 3 Stop when the value of c become 1 Then the latest value of b is the value of d b= -13 (It s negative ) Based on note 1 d= ф+b 40+(-13)= 27 d= 27 Important notes : 1. If the value of b is negative d= ф + b 2. If the value of b> ф d= b mod ф To confirm your answer: a*ф + b*e = gcd (ф,e) In our example : 40+ (-39) = 1 1=1 it s correct
RSA Step 1:selecting keys 1. p=5 ; q =11 2. n=55 3. ф = 40 4. e=3 5. d=27 Note : Announce e and n to the public; keep ф and d secret.
RSA Step 2: Encryption (Sender) P=M=YES(must be encoded before), e=3,n=55 Y=24 S=18 C = 24 3 mod (55) C = 18 3 mod (55) C= 19 C= 2 E=4 C = 4 3 mod (55) C= 9
RSA Step 2: Encryption (Sender) cont. 27 24-Feb-15
RSA Step 3: Decryption (Receiver) C=19 P = 19 27 mod (55) P= 24 C=9 P = 9 27 mod (55) P= 4 C=2 P = 2 27 mod (55) P= 18