Shift Encryption Error

I am working on a program that will use a shift to encrypt a string from a file. I thought that I had it right, but the encryption appears in cout as a jumble of random characters. I had it as a cout statement so that I can test to see if it works correctly. I want it to shift to other letters. So when the string is imported, the program asks the user what shift number they want to use and then shifts the letters that value on their ASCII value. I do not know why it is not working correctly. Can anyone tell me what I'm doing wrong? Thanks so much for your help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

string linelength;

void openfile()
{
	ifstream inputfile;
	string inputfilename;
	cout<< "What file can I encrypt?";
	getline(cin, inputfilename);
	int length;
		char*buffer;
		inputfile.open(inputfilename.c_str(), ios::binary);

		inputfile.seekg(0, ios::end);
		length=inputfile.tellg();
		inputfile.seekg(0,ios::beg);

		buffer=new char [length];

		inputfile.read(buffer,length);

		inputfile.close();
		cout.write(buffer,length);
		delete[] buffer;

		string outputfilename;
		cout <<"What shall I name the encrypted file?";
		getline(cin, outputfilename);
		ofstream ciphertext(outputfilename.c_str());

		cout<< "What shift will I use?";
		int shiftvalue;
		shiftvalue=0;
		cin>>shiftvalue;

		
		
		
		int *asciivalue;
		char *cipherline;

		asciivalue=new int[linelength.length()];
		cipherline=new char[linelength.length()];

		int i;
		for(i=0; i<linelength.length()-1; i++){
			asciivalue[i]+=shiftvalue;
			cipherline[i]=(char)asciivalue[i];
			cout<<cipherline[i];
		}
		delete cipherline;
		delete asciivalue;
		cout<<endl;
		system("pause");	
}




int main()
{
	openfile();
	return 0;
}
Topic archived. No new replies allowed.