simple Encryption program
program in c language
#include<stdio.h>
#include<string.h>
void main()
{
char string[100];
int a,temp,count,length,key=7;
printf("Press 1 for encryption or 2 for decryption..");
scanf("%d",&a);
if(a==1)
{
printf("Enter a text to be encrypt.....");
scanf("%s", string);
#include<string.h>
void main()
{
char string[100];
int a,temp,count,length,key=7;
printf("Press 1 for encryption or 2 for decryption..");
scanf("%d",&a);
if(a==1)
{
printf("Enter a text to be encrypt.....");
scanf("%s", string);
length = strlen(string) - 1;
for(count = 0; count < length; count++, length--)
{
temp = string[count];
string[count] = string[length];
string[length] = temp;
}
length=strlen(string) - 1;
for(int i =0;i<length;i++)
{
string[i]= string[i]+key;
key++;
}
printf("Encrypted text is....%s\n",string);
}
if(a==2)
{ printf("Enter a text to be decrypt.....");
scanf("%s", string);
length = strlen(string) - 1;
length=strlen(string) - 1;
for(int i =0;i<length;i++)
{
string[i]= string[i]-key;
key++;
}
for(count = 0; count < length; count++, length--)
{
temp = string[count];
string[count] = string[length];
string[length] = temp;
}
printf("Decrypted text is....%s\n",string);
}
}
for(count = 0; count < length; count++, length--)
{
temp = string[count];
string[count] = string[length];
string[length] = temp;
}
length=strlen(string) - 1;
for(int i =0;i<length;i++)
{
string[i]= string[i]+key;
key++;
}
printf("Encrypted text is....%s\n",string);
}
if(a==2)
{ printf("Enter a text to be decrypt.....");
scanf("%s", string);
length = strlen(string) - 1;
length=strlen(string) - 1;
for(int i =0;i<length;i++)
{
string[i]= string[i]-key;
key++;
}
for(count = 0; count < length; count++, length--)
{
temp = string[count];
string[count] = string[length];
string[length] = temp;
}
printf("Decrypted text is....%s\n",string);
}
}
Comments
Post a Comment