×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

decoding encrypted message

decoding encrypted message

decoding encrypted message

(OP)
can someone tell me how to decode an encrypted message by using exclusive OR and using the orginal encryption key?

RE: decoding encrypted message

(OP)
Kim,
just to decode a message using XOR. I don't mind to learn how to crack a message though.

Joe

RE: decoding encrypted message

Below is some very 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? ;)


#include <stdio.h>
#include <string.h>

int main()
{

int length, x;
char OrgString[] = "Hello there!";
char EncryptedStr[20];
char DecryptedStr[20];
char key = 0x55; /* The encryption/decryption key */

printf( "Original string --->%s\n", OrgString );

length = strlen( OrgString );
/* In the loop below we encrypt the original string with the "key"*/
for ( x=0; x<length; x++)
     {
     EncryptedStr[x] = OrgString[x] ^ key;
     }
EncryptedStr[x] = 0;
printf( "Encrypted string -->%s\n", EncryptedStr );


length = strlen( EncryptedStr );
/* In the loop below we decrypt the encrypted string with the "key"*/
for ( x=0; x<length; x++)
     {
     DecryptedStr[x] = EncryptedStr[x] ^ key;
     }
DecryptedStr[x] = 0;
printf( "Decrypted string -->%s\n", DecryptedStr );

return 0;
}


Kim_Christensen@telus.net
Home Page

RE: decoding encrypted message

Joebeach,
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:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{

int length, x;
char OrgString[] = "Hello there, and how are you today?";
char EncryptedStr[80];
char DecryptedStr[80];
char key = 0x55; /* The encryption/decryption key */

printf( "Original string --->%s\n", OrgString );

length = strlen( OrgString );
/* In the loop below we encrypt the original string with the "key" seed*/
srand(key);
for ( x=0; x<length; x++)
    {
    EncryptedStr[x] = OrgString[x] ^ rand();
    }
EncryptedStr[x] = 0;
printf( "Encrypted string -->%s\n", EncryptedStr );

/* In the loop below we decrypt the encrypted string with the "key" seed*/
srand(key);
for ( x=0; x<length; x++)
    {
    DecryptedStr[x] = EncryptedStr[x] ^ rand();
    }
DecryptedStr[x] = 0;
printf( "Decrypted string -->%s\n", DecryptedStr );

return 0;
}


Kim_Christensen@telus.net
Home Page

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close