heh I know, it was kind of a joke. I really know nothing about encryption. :)Quote:
Originally Posted by ILoveVectors
Printable View
heh I know, it was kind of a joke. I really know nothing about encryption. :)Quote:
Originally Posted by ILoveVectors
maybe you could use this oppurtunity to come up with something :)
This code (and the equivalent decrypting bit) seem a bit suspect. Surely it only actually applies the third of the 3 key characters you are meaning to apply. Shouldn't it be more like:-Quote:
Originally Posted by ILoveVectors
I could be completely wrong...Code:changed1 = letter;
for(int j = 0; j != 3; j++,i++)//applys 3 character of the key to character read in
{
changed1 -= mykey[i];//subtract mykey[i] thru mykey[i+3] from original letter
}
Pete
that is a good catch i spent more time putting
in stuff to protect the user instead of actually
checking what i did, i suppose since it encrypted
and decrypted correctly i didnt put to much thought into it.
its ok though i added it to my fix list, i was gonna make some changes so i can encrypted the file to the same file,
and possibly use several keys. i still got
some time before the contest is over anyways.
Fkulvwldqv 0 Nlwwbc 4 !!!!
OK my final entry, i never got around to doing everything
i wanted to cause i was busy, but oh well
Code:#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
string mykey;
string infile;
string outfile;
int choice;
cout << "1. Encrypt" << endl;
cout << "2. Decrypt" << endl;
cout << "Your Choice : ";
cin >> choice;
cin.ignore();
if(!cin)//Checks for bad input
{
cout << "I tried to figure out what you wanted" << endl;
cout << "but your want eludes me." << endl;
cout << "Program has been terminated!" << endl;
return 1;
}
if(choice == 1)//Load encrypt Section
{
cout << "Enter your key (Must be at least 8 characters): ";
getline(cin, mykey, '\n');
cout << "Location of file to encrypt, Ex \"c:/myfile.txt\" : ";
getline(cin, infile, '\n');
cout << "Location to save encrypted file, Ex \"c:/myoutfile.txt\" : ";
getline(cin, outfile, '\n');
int keysize = mykey.size();
if(keysize <= 7)
{
mykey.clear();
cout << endl << endl;
cout << "Your key was to short, here is a chance to fix that." << endl;
cout << "Enter a Key : ";
getline(cin, mykey, '\n');
keysize = mykey.size();
if(keysize <= 7)
{
cout << endl << endl;
cout << "You have failed to comply, encryption terminated!" << endl;
cin.get();
return 4;
}
}
if(infile.empty())
{
cout << endl << endl;
cout << "How can i encrypt this file \"" << infile << "\" if it does not exsist?" << endl;
cin.get();
return 5;
}
if(outfile.empty())
{
cout << endl << endl;
cout << "How can i save to this file \"" << outfile << "\" if you dont specify one?" << endl; cin.get();
return 5;
}
if(infile == outfile)
{
outfile+=".enc";
}
ifstream in(infile.c_str(), ios::binary);
if(in.fail())//Makes sure both file have been opened before continuing
{
cout << endl << endl;
cout << "I couldnt locate your file, I am sorry." << endl;
cout << "The error is related to this entry : ";
cout << infile << endl;
cin.get();
return 2;
}
ofstream out(outfile.c_str(), ios::binary);
if(out.fail())
{
cout << endl << endl;
cout << "I was unable to create a output file, I am sorry." << endl;
cout << "The error is related to this entry : ";
cout << outfile << endl;
cin.get();
return 2;
}
int i = 0;
int q = 0;
char letter;
char changed1;
char junkletter;
while( in.read( (char*)&letter, sizeof(letter) ))//read one character till end of the file
{
changed1 = letter;
q++;
if((i+3) > keysize)//make sure we wont be overstepping the bound of our keysize
{
i = 0;
}
changed1 -= mykey[i];
i++;
changed1 += mykey[i];
i++;
changed1 -= mykey[i];
i++;
out.write( (char*)&changed1, sizeof(changed1) );//output the character to the new file
if(q == mykey[i])//if q is equal to a character in the key, it time to put a junk character
{
q = 0;
junkletter = (changed1+mykey[i+2]);//create the junk character
out.write( (char*)&changed1, sizeof(changed1) );//out put the junk character
}
}
in.close();
out.close();
}
else //Load Decrypt Section
{
cout << "Enter your key : ";
getline(cin, mykey, '\n');
cout << "Location of the encrypted file, Ex \"c:/myfile.txt\" : ";
getline(cin, infile, '\n');
cout << "Location to save decrypted file, Ex \"c:/myoutfile.txt\" : ";
getline(cin, outfile, '\n');
int keysize2 = mykey.size();
if(keysize2 <= 7)
{
mykey.clear();
cout << endl << endl;
cout << "Your key was to short, here is a chance to fix that." << endl;
cout << "Enter a Key : ";
getline(cin, mykey, '\n');
keysize2 = mykey.size();
if(keysize2 <= 7)
{
cout << endl << endl;
cout << "You have failed to comply, encryption terminated!" << endl;
cin.get();
return 4;
}
}
if(infile.empty())
{
cout << endl << endl;
cout << "How can i decrypt this file \"" << infile << "\" if it does not exsist?" << endl;
cin.get();
return 5;
}
if(outfile.empty())
{
cout << endl << endl;
cout << "How can i save to this file \"" << outfile << "\" if you dont specify one?" << endl;
cin.get();
return 5;
}
ifstream in2(infile.c_str(), ios::binary);
if(in2.fail())//Makes sure both file have been opened before continuing
{
cout << endl << endl;
cout << "I couldnt locate your file, I am sorry." << endl;
cout << "The error is related to this entry : ";
cout << infile << endl;
cin.get();
return 2;
}
ofstream out2(outfile.c_str(), ios::binary);
if(out2.fail())
{
cout << endl << endl;
cout << "I was unable to create a output file, I am sorry." << endl;
cout << "The error is related to this entry : ";
cout << outfile << endl;
cin.get();
return 2;
}
int i2 = 0;
int q2 = 0;
char letter2;
char shanged1;
while( in2.read( (char*)&letter2, sizeof(letter2) ) )//read one character till end of the file
{
q2++;
shanged1 = letter2;
if((i2+3) > keysize2)//make sure we wont be overstepping the bound of our keysize
{
i2 = 0;
}
shanged1 += mykey[i2];
i2++;
shanged1 -= mykey[i2];
i2++;
shanged1 += mykey[i2];
i2++;
out2.write((char*)&shanged1, sizeof(shanged1));//output the character to the new file
if(q2 == mykey[i2])
{
q2 = 0;
in2.read( (char*)&letter2, sizeof(letter2) );//discard the junk character
}
}
in2.close();
out2.close();
}
cout << "HAHA I have completed your tasks, may I have another!" << endl;
cin.get();
return 0;
}
dealine has passed or is about to depending on your time zone
and what you ment by dealine!!
who is the winner, and what do i get :)
Christians 0 Kittyz 4 !!!!Quote:
Originally Posted by kryptkat
no zip uploads? and 97kb limit?
Code:case IDC_CeazarEncrypt:
for(a=0;a< (textlen +1) ; a++ ) {
if( ( ( buff[a] ) > 96 ) && ( ( buff[a] ) < 123 ) ) {
tempbuff[a] = lowtest( buff[a] , atoi(keybuf) );
}
else if( ( ( buff[a] ) > 64 ) && ( ( buff[a] ) < 91 ) {
tempbuff[a] = hightest( buff[a] , atoi(keybuf) );
}
else
{
tempbuff[a] = buff[a];
}
};
SetDlgItemText(hwnd, IDC_TEXTB, tempbuff ) ;
GlobalFree((HANDLE)buff);
}
break;
--------
case IDC_CeazarDeCrypt:
for(a=0; a < (textlen +1) ; a++ ) {
if( ( ( buff[a] ) > 96 ) && ( ( buff[a] ) < 123 ) ) { tempbuff[a] = delowtest( buff[a] , atoi(keybuf) ); }
else if( ( ( buff[a] ) > 64 ) && ( ( buff[a] ) < 91 ) ) {
tempbuff[a] = dehightest( buff[a] , atoi(keybuf) ); }
else
{
tempbuff[a] = buff[a];
}
};
SetDlgItemText(hwnd, IDC_TEXTB, tempbuff ) ;
GlobalFree((HANDLE)buff);
}
break;
Ill allow late submissions seeing as I only recieved one...
Late submissions are still valid, if there isnt enough space email it to me:
[email protected]
The results will be posted in a week.
Thanks for everyone that participated!
if ne one would like to see meow entry...
http://www.tekcities.com/kitty/index.html
still had logic error 209kb zipped halfmeg unzip
Ok, now that we have more entries it will take longer for testing so please allow me another week.
Thanks,
Josh
Well I'm just about done, sorry it took so long I've been on vacation for a while.
ive been very anxious :), how many submission did you
end up recieving?
Not many, ya sorry ive been really busy so its hard to sit down and look closely at them. I think i have 3 submissions.