codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  File encryption help  Phoenix at 21:31 on Tuesday, June 20, 2006
 

Hey. I recently created a simple file encryption program that opens a file, reads the contents, encrypts the contents using a simple XOR process, and rewrites the file. Ive posted the source code below with a changed encryption key as reference.

I have encountered two problems. The program will not allow me to assign a value contained in a variable to a character array, so the line (char string[50] = line;) becomes invalid. I have not been able to figure a way around this problem as yet. I have created classes, tried using different types of arrays, and some other stuff, with no success, so I modifyed the source code to allow for manual encryption. Was wondering if anyone could help me figure a way to assign the value containted in (string line) to (char string[50]) and still have a working encryption? There is probably a really basic solution to this problem that i just keep overlooking.

My second problem is that I just haven't been able to figure out a way to count ONLY the number of spaces in a text file, because this algorithm does not encrypt spaces. lol need help with that too.


#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
long begin, end;
string line;
ifstream myfile ("/forum/file.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";

myfile.open ("/forum/file.txt");
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();

char string[50];
char key[129] = "ZaQ12wSXCde34RFVBGt56YHNMJu78IkLO9oP09OlKI87UjMNHY65tGbVFR43edCXSW21QAZAQ12WSXCDE34RFvbGT56YhNmJU78IKLO90P09OLKI87UJMNhY65TGBVFr";
ofstream newfile ("/forum/file.txt");
if (newfile.is_open())
{
for (int x=0; x<((end-begin)-5); x++)
{
cin >> string[50];
string[x]=string[50]^key[129];
cout << string[x];
newfile << string[x];
}
newfile.close();
}
cout << endl << "\nFile encrypted" << endl;
system("PAUSE");
return EXIT_SUCCESS;
}








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: User input. Command line application.
•  email in bulk
•  problem displaying
•  Re: dynamic crystal report generation
•  reading text files line by line
•  Re: crystal report in windows C#.NET
•  is null or not an object error
•  Need to control remote machine
•  Re: convert minutes into hours and minutes


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006