WeeZer51402
Registered
ok every body what i want to do is create a little simple encryption scheme, i have one here but id like to add on to it.
'#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
char string[100],yn;
int c,a=0,offset;
int encrypt(void);
int main (void)
{
encrypt();
return 0;
}
int encrypt(void)
{
printf("> ");
scanf("%s", &string);
printf("Offset by > ");
scanf("%d", &offset);
for(c=0;c<(strlen(string));c++)
{
a=(int)string[c];
string[c]=(char)(a+offset);
}
printf("%s\n", string);
printf("Run again? y/n: ");
scanf("%s", &yn);
if(yn=='y')
encrypt();
else
return 0;
}'
what this program does is it gets a string from the user, converts the characters to there decimal ascii value adds what the user wishes to off set the value by and converts it back to a character, heres what id like to do is say the user enters 'hello' (string[0]='h', string[1]='e', string[2]='l', string[3]='l', string[4]='o')
id like to be able to have the program take each char encrypt it but then add some extra stuff to the string so for instance hello would then = (string[0]='h', string[1]='a', string[2]='e'', string[3]='b', string[4]='l', string[5]='c', string[6]='l', string[7]='d', string[8]='o', string[9]='e')
in other words replacing every other character or every 2 characters or whatever, hopefully user specefied , with just some random garbage,as opposed to 'a,b,c,d,e', that can be encrypted as well the actual contents of the string. any help would be greatly appreceated thanks.
-mike
'#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
char string[100],yn;
int c,a=0,offset;
int encrypt(void);
int main (void)
{
encrypt();
return 0;
}
int encrypt(void)
{
printf("> ");
scanf("%s", &string);
printf("Offset by > ");
scanf("%d", &offset);
for(c=0;c<(strlen(string));c++)
{
a=(int)string[c];
string[c]=(char)(a+offset);
}
printf("%s\n", string);
printf("Run again? y/n: ");
scanf("%s", &yn);
if(yn=='y')
encrypt();
else
return 0;
}'
what this program does is it gets a string from the user, converts the characters to there decimal ascii value adds what the user wishes to off set the value by and converts it back to a character, heres what id like to do is say the user enters 'hello' (string[0]='h', string[1]='e', string[2]='l', string[3]='l', string[4]='o')
id like to be able to have the program take each char encrypt it but then add some extra stuff to the string so for instance hello would then = (string[0]='h', string[1]='a', string[2]='e'', string[3]='b', string[4]='l', string[5]='c', string[6]='l', string[7]='d', string[8]='o', string[9]='e')
in other words replacing every other character or every 2 characters or whatever, hopefully user specefied , with just some random garbage,as opposed to 'a,b,c,d,e', that can be encrypted as well the actual contents of the string. any help would be greatly appreceated thanks.
-mike