Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Need help with encryption/decryption program

Need help with encryption/decryption program

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialsecurityhelplearning
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Quaydogg
    wrote on last edited by
    #1

    I'm having trouble with something that my professor assigned. He's out of town at the moment and hasn't answered any of my emails and the text book doesn't explain how to do this very well. It is an encryption/decryption program. The output should be like this: Original string is: this is a secret! Encrypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc. The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it. Here's the template. Where you see /* that's where I have to write lines of code. The part that I'm totally cluless on is the implementation of the functions 'encrypt' and 'decrypt'. Thanks. #include using std::cout; using std::endl; /* Write the prototype for function encrypt */ /* Write the prototype for function decrypt */ int main() { // create a string to encrypt char string[] = "this is a secret!"; cout << "Original string is: " << string << endl; encrypt( string ); cout << "Encrypted string is: " << string << endl; decrypt( string ); cout << "Decrypted string is: " << string << endl; return 0; } // end main // encrypt data void encrypt( char e[] ) { /* Write implementation for function encrypt */ } // end function encrypt // decrypt data void decrypt( char *ePtr ) { /* Write implementation for function decrypt */ } // end function decrypt

    M D C J 4 Replies Last reply
    0
    • Q Quaydogg

      I'm having trouble with something that my professor assigned. He's out of town at the moment and hasn't answered any of my emails and the text book doesn't explain how to do this very well. It is an encryption/decryption program. The output should be like this: Original string is: this is a secret! Encrypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc. The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it. Here's the template. Where you see /* that's where I have to write lines of code. The part that I'm totally cluless on is the implementation of the functions 'encrypt' and 'decrypt'. Thanks. #include using std::cout; using std::endl; /* Write the prototype for function encrypt */ /* Write the prototype for function decrypt */ int main() { // create a string to encrypt char string[] = "this is a secret!"; cout << "Original string is: " << string << endl; encrypt( string ); cout << "Encrypted string is: " << string << endl; decrypt( string ); cout << "Decrypted string is: " << string << endl; return 0; } // end main // encrypt data void encrypt( char e[] ) { /* Write implementation for function encrypt */ } // end function encrypt // decrypt data void decrypt( char *ePtr ) { /* Write implementation for function decrypt */ } // end function decrypt

      M Offline
      M Offline
      Micie
      wrote on last edited by
      #2

      I have an idea for encrypt implementation only. Pointers are my bad side. Still working on them. ;P [btw. You are a lucky guy, coz u have some1 who can teach you... I'm learning from net and books.]

      void encrypt(char array[])
      {
         char getString[] = decryptedString;
         char encryptedString[];
         int size = sizeof(getString);
         for( int n=0 ; n < size ; n++ )
         {
              encryptedString[n] = char((reinterpret_cast<int>(decryptedString[n]))-1);
         }
      }
      

      I'm outta home now.. not sure if it will works.. can't check it now.. I think that code is close to truth though. Hope it works and will help you at least a little. **__________ I'm made in C++... and I'm proud of it!_**

      1 Reply Last reply
      0
      • Q Quaydogg

        I'm having trouble with something that my professor assigned. He's out of town at the moment and hasn't answered any of my emails and the text book doesn't explain how to do this very well. It is an encryption/decryption program. The output should be like this: Original string is: this is a secret! Encrypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc. The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it. Here's the template. Where you see /* that's where I have to write lines of code. The part that I'm totally cluless on is the implementation of the functions 'encrypt' and 'decrypt'. Thanks. #include using std::cout; using std::endl; /* Write the prototype for function encrypt */ /* Write the prototype for function decrypt */ int main() { // create a string to encrypt char string[] = "this is a secret!"; cout << "Original string is: " << string << endl; encrypt( string ); cout << "Encrypted string is: " << string << endl; decrypt( string ); cout << "Decrypted string is: " << string << endl; return 0; } // end main // encrypt data void encrypt( char e[] ) { /* Write implementation for function encrypt */ } // end function encrypt // decrypt data void decrypt( char *ePtr ) { /* Write implementation for function decrypt */ } // end function decrypt

        D Offline
        D Offline
        Doug Mitchell
        wrote on last edited by
        #3

        IMHO, the common quality to all really good developers is problem solving skills. This quality separates those that do great things in the technology industry and those that are always worried about layoffs. I see two problems here that you need to solve. The first is the encrypt/decrypt functionality, which the professor has already given the solution. The other problem is how to use pointers. Is there something more specific you would like to ask?

        1 Reply Last reply
        0
        • Q Quaydogg

          I'm having trouble with something that my professor assigned. He's out of town at the moment and hasn't answered any of my emails and the text book doesn't explain how to do this very well. It is an encryption/decryption program. The output should be like this: Original string is: this is a secret! Encrypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc. The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it. Here's the template. Where you see /* that's where I have to write lines of code. The part that I'm totally cluless on is the implementation of the functions 'encrypt' and 'decrypt'. Thanks. #include using std::cout; using std::endl; /* Write the prototype for function encrypt */ /* Write the prototype for function decrypt */ int main() { // create a string to encrypt char string[] = "this is a secret!"; cout << "Original string is: " << string << endl; encrypt( string ); cout << "Encrypted string is: " << string << endl; decrypt( string ); cout << "Decrypted string is: " << string << endl; return 0; } // end main // encrypt data void encrypt( char e[] ) { /* Write implementation for function encrypt */ } // end function encrypt // decrypt data void decrypt( char *ePtr ) { /* Write implementation for function decrypt */ } // end function decrypt

          C Offline
          C Offline
          cmk
          wrote on last edited by
          #4

          normally i don't like to answer homework questions, but ... Without error or roll-over checking the following does what you want. If you were to hand in as shown i would fail you. Put in error and roll-over checking and maybe expand to make more readable. void encrypt( char e[] ) { for( int i = 0; e[i]; e[i++]++ ); } void decrypt( char *ePtr ) { while( *ePtr ) (*(ePtr++))--; } ...cmk Save the whales - collect the whole set

          1 Reply Last reply
          0
          • Q Quaydogg

            I'm having trouble with something that my professor assigned. He's out of town at the moment and hasn't answered any of my emails and the text book doesn't explain how to do this very well. It is an encryption/decryption program. The output should be like this: Original string is: this is a secret! Encrypted string is: uijt!jt!b!tfdsfu" Decrypted string is: this is a secret! Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc. The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it. Here's the template. Where you see /* that's where I have to write lines of code. The part that I'm totally cluless on is the implementation of the functions 'encrypt' and 'decrypt'. Thanks. #include using std::cout; using std::endl; /* Write the prototype for function encrypt */ /* Write the prototype for function decrypt */ int main() { // create a string to encrypt char string[] = "this is a secret!"; cout << "Original string is: " << string << endl; encrypt( string ); cout << "Encrypted string is: " << string << endl; decrypt( string ); cout << "Decrypted string is: " << string << endl; return 0; } // end main // encrypt data void encrypt( char e[] ) { /* Write implementation for function encrypt */ } // end function encrypt // decrypt data void decrypt( char *ePtr ) { /* Write implementation for function decrypt */ } // end function decrypt

            J Offline
            J Offline
            JimmyRopes
            wrote on last edited by
            #5

            /* Quaydogg wrote: Basically this program turns a character into the next letter of the alphabet. For example t becomes u, h becomes i,spaces become exclamation points, etc. Your synopsis of the problem is close but not 100% correct. As you have stated spaces become exclaimation points. When did spaces become part of the Roman alphabet? From your very limited example I think what is more likely happening is that you are incrementing and decrementing ASCII character codes. The example string you provided does not have sufficient information to make this statement unequivocally because there is no Z or z in the string but since space (ASCII 0x20)) ==> ! (ASCII 0x21) and ! (ASCII 0x21) ==> " (ASCII 0x22) it looks like that is what is happening. You should probably verify this with your professor because if you are rotating alphabetic characters than "Z" (ASCII 0x5a)would become "A" (ASCII 0x41) and "z" (ASCII 0x7a)would become "a" (ASCII 0x61) in the encryption routine. If you are incrementing ASCII character codes "Z" (ASCII 0x5a) ==> "[" (ASCII 0x5b)and "z" (ASCII 0x7a) ==> "{" (ASCII 0x7b) and your algorythm is a lot simpler to implement. I digress, onto the more pressing problem. Quaydogg wrote: The objective of this lab is to use pointer notation to make the program do this but I don't understand pointers too well. If someone could get me started on this program I'd appreciate it. I could give you code that solves the encryption and decryption problem but then you would still not understand pointers which is, in fact, the point (pun intended) of this whole exercise in the first place. Instead I will provide you with a few illustrations of pointers at work and try to explain what is going on so that, hopefully, you will understand the process more clearly. To start off pointers, as their name implies, point to something. This is different than being something as I will attempt to explain. A pointer is an address of a variable, structure, array, function, etc. You can reference the thing pointed to by use of the pointer. The semantics of pointers may be a bit confusing at first but work through it and they will become easier to understand. In the following examples I will be using cahracter arrays but pointers are by no means limited to strings. As I said before the pointer is an address of a thing. When you preface the pointer with an asterisk "*" you are working with the actual thing you are pointing to. Individual elements of the character array in the

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups