## RSA Encryption in Discrete MathematicsRSA stands for RSA is a type of public-key cryptography. There are various types of public-key cryptography, but the most famous one is RSA. The RSA is totally based on the number theory. The RSA can be used in file encryption, secure shell or ftp, sending information of credit card/ debit card, saving passwords, encrypting e-mails, and many more.
There can be an opposite case where the owner encrypts the message with the help of their private key, and anyone has the ability to decrypt it. But in this case, only the owner can encrypt the message.
To more understand this example in the real world, we can replace Harry with the bank, homework with the credit card number, and students with customers. So everyone who has a bank account, and sends the message to bank. The other customer can only know that some customer has a credit card of this bank, but the credit card details are only contained by the bank and that customer. ## Generating of RSA keys:The following steps will be used to generate the public key or private key pair in RSA: - Suppose there is a pair p and q, which indicate large random prime numbers and contain the same amount of bits. We have to generate these p and q.
- Now, we have to compute the n in the following form:
n = pq Here modules are indicated by the public integer n. - Now, we will select an odd public exponent e that is relatively primed to the following terms: (p - 1) (q - 1) and 1 < e < (p - 1) (q - 1)
- Now, we have to compute the p, q, and a private exponent d.
- The Private keys will be calculated by the pair (n, d), and Public keys are indicated by the pair (n, e).
## Questions related to Key generation:There are some questions related to key generation, which are described as follows:
So here we will try primes, and we have to be careful that these primes do not divide
## Working Scenario of RSASuppose Alice wants to send the office files to Bob. She will post the grades on Piazza, but at the same time, she doesn't want that the other students will read them. So for this, Alice and Bob need a cryptosystem. Here Bob has both the keys: Public key and private key. So Bob will set up the private key and public key for their office privacy. The public key (n, e) will be set as (3233, 17), and the private key (n, d) as (3233, 2753). He will keep 'd' secret and posts 'n' and 'e' on piazza. Here Alice encrypts the message with the help of Bob's public key. Alice also doesn't know the private key d. After all, someone could intercept that if Bob were to send it to Alice. Bob is able to decrypt the message with the help of their own private key. We can only encrypt the message with the help of a public key, but we cannot decrypt it. So, in this case, anyone who is on Piazza is able to send the message to Bob. But the clear text of each message can be read by the sender and Bob. ## RSA EncryptionThe encryption is used to secretly send the message. We can encrypt a message which is encoded as an integer with the help of following ways: First, we will translate each letter into an integer. After that, we will form a larger integer by grouping these integers. A block of letters will be represented by these larger integers. Each block can be encrypted with the help of following mapping: c = m ^{e} mod nIn other words, the encryption operation of RSA can be described as exponentiation to the e c = ENCRYPT (m) = m ^{e} mod nHere c is used to indicate the resulting
Suppose Anne wants to send a message "gcd" to Chris. For this, she will encode this message into a positive integer m, which must be smaller than the module n = 3233. If the message is longer, then it will be broken into chunks. The transformation will be reversible. In this example, there will be two-character chunks and maximum 9 characters in the alphabet, which is described as follows: 'gcd' → 'gc', 'd_' → 7.10 + 3, 4.10 + 0 → 73, 40 Here the underscore is used to indicate the padding. It is obviously reversible. Till now, nothing is secret or mysterious. We will encrypt and separately send 73 and 40. First, we will send m = 73, and after that, we will send m = 40. ## Working of RSA EncryptionHere Message m = 73, Public key (n, e) = (3233, 17). When we encrypt a message, it will generate cipher text like this: c = m After putting the values, we will get the following c = 7317 MOD 3233 c = 4747758526700098686074966922953 MOD 3233 = 1486 As we can see that the final result is small, but the intermediate result is huge. We can fix that with the help of pow. Now post the result of c (ciphertext), which is 1486 on Piazza. ## Example of RSA Encryption:In this example, we have to use RSA to encrypt the message "STOP" with p = 43, q = 59, and e = 13.
- We have to first determine n with the following formula:
n = p * q n = 43 * 59 = 2537 - After that, we have to convert each letter into a number in [0, 25].
S = 18, T = 19, O = 14, P = 15. - Now, we have to group the sequence into the blocks of 4 digits, which is described as follows:
m = 1819 1415 - Now, we will encrypt each block with the help of formula:
c = m^{13}(mod 2537) - Now, we have to first determine the first block like this:
1819^{13}= mod 2537 = 2081 - Now, we have to determine the second block like this:
141513 = (mod 2537) = 2182
So the Ciphertext c = 2081 2182 Next TopicIntroduction to Mojette Transform |