String Encryption Challenge Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 15
Reputation: Wolf CCMLG is an unknown quantity at this point 
Solved Threads: 0
Wolf CCMLG Wolf CCMLG is offline Offline
Newbie Poster

String Encryption Challenge Help

 
0
  #1
Sep 20th, 2009
I am having an extremely difficult time with this programming challenge I have to do. I have no idea where to begin on this. I am a beginning programmer (obvious I know), and here are my instructions for the challenge:

"Write a class EncryptableString that is derived from the STL string class. The EncryptableString class adds a member function

void encrypt( )

That encrypts the string contained in the object by replacing each letter with its successor in the ASCII ordering. For example, the string baa would be encrypted to cbb. Assume that all characters that are part of an EncryptableString object are letters a..z and A...Z, and that the successor of z is a and the successor of Z is A. Test your class with a program that asks the user to enter strings that are then encrypted and printed.


If someone can maybe lay these instructions out in a more clear and simplified form so I can possibly comprehend it better. I am quite confused on how this should be done.

This is what tiny little beginning I have, hopefully it's right. I still need a lot of help on laying out where the stuff should go, and then of course actually doing it. Any help would be greatly appreciated.

EncryptableString.h
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class EncryptableString
  6. {
  7. public:
  8. EncryptableString();
  9. void encrypt();
  10. };


EncryptableString.cpp
  1. #include "EncryptableString.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. void EncryptableString::encrypt()
  8. {
  9. // Encryption Code Here
  10. }



EncryptString.cpp

  1. #include "EncryptableString.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. EncryptableString.encrypt();
  9.  
  10. cin.get();
  11. return 0;
  12. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,679
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 193
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: String Encryption Challenge Help

 
0
  #2
Sep 20th, 2009
I think those instructions are pretty clear.

Create a class, that is derived from the string class. You will have to create your own constructor(s), the encryption method, and ideally input and output methods. See below for a general framework

  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class myString: public string
  7. {
  8. private:
  9.  
  10.  
  11. public:
  12. myString( );
  13. myString( string source );
  14. void modify( );
  15. string theString; //should be private, and need to include input output methods
  16. };
  17.  
  18. myString::myString( )
  19. {
  20. theString = "";
  21. }
  22.  
  23. myString::myString(string source )
  24. {
  25. theString = source;
  26. }
  27.  
  28. void myString::modify( )
  29. {
  30. theString[0] = 'A';
  31. }
  32.  
  33.  
  34. int main()
  35. {
  36. myString s1;
  37. myString s2( "Hello, World" );
  38. cout << s1.theString << endl << s2.theString << endl << endl;
  39.  
  40. s2.modify( );
  41. cout << s2.theString << endl;
  42.  
  43. return 0;
  44. }
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 250
Reputation: sfuo is on a distinguished road 
Solved Threads: 29
sfuo's Avatar
sfuo sfuo is online now Online
Posting Whiz in Training

Re: String Encryption Challenge Help

 
0
  #3
Sep 20th, 2009
You can use this to encrypt your string.
  1. void EncryptableString::encrypt()
  2. {
  3. for( int i = 0; i < content.length(); i++ )
  4. {
  5. if( (content[i] >= 'a' && content[i] < 'z') || (content[i] >= 'A' && content[i] < 'Z'))
  6. {
  7. content[i] += 1;
  8. }
  9. else if( content[i] == 'z' || content[i] == 'Z' )
  10. {
  11. content[i] -= 25;
  12. }
  13. }
  14. }
I made a class that has a private variable content and has two public functions: print() and encrypt().

Based on some of your start code you showed I have a feeling you are going to run into a few problems while doing this project.
  1. #include "EncryptableString.h"
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. EncryptableString.encrypt();
  9.  
  10. cin.get();
  11. return 0;
  12. }

EncryptableString.encrypt() means nothing because it is a variable type not a variable its self.

Coming across this thread made me wonder how to output a variable within a class without having to call a function. I made a new thread for that but not knowing how to do that forced me to use a print() function, which I think is messy unless this is going to be a closed source submission.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 97
Reputation: Alex_ is an unknown quantity at this point 
Solved Threads: 2
Alex_'s Avatar
Alex_ Alex_ is offline Offline
Junior Poster in Training

Re: String Encryption Challenge Help

 
0
  #4
Sep 20th, 2009
I believe your homework is complete. All you have to do know is put those two in one and study it well, understanding how to program.
Fundamental law of life:
do{ ThingsToDo+=me.CompleteTask(ThingsToDo); }while(ThingsToDo); Die(me);
Law of the Spirit:
do{ Rebuke(me); }while(!me.Repented); LiveEternal(me);
PM me to know more why i wrote this or what it means.
Reply With Quote Quick reply to this message  
Reply

Tags
challenge, encryption, string

Message:


Thread Tools Search this Thread



Tag cloud for challenge, encryption, string
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC