A some what complex problem

Before I ask questions I understand, that it is important to give some information and background before I do so, on issue related to programing. For quite some time I have been looking around for a way to strings using AES or rijndael. I had done a bit of looking around and my efforts where largely fruitless. One problem lead to another and I had to look around for code that would actually compile. After asking questions and getting no response, combined with looking around the web I did hit gold. I found a library of sorts that would work to encrypt data under AES. It compiled and worked pretty well for files it was slow but usable.
I however wanted to encrypt strings which was my original goal. I tried for some time to replicate the function of this bit of code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
	string keyStr = "abcdefghijklmnop";  
	byte key[16];   
	charToByte(key, keyStr.c_str());  
	// ÃÜÔ¿À©Õ¹  
	word w[4*(Nr+1)];  
	KeyExpansion(key, w);  

	bitset<128> data;  
	byte plain[16];  
	// ½«Îļþ flower.jpg ¼ÓÃܵ½ cipher.txt ÖÐ  
	ifstream in;  
	ofstream out;  
	in.open("N://flower.jpg", ios::binary);  
	out.open("N://cipher.txt", ios::binary);  
	while(in.read((char*)&data, sizeof(data)))  
	{  
		divideByte(plain, data);  
		encrypt(plain, w);  
		data = mergeByte(plain);  
		out.write((char*)&data, sizeof(data));  
		data.reset();  // ÖÃ0  
	}  
	in.close();  
	out.close();  

I tried to edit it to encrypt strings rather than files. I made use of the memcpy function however my efforts where fruitless. One problem lead to another and I quickly understood I was in a bit over my head.
I tried to make it work and tried to work around the issues but result remained the same. I might be a bad programer but, a lot of you here are little bit better than bad. So do you have advice or a fix to this problem.
http://pastebin.com/nbEV6zkG
I tried several times and I tried different approaches but none worked.
http://pastebin.com/nbEV6zkG
http://pastebin.com/Mjnvg1Eb
https://github.com/SongLee24/Aes_and_Des

Edit/Delete Message
Last edited on
I suggest using the Crypto++ library:

http://www.cryptopp.com/

lines 15/20 are wrong. You overwrite members of the bitset rather than it's internal data (the 128 bits). sizeof also returns the wrong value. Use a byte array instead.
I would agree with that but how could you compile it under VS2012 or codeblocks.
I should also say in addition Crypto++ does not compile.
Last edited on
Topic archived. No new replies allowed.