Using XOR for Encryption

Any other programming language that is not covered in the Web Scripting category.

Using XOR for Encryption

Postby Talbas2001 on Thu Mar 09, 2006 1:08 am

I know that this is basic but I'm proud of it, considering that I'm still learning c++ Very Happy


Code: Select all
//----Simple Encryption / Decryption using XOR
// Written by Talbas March 8 2006


#include <iostream>

int main()
// Encryption Routine - replace the key and string with own data
{
char string[11]="talbas20011";
char key[11]="ABCDEFGHIJK";
for (int x=0; x<11; x++)
{
  string[x]=string[x]^key[x];
  std::cout << string[x];
}
// Decryption Routine - I placed this here to verify encryption
std:: cout << "\n";
for (int x=0; x<11; x++)
{
  string[x]=key[x]^string[x];
  std::cout << string[x];
}

return 0;

}
Image
Talbas2001
Contributer
Contributer
 
Posts: 68
Joined: Mon Feb 27, 2006 11:03 am
Location: Eureka, CA. - United States

neat

Postby taladon on Fri Mar 10, 2006 6:22 pm

Good for you!
I know it doesn't seem that big of a deal, but mastering small projects like that will prepare you for working on bigger and better things.
Code on!

--Taladon
taladon
Newbie
Newbie
 
Posts: 15
Joined: Fri Mar 10, 2006 5:37 pm

Good job

Postby selket on Sun Apr 16, 2006 12:30 am

You might also want to consider expanding the key so that you can encode any length string.

-selket
selket
Contributer
Contributer
 
Posts: 44
Joined: Sat Apr 15, 2006 11:59 pm
Location: Chicago, IL

Postby Bugs42 on Sun Apr 16, 2006 4:10 am

Nice. Simple, but a good learning project.
I didn't even know there was an XOR operation in C++. Cool use of it.
Sufficiently advanced technology is indistinguishable from magic.
Bugs42
Valued Member
Valued Member
 
Posts: 189
Joined: Sat Dec 03, 2005 6:48 pm

Postby kotuk on Sun Apr 16, 2006 10:30 am

Heh, XOR is nice... as far as you key bigger then the plaintext
but still nice Smile
kotuk
Contributer
Contributer
 
Posts: 24
Joined: Sat Apr 15, 2006 7:42 pm

Postby Shadowed on Tue Jun 13, 2006 1:18 am

There is a way to use short key for big plaintext - just repeat it over and over ;).
Shadowed
Newbie
Newbie
 
Posts: 17
Joined: Wed May 31, 2006 2:56 am

Postby alg8662 on Sun Aug 06, 2006 12:37 am

Now I'm definitely a C++ noob, but I think you can make your XOR program a little more flexible in string sizes by using the string library rather than allocating a 15-char array (one char of which must be taken up by the \0 terminator). Just a thought...
alg8662
Contributer
Contributer
 
Posts: 56
Joined: Fri Aug 04, 2006 1:22 pm

Postby gls on Wed Aug 16, 2006 6:24 am

Cool Good starting point. Just don't panic when NSA knocks on your door and puts you in a room (and they throw away the room)...

I'm kidding. But seriously they take encryption seriously, because they get pissed off when they can't crack your email messages...

You might be interested in doing some research on PGP...

http://en.wikipedia.org/wiki/OpenPGP
gls
Contributer
Contributer
 
Posts: 28
Joined: Wed Aug 16, 2006 4:30 am
Location: Chicago, IL


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron