CN-Lab Exp-7
CN-Lab Exp-7
Decryption Formula
The Formula for Caesar cipher decryption is Dn(x) = (x – n) mod 26.
here,
Dn(x) represents the Decryption of x,
x is the letter that is going to be decrypted,
and n is the number that is going to be reduced.
int main() {
char plaintext[100], ciphertext[100], decryptedtext[100];
int shift;
return 0;
}
Explanation
encrypt Function:
o Encrypts the input plaintext by shifting each letter by the specified
shift value.
o The % 26 operation ensures the shifting wraps around the
alphabet.
o Non-alphabet characters are not altered.
decrypt Function:
o Decrypts the input ciphertext by reversing the shift operation.
o The + 26 ensures the result is always positive before taking the %
26 operation.
Usage
1. Input:
o The user enters the plaintext message they wish to encrypt.
o The user specifies the shift value for the Caesar Cipher.
2. Encryption:
o The program encrypts the plaintext using the shift value and prints
the ciphertext.
3. Decryption:
o The program decrypts the ciphertext using the same shift value
and prints the decrypted text.
Example
Input:
Enter the plaintext: HELLO
Enter the shift value: 3
Output:
Encrypted text: KHOOR
Decrypted text: HELLO