CNS Practical-3

#include <stdio.h>
#include <string.h>

int main()
{
    char pt[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
                   'x', 'y', 'z'};
    char ct[26] = {'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd',
                   'c', 'b', 'a'};
    char p[20] = {'\0'}, c[20] = {'\0'}, r[20] = {'\0'};
    printf("Enter the plain text: ");
    scanf("%s", p);
   
    // converting plain text into cipher text (encryption)
    for (int i = 0; i < strlen(p); i++)
    {
        for (int j = 0; j < 26; j++)
        {
            if (pt[j] == p[i])
                c[i] = ct[j];
        }
    }
    printf("Cipher text is: %s", c);

    // converting cipher text into plain text (decryption)
    for (int i = 0; i < strlen(c); i++)
    {
        for (int j = 0; j < 26; j++)
        {
            if (ct[j] == c[i])
                r[i] = pt[j];
        }
    }
    printf("\nPlain text is: %s", r);
    return 0;
}

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!
Scroll to Top