Click here to Skip to main content
15,887,746 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC SP5 PSDK FEb2003 Pin
David Crow9-Jan-04 5:38
David Crow9-Jan-04 5:38 
GeneralRe: VC SP5 PSDK FEb2003 Pin
pranavamhari9-Jan-04 16:23
pranavamhari9-Jan-04 16:23 
GeneralRe: VC SP5 PSDK FEb2003 Pin
Michael Dunn9-Jan-04 17:17
sitebuilderMichael Dunn9-Jan-04 17:17 
GeneralReading a .csv file Pin
mr20039-Jan-04 4:06
mr20039-Jan-04 4:06 
GeneralRe: Reading a .csv file Pin
David Crow9-Jan-04 5:32
David Crow9-Jan-04 5:32 
GeneralRe: Reading a .csv file Pin
mr20039-Jan-04 5:56
mr20039-Jan-04 5:56 
GeneralRe: Reading a .csv file Pin
David Crow9-Jan-04 6:06
David Crow9-Jan-04 6:06 
GeneralEncryption Pin
HackerBoy9-Jan-04 4:05
HackerBoy9-Jan-04 4:05 
Can anyone tell me why this program is not working? I wrote this program the other day and I keep getting error messages.

Here is the program:
/*
XOR.cpp
Brandon Quick
brandon@omlit.om.org
Proper usage is XOR.exe filename Key
Encrypt the file with a key 324
XOR.exe plain.txt 324
Decrypt that file
XOR.exe plain.enc 324
Encrypt a file
XOR.exe keepsafe.txt 56765
Decrypt that file
XOR.exe keepsafe.end 56765
*/
#include <iostream.h>
#include <string.h>
#include <stdio.h>

float atol;

int XOR(char * filename, unsigned long key);
int main(int argv, char ** argc)
{
unsigned long key;
char filename[100];
//if they used command line arguments pass the filename and key to xor function
if( argv == 3)
{
if( XOR(argc[1],(unsigned int)atol(argc[2]) ) )
{
cout << "There was an error trying to encrypt/decrypt the file " << argc[1] << endl;
}
}
//other wise prompt for the key and filename
else
{
cout << "What is the filename?" << endl;
cin.getline(filename,99,'\n');

cout << "What is the key?" << endl;
cin >> key;

//tell the user about command line then call xor function
cout << "Next time you can use the command line, the format is " << argc[0] << " filename key" << endl;
if( XOR(filename,key) )
{
cout << "There was an error trying encrypt/decrpyt the file " << filename << endl;
}
}
return 0;
}
int XOR(char * filename, unsigned long key)
{
FILE * input = NULL , *output = NULL;
char * outfilename = NULL;
int len = strlen(filename);
unsigned char buffer;
if( (filename[len-4] == '.') && (filename[len-3] == 'e') && (filename[len-2] == 'n') && (filename[len-1] == 'c') )
{
// our input file is encoded then we will create a file without the .end extension
outfilename = new char[len+1]; //make room for the name+\0
strcpy(outfilename,filename); //copy the string name
outfilename[len-4] = '\0'; //put the \0 before the .enc extension to cut it off
}
else
{
outfilename = new char[len+5]; //make room for the name + .enc + \0
strcpy(outfilename,filename); //copy the file name
strncat(outfilename,".enc",4); //add the .enc extension
}
input = fopen(filename,"rb");
if( input == NULL)
{
cout << "Error opening file " << filename << endl;
delete [] outfilename; //free the memory before leaving
outfilename = NULL;
return 1;
}

output = fopen(outfilename,"wb");
if( output == NULL )
{
cout << "Error creating output file " << outfilename << endl;
delete [] outfilename; //free the mem before leaving
outfilename = NULL;
return 1;
}
while( ! feof(input) )
{
//get some data
if( fread(&buffer,sizeof(unsigned char),1,input) != 1 )
{
//if we didnt get any data, but we are not at the eof, then an error has occured
if( ! feof(input) )
{
delete [] outfilename;
outfilename = NULL;
fclose(input);
fclose(output);

return 1;
}
}
else
{
//xor that data
buffer ^= key;

//write some data
fwrite(&buffer,sizeof(unsigned char),1,output);
}
}
//close the files and free that memory
fclose(input);
fclose(output);
delete [] outfilename;
return 0;
}
GeneralRe: Encryption Pin
David Crow9-Jan-04 5:25
David Crow9-Jan-04 5:25 
GeneralAlphaBlend Pin
Anthony98879-Jan-04 3:46
Anthony98879-Jan-04 3:46 
GeneralRe: AlphaBlend Pin
John R. Shaw9-Jan-04 3:56
John R. Shaw9-Jan-04 3:56 
QuestionHow to change from WORD to CString Pin
mr20039-Jan-04 3:40
mr20039-Jan-04 3:40 
AnswerRe: How to change from WORD to CString Pin
John R. Shaw9-Jan-04 3:53
John R. Shaw9-Jan-04 3:53 
AnswerRe: How to change from WORD to CString Pin
Dominik Reichl9-Jan-04 3:55
Dominik Reichl9-Jan-04 3:55 
AnswerRe: How to change from WORD to CString Pin
Ted Ferenc9-Jan-04 4:20
Ted Ferenc9-Jan-04 4:20 
AnswerRe: How to change from WORD to CString Pin
John M. Drescher9-Jan-04 4:49
John M. Drescher9-Jan-04 4:49 
GeneralVery strange bug with VS6 SP5 Pin
Jerome Conus9-Jan-04 2:40
Jerome Conus9-Jan-04 2:40 
GeneralRe: Very strange bug with VS6 SP5 Pin
David Crow9-Jan-04 3:24
David Crow9-Jan-04 3:24 
GeneralRe: Very strange bug with VS6 SP5 Pin
Jerome Conus9-Jan-04 3:29
Jerome Conus9-Jan-04 3:29 
GeneralRe: Very strange bug with VS6 SP5 Pin
Ted Ferenc9-Jan-04 4:34
Ted Ferenc9-Jan-04 4:34 
GeneralRe: Very strange bug with VS6 SP5 Pin
Michael Dunn9-Jan-04 17:25
sitebuilderMichael Dunn9-Jan-04 17:25 
GeneralMS Word and VC++ Pin
Duncan Wells9-Jan-04 2:24
Duncan Wells9-Jan-04 2:24 
GeneralRe: MS Word and VC++ Pin
Animesh Rawal9-Jan-04 2:47
Animesh Rawal9-Jan-04 2:47 
GeneralRe: MS Word and VC++ [edited] Pin
Michael P Butler9-Jan-04 3:06
Michael P Butler9-Jan-04 3:06 
GeneralRe: MS Word and VC++ [edited] Pin
Duncan Wells9-Jan-04 3:41
Duncan Wells9-Jan-04 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.