Hi:
This is about as simple as encryption gets. I've implemented Bruce Schneier's xor algorithm from his book Applied Crytography.
Schneier rates this algorithm as an "embarrassment" in the amount of time a trained cryptographer needs to break this algorithm.
Regards,
Ed
#include <stdio.h>
int main(int argc, char *argv[])
{
char *key="theduke";
char *password="whopper";
char buffer[80];
int len;
/* encode the password*/
len=strlen(password);
strcpy(buffer, password);
xor(buffer, key, len);
printf("encoded password: %s \n", buffer);
/* decode the password*/
xor(buffer, key, len);
/* it works if both are the same */
printf("%s|%s|\n", password, buffer);
exit(0);
}
/*
* encode/decode 'str' with 'key' using the XOR
* algorithm. This algorithm is from Applied Cryptography
# by Bruce Schneier.
*/
int xor(str, key, len)
char *str;
char *key;
int len;
{
char *keys;
int str_len;
keys=key;
str_len=len;
while(len)
{
if(!*keys)
keys=key;
*(str++) ^= *(keys++);
len--;
}
str[str_len+1]='\0';
}