Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A simple way to encrypt/decrypt a CString?

Status
Not open for further replies.

d00ape

Programmer
Apr 2, 2003
171
SE
I’m going to Serialize a class with CString and int-members to a file and then transfer it over the network. One of the members is a password-like one and I would like it to be encrypted before the serialization.

Any tip fore easy implementation.
 
the easyest way is XOR encription, but it is not the best.
For each sumbol you apply a XOR per bit
for example you have password key qwerty. And you have string, "hello my baby, I want to see you"
you encript like this:

hello my baby, I want to see you
^=
qwertyqwertyqwertyqwertyqwertyqw|erty
like this:
str[0] ^= q;
str[1] ^= w;
str[3] ^= e;
....
and you obtain some encripted string:
dfsdfsdfasddadfasdfwtkoeyjlkruju

after you send the string you can uncrypt it by aplaying XOR again:
dfsdfsdfasddadfasdfwtkoeyjlkruju
^= qwertyqwertyqwertyqwertyqwertyqw|erty
The operation will be the same:
obtained_str[0] ^= q;
obtained_str[1] ^= w;
obtained_str[3] ^= e;
.....
and you will obtain the originally created string:
hello my baby, I want to see you


Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top