You mean to crack a message or just encode/decode one using the exclusiveOR method??<br>
<br>
<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href=
Below is some <b>very</b> simple code that shows how to do this. It would be much more secure if more than one byte was used for the "key", but I'm keeping it simple. It also has a minor bug. Can you spot it? <br>
<br>
<br>
#include <stdio.h><br>
#include <string.h><br>
<br>
int main()<br>
{<br>
<br>
int length, x;<br>
char OrgString[] = "Hello there!";<br>
char EncryptedStr[20];<br>
char DecryptedStr[20];<br>
char key = 0x55; /* The encryption/decryption key */<br>
<br>
printf( "Original string --->%s\n", OrgString );<br>
<br>
length = strlen( OrgString );<br>
/* In the loop below we encrypt the original string with the "key"*/<br>
for ( x=0; x<length; x++)<br>
{<br>
EncryptedStr[x] = OrgString[x] ^ key;<br>
}<br>
EncryptedStr[x] = 0;<br>
printf( "Encrypted string -->%s\n", EncryptedStr );<br>
<br>
<br>
length = strlen( EncryptedStr );<br>
/* In the loop below we decrypt the encrypted string with the "key"*/<br>
for ( x=0; x<length; x++)<br>
{<br>
DecryptedStr[x] = EncryptedStr[x] ^ key;<br>
}<br>
DecryptedStr[x] = 0;<br>
printf( "Decrypted string -->%s\n", DecryptedStr );<br>
<br>
return 0;<br>
}<br>
<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href=
Joebeach,<br>
I got your e-mail. No problem. The bug in the above code is that the message would be trunciated if any character in the "OrgString" matched the "key". If you put an uppercase U in the OrgString, you'll see what happens. I've had some fun with this (Added way more security), so check out the code below:<br>
<br>
#include <stdio.h><br>
#include <string.h><br>
#include <stdlib.h><br>
<br>
int main()<br>
{<br>
<br>
int length, x;<br>
char OrgString[] = "Hello there, and how are you today?";<br>
char EncryptedStr[80];<br>
char DecryptedStr[80];<br>
char key = 0x55; /* The encryption/decryption key */<br>
<br>
printf( "Original string --->%s\n", OrgString );<br>
<br>
length = strlen( OrgString );<br>
/* In the loop below we encrypt the original string with the "key" seed*/<br>
srand(key);<br>
for ( x=0; x<length; x++)<br>
{<br>
EncryptedStr[x] = OrgString[x] ^ rand();<br>
}<br>
EncryptedStr[x] = 0;<br>
printf( "Encrypted string -->%s\n", EncryptedStr );<br>
<br>
/* In the loop below we decrypt the encrypted string with the "key" seed*/<br>
srand(key);<br>
for ( x=0; x<length; x++)<br>
{<br>
DecryptedStr[x] = EncryptedStr[x] ^ rand();<br>
}<br>
DecryptedStr[x] = 0;<br>
printf( "Decrypted string -->%s\n", DecryptedStr );<br>
<br>
return 0;<br>
}<br>
<p> <br><a href=mailto:Kim_Christensen@telus.net>Kim_Christensen@telus.net</a><br><a href=
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.