In this example, you will learn about C program to encrypt and decrypt the string using two algorithms i.e. Caesar Cypher and RSA.
Encryption/Decryption using Caesar Cypher Algorithm |
Encryption/Decryption using RSA Algorithm |
Print Numbers Which are Divisible by 3 and 5 in C. This program will print numbers 1 to 100 which are divisible by 3 and 5. Find more Free Online C Tutorial. So, in summary, array names in a C program are (in most cases) converted to pointers. One exception is when we use the sizeof operator on an array. If a was converted to a pointer in this context, sizeof a would give the size of a pointer and not of the actual array, which would be rather useless, so in that case a means the array itself.
For encryption and decryption, we have used 3 as a key value.
While encrypting the given string, 3 is added to the ASCII value of the characters. Similarly, for decrypting the string, 3 is subtracted from the ASCII value of the characters to print an original string.
Let’s take a look at the program.
#Encryption
#Decryption
Explanation
In the above program, we have used simple logic for encrypting and decrypting a given string by simply adding and subtracting the particular key from ASCII value.
RSA is another method for encrypting and decrypting the message. It involves public key and private key, where the public key is known to all and is used to encrypt the message whereas private key is only used to decrypt the encrypted message.
It has mainly 3 steps:
1: Creating Keys
n = x * y
n
is the modulus of private and the public keyø (n) = (x − 1)(y − 1)
e
such that e
is coprime to ø(n)
and 1 < e < ø(n)
.e
is the public key exponent used for encryptiond
, so that d · e mod ø (n) = 1
, i.e., >code>d is the multiplicative inverse of e
in mod ø (n)2: Encrypting Message
Messages are encrypted using the Public key generated and is known to all.
The public key is the function of both e
and n
i.e. {e,n}
.
If M
is the message(plain text), then ciphertext
3: Decrypting Message
The private key is the function of both d
and n
i.e {d,n}
.
If C
is the encrypted ciphertext, then the plain decrypted text M
is
Here is an implementation of RSA in C program.
Output