[ create a new paste ] login | about

Link: http://codepad.org/tfnFYnHJ    [ raw code | output | fork ]

C++, pasted on Oct 21:
#include <cmath>
#include <string>
#include <cstdlib>
#include <fstream>

using namespace std;

void decrypt(ifstream & infile, ofstream & outfile);

int main()
{
	int numtype, n;
	string filetype, filename, add_on, decrypt_add_on;
	
	ifstream infile;
	ifstream infile2;
	ofstream outfile;
	infile.open("batch_list.txt");
	

	infile >> filetype >> numtype;

	

	while (!infile.fail())
	{
            n=0;
		while (!infile.fail() and n<1) 
		{
			switch(numtype)
			{
				case 10:
					add_on = "_9.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_9_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);			
					infile2.close();
					outfile.close();
				case 9:
					add_on = "_8.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_8_decrypted.txt";
					infile2.open(filetype.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 8:
					add_on = "_7.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_7_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 7: 
					add_on = "_6.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_6_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 6:
					add_on = "_5.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_5_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 5:
					add_on = "_4.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_4_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 4:
					add_on = "_3.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_3_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);				
					infile2.close();
					outfile.close();
				case 3:
					add_on = "_2.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_2_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 2:
					add_on = "_1.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_1_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();
				case 1:
					add_on = "_0.txt";
					filename = filetype + add_on;
					decrypt_add_on = "_0_decrypted.txt";
					infile2.open(filename.c_str());
					filename = filetype + decrypt_add_on;
					outfile.open(filename.c_str());
					decrypt(infile2, outfile);
					infile2.close();
					outfile.close();

					
			}
				n++;
				
		}
			infile >> filetype >> numtype;
	}
}


void decrypt(ifstream & infile, ofstream & outfile)
{
	int n=0;
	char decryptchar;
	bool failed = false;
	string decryptcode, message, reversestring;
	getline( infile, decryptcode);

	while (!infile.fail())
	{
		getline( infile, message);
		n=0;
		while (n < decryptcode.size())
		{
			decryptchar = decryptcode.at(n);
			switch(decryptchar)
			{
				case 'r': 
				{
					int w;
					w = message.size();
				
					while(w>=1)
					{
						reversestring += message.at(w-1);
			
						w--;

						message = reversestring;
					}
					break;
				}
				case 'x': 
				{
					char removechar;
					removechar = decryptcode.at(n+1);
				
					while(message.find(removechar) != message.npos)
					{
		
						message.erase(message.find(removechar), 1);
					}
					
					n++;
					break;
				}
				case '#':
				{
					char q;
					string newstring;
					int shiftnum;
					int counter=0;
					shiftnum = decryptcode.at(n+1);

					while (counter < message.size())
					{
						q = message.at(counter);
						q = q-shiftnum;
						newstring += q;
						counter++;	
					}	
					message = newstring;
					n++;
					break;
				}
				case 'y':
				{
					char replacechar, replacewithchar;
					replacechar = decryptcode.at(n+1);
					replacewithchar = decryptcode.at(n+2);
					while (message.find(replacechar) != message.npos)
					{
	
					message.replace(message.find(replacechar), 1, 1, replacewithchar);

					}
					n+=2;
					break;
				}
				case 'i':
				{
					int loc;
					char insertchar;
					insertchar = decryptcode.at(n+1);
					loc = decryptcode.at(n+2);
					message.insert(loc, 1, insertchar);
					n+=2;
					break;
				}
				
				default:
				{
					failed = true;
				}
			}
			
			n++;
		}

		if(failed=false)
		{
		outfile << message << endl;
		}
			n=0;
	}

return;





}


Output:
1
2
3
4
cc1plus: warnings being treated as errors
In function 'void decrypt(std::ifstream&, std::ofstream&)':
Line 155: warning: comparison between signed and unsigned integer expressions
Line 197: warning: comparison between signed and unsigned integer expressions


Create a new paste based on this one


Comments: