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:
  need help!!!  newProgrammer19 at 07:51 on Thursday, December 14, 2006
 

i no next to nothing about decrpytion and encryption, so i need help following these guidelines.

Implement the class Crypto
Implement three (3) encryption/decryption functions
Implement a program that lets a user encrypt/decrypt text using your Crypto class functions
Your program must allow the user to continue encrypting/decrypting text until he/she chooses to quit
Your program must allow the user to choose any of the encryption functions you implemented in the class Crypto.
Allow the user to enter a line of plain text, and encrypt it--show the user the encrypted text AND the original clear text
Allow the user to enter a line of encrypted text, and decrypt it-- show the user the clear text that results from decryption AND the original encrypted text
Display must be well formatted
Keep the user interface as clean, logical, and simple as possible

here is the .cpp crypto file

#include "Crypto.h"


/* constructors */
Crypto::Crypto ()
{
clearText = "START CLEAR";
cipherText = "START CIPHER #$%#";
key = -1;
}

Crypto::Crypto (string ct, int k)
{
clearText = ct;
key = k;
cipherText = "START CIPHER $##^%$^#";
}

/* function definitions go in here */

string Crypto::shiftEncrypt (string tClear, int k)
{
string encrypted = "XLKJ LJOUY JLLHGKHL";

return encrypted;
}

string Crypto::shiftDecrypt (string tCipher, int k)
{
string decrypted = "NOT YET IMPLEMENTED";

return decrypted;
}

string Crypto::getClearText ()
{
return clearText;
}

string Crypto::getCipherText ()
{
return cipherText;
}

int Crypto::getKey ()
{
return key;
}

void Crypto::setClearText (string ct)
{
clearText = ct;
}

void Crypto::setCipherText (string ct)
{
cipherText = ct;
}

void Crypto::setKey (int k)
{
key = k;
}


here is the header file

#include <string>

using namespace std;

/* Crypto: a class that performs simple crypto routines */
/*****************
* character mapping:
* a b c d e f g ...
* 1 2 3 4 5 6 7 ...
*****************/

class Crypto
{
/* function headers go in public */
public:

/* constructors */
Crypto ();
Crypto (string ct, int k);

string shiftEncrypt (string tClear, int k);
string shiftDecrypt (string tCipher, int k);

/* accessor functions */
string getClearText ();
string getCipherText ();
int getKey ();

/* mutator functions */
void setClearText (string ct);
void setCipherText (string ct);
void setKey (int k);

/* data goes in private */
private:
string clearText;
string cipherText;
int key;
};

here is what i have


#include <iostream>
#include "Crypto.h"

using namespace std; //introduces namespace std

int main ( void )
{
cout << "Crypto2--just a test\n";

// create a Crypto variable
Crypto* c2;

c2 = new Crypto; // THIS IS THE CALL TO THE FUNCTION/CONSTRUCTOR Crypto::Crypto()
cout << "clear text: " << c2->getClearText() << endl;
cout << "cipher text: " << c2->getCipherText() << endl;
cout << "key: " << c2->getKey() << endl;

// use Crypto functions
c2->setClearText("hello");
c2->setCipherText("#$%@#");
c2->setKey(25);

// create another Crypto variable
Crypto* c3;
c3 = new Crypto("this is bt's cleartext", 57);
cout << "clear text: " << c3->getClearText() << endl;
cout << "cipher text: " << c3->getCipherText() << endl;
cout << "key: " << c3->getKey() << endl;

return 0;
}
someone please help soon!!!


  Re: need help!!!  Gord T at 19:54 on Thursday, December 14, 2006
 

Where do you need help?
I am also sending a PM with a link that may help.
What time frame (date) do you need this done. Assume it's a school/work proj?

<Added>

I would begin by setting up some dummy functions in main() to handle specific tasks. The code to be added later. Break down the qustions first into functions...let me try real fast...

Implement the class Crypto
- just declare like
Crypto MyCrypto;

Implement three (3) encryption/decryption functions
-Make three dummy funcs for now...
string Crypt_1(string line_of_text);
string Crypt_2(string line_of_text);
string Crypt_3(string line_of_text);
...These functions should accept a string that contains text to encrypt.
...It then returns a encrypted string.

Implement a program that lets a user encrypt/decrypt text using your Crypto class functions
-That is what we are doing...

Your program must allow the user to continue encrypting/decrypting text until he/she chooses to quit
-User Interface routines (herin called UIR)

Your program must allow the user to choose any of the encryption functions you implemented in the class Crypto.
-UIR

Allow the user to enter a line of plain text, and encrypt it--show the user the encrypted text AND the original clear text
-promt user to enter text,
-Call one of Crypt_1(),_2 or _3 functions.

Allow the user to enter a line of encrypted text, and decrypt it-- show the user the clear text that results from decryption AND the original encrypted text
-Make Three funcs like the Crypt_1() ???Is Decrypt the right word??:)
string Decrypt_1(string text);
string Decrypt_2(string text);
string Decrypt_3(string text);


Display must be well formatted
Keep the user interface as clean, logical, and simple as possible


<Added>

I would begin by setting up some dummy functions in main() to handle specific tasks. The code to be added later. Break down the qustions first into functions...let me try real fast...

Implement the class Crypto
- just declare like
Crypto MyCrypto;

Implement three (3) encryption/decryption functions
-Make three dummy funcs for now...
string Crypt_1(string line_of_text);
string Crypt_2(string line_of_text);
string Crypt_3(string line_of_text);
...These functions should accept a string that contains text to encrypt.
...It then returns a encrypted string.

Implement a program that lets a user encrypt/decrypt text using your Crypto class functions
-That is what we are doing...

Your program must allow the user to continue encrypting/decrypting text until he/she chooses to quit
-User Interface routines (herin called UIR)

Your program must allow the user to choose any of the encryption functions you implemented in the class Crypto.
-UIR

Allow the user to enter a line of plain text, and encrypt it--show the user the encrypted text AND the original clear text
-promt user to enter text,
-Call one of Crypt_1(),_2 or _3 functions.

Allow the user to enter a line of encrypted text, and decrypt it-- show the user the clear text that results from decryption AND the original encrypted text
-Make Three funcs like the Crypt_1() ???Is Decrypt the right word??:)
string Decrypt_1(string text);
string Decrypt_2(string text);
string Decrypt_3(string text);


Display must be well formatted
Keep the user interface as clean, logical, and simple as possible


<Added>

I accidentally hit enter or something there. Anyways, Set up your main() with functions like above so that it seems to make logical sense. Add some couts between funcs if U need. Document what the functions are supposed to do...like
//
// Encrypt_1()
// Accpets one line of text and encrypts it using excryption method 1
// Return: The encrted string
//
string Encrypt_1(string text_to_encrypt)
{
//TODO:
Add the encryption code here.

}


Once your program is set close to where it should work, if the functions do what they are supposed to do, then you fill the in the function body's with code.

The actual encryption code part will NOT be difficult.
The main thing first IS the interface and logic flow.
That would be my choice of where to start but I stress 'MY'.
I'll probably check back in later tonight but I'm not going to be in good shape lol so if I do comment and sound silly, please blame the Dutch for their great distillers.



<Added>

One more...for starters U can look at my post "Looking to code something" in the c++ forum. In there I wrote a very VERY basic decrypter/decrypter to kill some time.

You will also find lots of help/links with the info I PM'd U.


<Added>

My typing is NOT that bad,parsing here is a issue to be sure.

<Added>

Okay, maybe, Beer-Biere-Alus-Piwo-N+(backwards N)BO = typos.

  Re: need help!!!  newProgrammer19 at 20:55 on Thursday, December 14, 2006
 

