Encrypting using C++

seanharding
seanharding used Ask the Experts™
on
Hi, i'm doing a C++ project for school. I'm reading and writing to a file, and am wondering if it is possible to encrypt the data stored in the file and then unencrypt it when it is pulled back onto the screen, i'm doing console programming, and was wondering if any of you could help me. is there any simple code to use (i really dont expect it to be simple, but there must be a way)

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Guidelines:
1) create two simple functions, one for encrypting and one for decripting.
Each function will receive one character as input and return one encrypted/decripted character

char encrypt(char ch);
char decrypt(char ch)

2) for each character you write to the file call the function for encryption, and for each character you read from it call the function for decryption

3) The encryption/decription may be something simple like adding a const offset to the character values.
In example for encryption add 50 and for decription substruct 50.
This assumes no problems for text files with english text.

4) To check it work use something like

char c = 'a';
char d;
char e;

d = encrypt(c);
e = decrypt(d);

cout << "orig: " << c << endl;
cout << "encrypted: " << d << endl;
cout << "decrypted: " << e << endl;

e should equal c
d should be different and even a strange character might appear, depending on your offset.

Author

Commented:
That should work perfect, thanks I never thought of that its quite simple too! Thanks alot this will really help me out alot!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial