Reading and writing encrypted data to file

Hi. I'm writing a program that will encipher a file using XTEA algorithm.
I made the algorithm functions to work:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void encipher(long *v, long *k)
{
	long v0 = v[0], v1 = v[1];
	long sum = 0;	
	long  delta = 0x9e3779b9;
	short rounds = 32;
	for(uint32 i = 0; i<rounds; i++)
	{
		v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]);
      sum += delta;
        v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum>>11) & 3]);
	}
	v[0] = v0;
	v[1] = v1;
}

But the problem is I don't know how to read a file, encipher it and save it as a new file. I have tried many methods, one of them:
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
	if(argc > 1)
	{
		ifstream fin(originalpath, ios::binary);
		ofstream eout(encryptedpath);
		ofstream dout(decryptedpath);

		while(!fin.eof())
		{
			// clear memory from buffers
			memset(&data[0], 0, sizeof(long));
			memset(&data[1], 0, sizeof(long));
			
			fin.readsome(ReadBuffer, 4);
			data[0] = *ReadBuffer;			
			fin.readsome(ReadBuffer, 4);
			data[1] = *ReadBuffer;
			

		encipher(data, key);
		*ReadBuffer = data[0];
		eout << ReadBuffer;
		

		*ReadBuffer = data[1];
		eout << ReadBuffer;
		
                 //.........
                 

		decipher(data, key);
		*ReadBuffer = data[0];
		dout << ReadBuffer;
		
		*ReadBuffer = data[1];
		dout << ReadBuffer;
		

Why does this not encipher my file? Why doesn't it read at all? Is there something wrong with my types?

I hope you can help me
- Jan
Topic archived. No new replies allowed.