Download presentation
Presentation is loading. Please wait.
Published byLaura Morgan Modified over 8 years ago
1
Information and Computer Security CPIS 312 Lab 8 1 Asymmetric Key Algorithms RSA Algorithm TRIGUI Mohamed Salim
2
1. Using RSA algorithm to Encrypt and Decrypt plaintext. 2. Learn how to achieve RSA algorithm parameters using some calculations, predefined procedures, and user defined in procedures. 3. Trying to adjust RSA by using different tactics 2 Lab Objectives
3
1. Students will be able to use RSA to encrypt and decrypt plaintext. 2. Students will be able to calculate different RSA parameters such as : A. Calculating E ( encryption parameter) B. Calculating D ( decryption parameter) C. Calculating GCD ( greatest common divisor) 3 Lab Outcomes
4
4 Data Encryption Standard (RSA) RSA Pseudo code: - Select P, Q where P and Q are prime numbers, P ≠Q - Calculate n, where n = P * Q - Calculate Ф (n), where Ф (n) = (P-1)(Q-1) - Select Random E such as : gcd (Ф (n), E) = 1 1<E< Ф (n), - Calculate D, where d.e ≡ 1 (mod φ(n)) - Public key {E,n} - private key {D,n}
5
5 Example 1 Use RSA algorithm to encrypt the following text number: Plaintext: 88 - Select P = 17, Q = 11 - Calculate n, n = 17 *11 = 187 - Calculate Ф (n), 16 * 10 = 160 - Select Random E such as: gcd (E, Ф (n),) = 1 1<E< Ф (n), E = 7 because gcd (7,160) = 1
6
6 Example 1 - Calculate D, where d.e ≡ 1 (mod φ(n)) D * 7 ≡ 1 mod 160 D = 23 - Public key { 187, 7} - private key {187, 23}
7
7 Example 1 Encryption: c = m e mod n 88 7 mod 187=11=Cipher Decryption: m = c d mod n 11 23 mod 187 = 88
8
8 Example 2 Select primes p=11, q=3. n = p.q = 11.3 = 33 phi = (p-1)(q-1) = 10.2 = 20 Choose e=3, gcd(e, phi)= gcd(3, 20)= gcd(20, 2) = gcd(2, 0)=1 (This means that 3 and 20 are coprime)
9
9 Example 2 Compute d such that ed ≡ 1 (mod phi) Simple testing (d = 1, 2,...) gives d = 7 Check: ed-1 = 3.7 - 1 = 20, which is divisible by phi. Public key = (n, e) = (33, 3) Private key = (n, d) = (33, 7).
10
10 Example 2 Now say we want to encrypt the message m = 7, c = m e mod n = 7 3 mod 33 = 343 mod 33 = 13. To check decryption we compute m = c d mod n = 13 7 mod 33 = 7. a = bc mod n = (b mod n).(c mod n) mod n
11
11 Hint that help in implementation 1. Modular Exponentiation routine /* return x^n (mod p) Assume x, n > = 0, p>0, x < p, 0^0 = 1 */ Public static long power (long x, long n, long p) { If (n ==0) {return 1 ;} long tmp = power( (x*x)%p, n/2, p ); if ( n% 2 != 0) { tmp = (tmp*x)% p ;} return tmp; }
12
12 Hint that help in implementation 2. Greatest common divisor /* Return the Greatest common divisor */ public static long gcd( long a, long b ) { if (b==0) return a; else return gcd ( b, a%b); }
13
13 Homework You intercept a message encrypted using RSA with value C = 10. You know that the message is intended for a user whose public key is {e=5, n=35}. Find the plaintext M. Hint: Factorize n to find p and q. Use e*d*mod ø(n) = 1 and trial and error to find d
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.