Encrypting input text file

I would like to write a program just for fun. (Inspired by the movie, The Imitation Game)
The program will input a txt file, lets say it holds the word "game" in it.
Then when it inputs it, it will then change each letter to a new letter, then it will output it. So inputs "game" and then outputs "jusa" (jibberish, basically) I know fstream and stuff. My only problem is the conversion of inputted text, "game".

I don't want you guys to write the program for me, just some help on what to use to create a "key" to encrypt and decrypt messages with
you can create an array of letters, for example:
char letters [] = {'a', 'b' ...}

user inputs a key for example:
94350829

you derive some reasonable number from the key, ie. 8

input test is for example:
"some text"

Now you replace each letter of text with a letter 8 places away in alphabet, and end up with "encrypted" text.

to decrypt, you will also need a function that replaces letters by 8 places in opposite way.

if password is wrong, output will also be wrong.
Awesome, I had that idea as well just didn't know how to implement it. Thanks for the reply, lets say I made a char a = 'a'

if I do a = a + 5;
would that make char a = f? does it change the place 5 places?
And can you also explain what to do with the array of letters?
no, you would use 'letters' as a pointer or iterator to iterate trough alphabet up and back depending on user supplied key.

for example
1
2
3
4
5
6
7
vector<char> alphabet = { /* input alphabet here */ }

string plaintext = "some text"

// replace each character 8 places away:
for(short i = 0; i < plaintext.size(); ++i)
         plaintext.at(i) = alphabet.at(i + 8);


you will also need to ensure not to iterate to far away, ie. by checking the iterator or something and if it's not valid to return it back to the beggining of alphabet and until char from 8 places away is obtained.
Last edited on
Topic archived. No new replies allowed.