M
Mahesh
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int main(void)
{
int key = 120;
char *s = "String to Encrypt using XOR";
char *ss = s;
char echar;
char dchar;
size_t sizeofmsg = strlen(s)*sizeof(char*);
char *emsg = (char*)malloc(sizeofmsg);
char *dmsg = (char*)malloc(sizeofmsg);
char *ddmsg = dmsg;
char *eemsg = emsg;
int lenofmsg = strlen(s);
int count=0;
int i=0;
while(count++<strlen(s)){
echar = (char)(*ss^key);
emsg = &echar;
emsg++;
ss++;
}
count=0;
emsg = eemsg; // HERE when i restore the address of emsg via
eemsg, i'm not able to
// decrypt. How to restore the address of
original pointer to char ?.
i=0;
printf("\n");
while(count++<strlen(s)){
echar = *emsg;
dchar = (char)(echar ^ key);
ddmsg = &dchar;
printf(" %c",dchar);
emsg++;
ddmsg++;
}
printf("\n");
getch();
return 0;
}
#include <string.h>
#include <malloc.h>
int main(void)
{
int key = 120;
char *s = "String to Encrypt using XOR";
char *ss = s;
char echar;
char dchar;
size_t sizeofmsg = strlen(s)*sizeof(char*);
char *emsg = (char*)malloc(sizeofmsg);
char *dmsg = (char*)malloc(sizeofmsg);
char *ddmsg = dmsg;
char *eemsg = emsg;
int lenofmsg = strlen(s);
int count=0;
int i=0;
while(count++<strlen(s)){
echar = (char)(*ss^key);
emsg = &echar;
emsg++;
ss++;
}
count=0;
emsg = eemsg; // HERE when i restore the address of emsg via
eemsg, i'm not able to
// decrypt. How to restore the address of
original pointer to char ?.
i=0;
printf("\n");
while(count++<strlen(s)){
echar = *emsg;
dchar = (char)(echar ^ key);
ddmsg = &dchar;
printf(" %c",dchar);
emsg++;
ddmsg++;
}
printf("\n");
getch();
return 0;
}