sweet but ya i am so lost, and i wont lie to you it is a school project. i will use the dummy functions but i am no good at this so it probally wont help. i just dont understand everything, i go to class, i study, and do research. just please lets get this done, it is my last project do sometime tomorrow.

  Re: need help!!!  Gord T at 21:13 on Thursday, December 14, 2006
 

Did U get my PM?


<Added>

Tell ya what, U come up with 3 encrypting funcs and I'll see If I can come up with the UI. But dude, the dutch are on thier way :)

  Re: need help!!!  Gord T at 21:30 on Thursday, December 14, 2006
 

setCipherText()
Is this the string U want to encrypt? e.g "Encrypt this text"

<Added>

Can I suggest something else? I don't think U need 3 instances of Crypto since you can only encrypt/decrypt 1 at a time. Therefore I would use a user-loop with 1 instance of Crypto and send it to whichever encryption method is requested. You do not need a pointer this way.
...wait for reply....

  Re: need help!!!  Gord T at 22:33 on Thursday, December 14, 2006
 

I've made a few minor changes, mostly in the naming of functions. Here's what I have so far...

////////////////////////////////////////
//
// Crypto.cpp
//
#include "stdafx.h"
#include "Crypto.h"
#include <iostream>

/* constructors */
Crypto::Crypto ()
{
standardText = "";
encodedText = "";
key = -1;
}

Crypto::Crypto (string ct, int k)
{
standardText = ct;
key = k;
encodedText = "TODO:encryption code here";
}

/* function definitions go in here */

string Crypto::shiftEncrypt (string tClear, int k)
{
string encrypted = "XLKJLJOUYJLLHGKHL";//NO SPACES PLEEEEZ

return encrypted;
}

string Crypto::shiftDecrypt (string tCipher, int k)
{
string decrypted = "NOT YET IMPLEMENTED";

return decrypted;
}

string Crypto::getStandardText ()
{
return standardText;
}

string Crypto::getCipheredText ()
{
return encodedText;
}


void Crypto::setStandardText (string ct)
{
standardText = ct;
}

void Crypto::encodeText (string ct)
{
encodedText = ct;
}

string Crypto::encrypt_text_1 ()
{
//TODO: Add code here
// Encryption method 1
cout << endl << "encryption method 1 selected." << endl << endl;
return "encrypt_text_1 under construction.";
}
string Crypto::encrypt_text_2 ()
{
//TODO: Add code here
// Encryption method 2
cout << endl << "encryption method 2 selected." << endl << endl;
return "encrypt_text_2 under construction.";
}
string Crypto::encrypt_text_3 ()
{
//TODO: Add code here
// Encryption method 3
cout << endl << "encryption method 3 selected." << endl << endl;
return "encrypt_text_3 under construction.";
}

/////////////end Crypto.cpp ///////////////////////

///////////////////////////////////////////////////
//
// Crypto.h
//
#pragma once
#include <string>

using namespace std;

/* Crypto: a class that performs simple crypto routines */
/*****************
* character mapping:
* a b c d e f g ...
* 1 2 3 4 5 6 7 ...
*****************/

class Crypto
{
/* function headers go in public */
public:

/* constructors */
Crypto ();
Crypto (string ct, int k);

string shiftEncrypt (string tClear, int k);
string shiftDecrypt (string tCipher, int k);

/* accessor functions */
string encrypt_text_1 ();
string encrypt_text_2 ();
string encrypt_text_3 ();
string getStandardText();
string getCipheredText ();
//int getKey ();////that was not specified in outline. Used any method.

/* mutator functions */
void setStandardText (string ct);
void encodeText (string ct);
//void setKey (int k); //that was not specified in outline. Used any method.

/* data goes in private */
private:
string standardText;
string encodedText;
int key;
};


//////////////////// end Crypto.h ////////////////


///////////////////////////////////////////////////
//
// Encrypt.cpp (no headers)
//

#include <iostream>
#include <conio.h> //getch()

#include "Crypto.h"

using namespace std; //introduces namespace std

