0% found this document useful (0 votes)
109 views3 pages

Practicle:-2: AIM:-Implement Monoalphabetic Cipher Encryption-Decryption

The document describes an implementation of a monoalphabetic cipher for encryption and decryption of messages. It takes a message and encryption key as input, encrypts the message by shifting each character by the key, and stores it in a new string. It then decrypts the encrypted message by shifting the characters in the opposite direction by the key and stores it in another string. The original and decrypted messages are printed for comparison.

Uploaded by

Ridham Vyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views3 pages

Practicle:-2: AIM:-Implement Monoalphabetic Cipher Encryption-Decryption

The document describes an implementation of a monoalphabetic cipher for encryption and decryption of messages. It takes a message and encryption key as input, encrypts the message by shifting each character by the key, and stores it in a new string. It then decrypts the encrypted message by shifting the characters in the opposite direction by the key and stores it in another string. The original and decrypted messages are printed for comparison.

Uploaded by

Ridham Vyas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practicle:-2

 AIM:-Implement Monoalphabetic cipher


encryption-decryption.

#include<stdio.h>
#include<ctype.h>

int main()
{
char *message,*emessage,*dmessage;
int i,j=0,k,key,temp;

printf("\nEnter the key\n");


scanf("%d",&key);
key=key%26;
printf("\nEnter message\n");
fflush(stdin);
gets(message);

for(i=0;message[i]!=NULL;i++)
message[i]=tolower(message[i]);

for(i=0;message[i]!=NULL;i++)
{
//printf("%c ",message[i]);
if(message[i]==' ')
emessage[j++]=message[i];

else
{

if(message[i]>=48 && message[i]<=57)


{
temp=message[i]+key;
if(temp>57)
emessage[j++]=48+(temp-58);
else
emessage[j++]=temp;
}
else
{
if(message[i]>=97 && message[i]<=123)
{
temp=message[i]+key;
if(temp>122)

Name:-Ridham Vyas Enrollment No:-170630116035


emessage[j++]=97+(temp-123);
else
emessage[j++]=temp;
}
else
emessage[j++]=message[i];
}

printf("%c ",emessage[j]);
}

emessage[j]='\0';
printf("\n\n\nEncrypted message is\n\n");
for(i=0;emessage[i]!=NULL;i++)
printf("%c",emessage[i]);
printf("\n end");

for(i=0,j=0;emessage[i]!=NULL;i++)
{

if(emessage[i]==' ')
dmessage[j++]=emessage[i];
else
{
if(emessage[i]>=48 && emessage[i]<=57)
{
temp=emessage[i]-key;
if(temp<48)
dmessage[j++]=58-(48-temp);
else
dmessage[j++]=temp;
}
else
{
if(emessage[i]>=97 && emessage[i]<=123)
{
temp=emessage[i]-key;
if(temp<97)
dmessage[j++]=123-(97-temp);
else
dmessage[j++]=temp;
}
else
dmessage[j++]=emessage[i];
}
}
Practicle:-2
}
dmessage[j]='\0';
printf("\n\n\nRetrieved message is\n\n");
for(i=0;dmessage[i]!=NULL;i++)
printf("%c",dmessage[i]);

return(1);
}

 OUTPUT

Name:-Ridham Vyas Enrollment No:-170630116035

You might also like