I have been working on an sncryption program recently, and at first it was okay and everything was working, but then it all started to go wrong.
It was working before, because i was using rather short strings. Then i actually used some decent sized files and it all stopped working. Rather than being able to see all the decrypted text, i only ever got the first line or so, then it would stop showing me the text. Below is the code for both my encryption, and my decryption program. Below that is an example of what happens.


Encryption Program

Code:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

char encrypt(char letter, int pass, int i)
{
     return letter + pass * pass * i - i;
}
int main()
{
    ifstream oldfile;
    ofstream newfile;
    string input;
    int pass;
    char letter;
    int i = 1;
    cout<<"what is the name of the file that you want encrypted?\n";
    getline(cin,input,'\n');
    oldfile.open(input.c_str());
    cout<<"what is the number password you wish to use to encrypt the file?\n";
    cin>>pass;
    cout<<"what is the name of the file you want the encrypted text to go to?\n";
    cin.get();
    getline(cin,input,'\n');
    newfile.open(input.c_str());
    while (oldfile)
    {
          oldfile.get(letter);
          if (oldfile)
          {
                       newfile.put(encrypt(letter,pass,i));
                       i++;
          }
    }
    cout<<"finished";
    oldfile.close();
    newfile.close();
    cin.get();
    cin.get();
}

Decryption Program


Code:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

char encrypt(char letter, int pass, int i)
{
     return letter - pass * pass * i + i;
}
int main()
{
    ifstream oldfile;
    string input;
    int pass;
    char letter;
    int i = 1;
    cout<<"what is the name of the file that you want decrypted?\n";
    getline(cin,input,'\n');
    oldfile.open(input.c_str());
    cout<<"what is the number password you used to encrypt the file?\n";
    cin>>pass;
    cout<<"here is your decrypted text:\n";
    while (oldfile)
    {
          oldfile.get(letter);
          if (oldfile)
          {
                       cout<<encrypt(letter,pass,i);
                       i++;
          }
    }
    oldfile.close();
    cin.get();
    cin.get();
}

Anyway, this is what happens when i use the program on the following string, using the number 12 as a password.

ok, this is a test, im working on it, i appear to be facing a lot of problems, these are really starting to annoy me.
This is why I'm resorting to the internet, maybe someone can help.
Anyway, I'm still typing because I need a long string to test, it seems to be okay with shorter strings.
I think the problem might be when i press enter and start a new line. Anyway, we'll see what people on the forums think.

This is the outputted text once i run the program.

ok, this is a test, im working on it, i appear to be f

Does anyone know why this is happening, and if so, what can i do about it?
The amount of text i see has something to do with the password because with a different password, i see a different amount of text.