void main ()
{

string strUser;// create a Crypto variable
Crypto c;
char ch_encryption_method;// 1, 2, or 3.
//char ch;
//TODO: Add program introduction here
do
{

system("cls");//clear screen from old data...

/* promt user for text to encrypt */
cout << "Enter text to encrypt." <<endl;
cin >> strUser;
cout << endl;//white space

c.setStandardText(strUser);//make it so.

/* Get method of encryption user wants.
*/
while(1)
{
cout << "Choose which method to encrypt. [1][2][3]" << endl;
ch_encryption_method = _getch();
if(ch_encryption_method != '1' || ch_encryption_method!='2' || ch_encryption_method != '3')break;
}

switch(ch_encryption_method)
{
case '1':c.encrypt_text_1(); break;
case '2':c.encrypt_text_2(); break;
case '3':c.encrypt_text_3(); break;
default:
cout << "switch(ch_encryption_method): unknown method." << endl;
system("pause");
return;

}//sw


cout << "standard text: " << c.getStandardText() << endl;
cout << "ciphered text: " << c.getCipheredText() << endl;



cout << "Press ESC to quit." << endl;
}while(_getch() != 27);//loop until user presses ESC
//system("pause");

}

////////////////// end Encrypt //////////////////



<Added>

Here we go again: Major modify. Dude, my code is updating so fast...

ERROR:
if(ch_encryption_method != '1' || ch_encryption_method!='2' || ch_encryption_method != '3')break;

to...
if(ch_encryption_method == '1' || ch_encryption_method=='2' || ch_encryption_method == '3')break;


This was old code from last compile, again, I WISH I COULD EDIT MY OWN CODE.




  Re: need help!!!  Gord T at 22:49 on Thursday, December 14, 2006
 

All U need to do now is put in the code for each...
encrypt_text_1
encrypt_text_2
encrypt_text_3
to encrypt/decrypt the standard text.
Hope I've been a help.

  Re: need help!!!  newProgrammer19 at 07:10 on Saturday, December 16, 2006
 

did you make changes to the header file and also the cpp? and give me an example of what the code looks like that i need to fill in. oh ya me and my teacher got into it cuz he said my brother was a sellout cuz he likes microsoft and visual studios... get back to me asap so i can get this turned in

  Re: need help!!!  Gord T at 03:25 on Sunday, December 17, 2006
 

I'm probably too late dude, I thought it was due yesterday. Anyways, today is Saturady about 12midnight so if U still need help, I can help all day Sunday so I'll check in noon E.S.T.

P.S. Your teacher could lose his/her job for saying crap like that. ("gosh, if I just had a copy of that....dude")

I did make changes to the .cpp and .h files only in changing the names of a couple of functions, only because I don't like to think. You did not provide documentation for the functions so I had to figure out what they were supposed to do. (sucks) So I changed a few names. I deleted a couple. Else, it's still all your code.

I'll check in tomorrow.


  Re: need help!!!  Gord T at 03:27 on Sunday, December 17, 2006
 

I'm probably too late dude, I thought it was due yesterday. Anyways, today is Saturady about 12midnight so if U still need help, I can help all day Sunday so I'll check in noon E.S.T.

P.S. Your teacher could lose his/her job for saying crap like that. ("gosh, if I just had a copy of that....dude")

I did make changes to the .cpp and .h files only in changing the names of a couple of functions, only because I don't like to think. You did not provide documentation for the functions so I had to figure out what they were supposed to do. (sucks) So I changed a few names. I deleted a couple. Else, it's still all your code.

I'll check in tomorrow.


<Added>

LAGG...








CodeToad Experts

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








Recent Forum Threads
•  Re: Multithreading question
•  Re: This forum sucks.
•  Re: Appending to a file
•  Re: Problems with mkdir
•  Re: help writing comparison CGI
•  Re: hello! i have a problem
•  Re: Help please.
•  Want Help from anyone!
•  Want Help from anyone!


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2006