Monday, January 9, 2012

Encoding text (basic encoding)

/* program for encoding entered text to any symbol (within the ASCII range)*/

#include<stdio.h>
#include<string.h>
void main()
{
char src[100]={0},enc[100]={0},c;
int i=0,d,len;
clrscr();
printf("enter text which you want to encode--");

while((c=getchar())!='\n')        //storing the entered text
 src[i++]=c; 

i=0;                                                                                                        len=strlen(src);

while(i<len)                  //main logic
{
d=src[i];
d=d+13;                      //instead of 13 you can take any value,
c=d;                              // but sum should be <255 because ASCii
enc[i]=c;                  //maximum value is 255
i++;
}

printf("encoded data is :\n\n\t %s",enc);

getch();
}

No comments:

Post a Comment