MATH 243 -- Algebraic Structures 

RSA Encryption/Decryption Example 

11/5/2012 

 

For this "toy example" we will use an RSA system with  

so the modulus is `and`(m = `*`(23, 41), `*`(23, 41) = 943.)  As  

encryption exponent we need some  ewith gcd(e, `*`(`+`(p, `-`(1)), `*`(`+`(q, `-`(1))))) = 1. 

We use  which is OK since  `and`(`*`(`+`(p, `-`(1)), `*`(`+`(q, `-`(1)))) = `*`(22, 41), `and`(`*`(22, 41) = 880, 880 = `*`(`+`(`*`(5, `*`(`^`(2, 4)))), 11.))) 

Say the plain text message is  

 

     SEND TWO COPIES 

 

According to the basic integer[27]encoding we have used this becomes 

 

      19,5,14,4,0,20,23,15,0,3,15,9,5,19 

 

For this RSA system, since the modulus is about 1000, we can 

group the numerical form of the plain text into three-digit  

"blocks" and apply the encryption function  proc (x) options operator, arrow; `mod`(`*`(`^`(x, 21)), 943) end proc 

to each block like this: 

 

> `assign`(plaintext, [195, 144, 20, 231, 503, 159, 519]); 1
 

[195, 144, 20, 231, 503, 159, 519] (1)
 

> `assign`(cyphertext, []); -1; for i to nops(plaintext) do `assign`(cyphertext, [op(cyphertext), `mod`(`*`(`^`(plaintext[i], 21)), 943)]) end do; -1
`assign`(cyphertext, []); -1; for i to nops(plaintext) do `assign`(cyphertext, [op(cyphertext), `mod`(`*`(`^`(plaintext[i], 21)), 943)]) end do; -1
`assign`(cyphertext, []); -1; for i to nops(plaintext) do `assign`(cyphertext, [op(cyphertext), `mod`(`*`(`^`(plaintext[i], 21)), 943)]) end do; -1
`assign`(cyphertext, []); -1; for i to nops(plaintext) do `assign`(cyphertext, [op(cyphertext), `mod`(`*`(`^`(plaintext[i], 21)), 943)]) end do; -1
 

> cyphertext; 1
 

[113, 349, 61, 507, 153, 241, 752] (2)
 


(This would not be converted back to a literal format for the RSA system --
 

the cyphertext is a string of numerical data.) 

 

Now, knowing p, qwe can compute the decryption exponent easily -- it is  

the  [d]  such that  `*`([e], `*`([d])) = [1]in  By our usual methods, we know 

that is   

 

For a "real" RSA system, though, the security would come from the fact that  

the factorization m = pq  would not be known, so, even knowing the encryption  

exponent  e,  there would not be any obvious way to find [d] = `/`(1, `*`([e]))in   

Here, we do have [d]so we can decrypt easily (and parallel to the method 

used for encryption): 

> `assign`(decrypt, []); -1; for i to nops(cyphertext) do `assign`(decrypt, [op(decrypt), `mod`(`*`(`^`(cyphertext[i], 461)), 943)]) end do; -1
`assign`(decrypt, []); -1; for i to nops(cyphertext) do `assign`(decrypt, [op(decrypt), `mod`(`*`(`^`(cyphertext[i], 461)), 943)]) end do; -1
`assign`(decrypt, []); -1; for i to nops(cyphertext) do `assign`(decrypt, [op(decrypt), `mod`(`*`(`^`(cyphertext[i], 461)), 943)]) end do; -1
`assign`(decrypt, []); -1; for i to nops(cyphertext) do `assign`(decrypt, [op(decrypt), `mod`(`*`(`^`(cyphertext[i], 461)), 943)]) end do; -1
 

> decrypt; 1
 

[195, 144, 20, 231, 503, 159, 519] (3)
 

When this is broken back up into two-digit groups and converted back to literal 

form, the original message is recovered(!)