CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Oct 2007
    Posts
    13

    encryption code please help

    Hey guys I need some help again. I need to create a program that will open a file and create a second file. The second file should be encrypted by reading the file by reading each character and adding 10 to the ASCII code. Here is what I have so far the thing I can't figure out is how to add 10 to the ASCII code. please help. The book says something about reinterpret cast but I'm not sure how to use it and if that is right. Thank for any help.

    Code:
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main()
    {
    	const int SIZE = 51;
    	char fileName[SIZE];
    	fstream dataFile, outPut, inFile;
    
    	ofstream outFile(outPut);
    
    	cout << "This program encrypts a text file by addind 10 to the\n";
    	cout << "ASCII code of each character in the file, then writes\n";
    	cout << "a new text file.\n";
    	cout << "Enter the input file name: " << fileName << endl;
    	cin >> fileName;
    	cout << "Enter the output file name: " << outPut << endl;
    	cin >> outPut;
    
    	dataFile.open(fileName);
    	if (fileName)
    	{
    		return 0;
    	}
    	dataFile.write (reinterpret_cast<char *>(ASCII+10), sizeof(ASCII+10));
    
    	cout << "The file has been encrypted." << endl;
    
    	dataFile.close();
    	return 0;
    }
    Last edited by cyke1; December 3rd, 2007 at 06:05 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured