CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2009
    Posts
    7

    Question string together letters for encryption..

    there is a certain command if I remember correctly to imput multiple letters like if I say "hello" it will encrypt "hello" not just the "h" thats what I'm stuck doing right now here is my code. I know its something simple I just can't think of it.. this is supposed to be a very simple cipher so I'd like to keep the program the same. thanks for the help I'll keep digging.
    Code:
    #include <iostream>
    #include <iomanip>
    #include <stdlib.h>
    
    using namespace std;
    
    char encrypt(char);
    int encrypt(int);
    double encrypt(double);
    char decrypt(char);
    int decrypt(int);
    double decrypt(double);
    void perform();     
    
    
    int main()
          {
          perform();   
          return 0;
          }
    
    //Cliff
    void perform()
          {
          char character;
          char decryptchoice = '1';
          char encryptchoice = '1';
          string choice;
          int integer;
          double real;
          cout << "\nWelcome to our encryption program\n" << endl;
          cout << fixed << showpoint;
          cout << setprecision(2); 
    
    
          {            
          cout << "Please 1 to Encrypt." << endl;
          cout << "Please 2 to Decrypt." << endl;
          cout << "Please 9 to Exit.\n" << endl;
          cout << "Press 1, 2 or 9: ";      
          cin >> choice;
          system("CLS");
          
          if (choice == "1")      
          {
          goto choice1;
          } 
          
          if (choice == "2")      
          {
          goto choice2;
          }
          if (choice == "9")
          {
          goto choice9;
          } 
          
          if (choice != "1")
          if (choice != "2")
          if (choice != "9")
          {
          cout << "Please choose 1, 2 or 9 ." << endl;
          system("PAUSE");
          system("CLS");
          return perform();
          } 
    
          //Charlie
          choice1:
          cout << "\nEncryption Menu" << endl;                 
          cout << "\nPlease 1 to encrypt a character." << endl;
          cout << "Please 2 to encrypt an integer." << endl;
          cout << "Please 3 to encrypt a real number." << endl;
          cout << "Please 9 to exit.\n" << endl;
          cout << "Press 1, 2, 3 or 9: ";   
          cin >> encryptchoice;              
                            }
                        
                        
          switch (encryptchoice)
          {
          case '1':
          cout << "Enter a character to encrypt: ";
          cin >> character;
          cout << "The encrypted character is " << encrypt (character) << endl;
          system("PAUSE");
          goto choice9;
          break;
          case '2':
          cout << "Enter an integer to encrypt: ";
          cin >> integer;
          cout << "The encrypted number is " << encrypt (integer) << endl;
          system("PAUSE");
          goto choice9;
          break;
          case '3':
          cout << "Enter a real number to encrypt: ";
          cin >> real;
          cout << "The encrypted number is " << encrypt (real)  << endl;
          system("PAUSE");
          goto choice9;
          break;
          case '9':
          cout << "Thank you for using the encryption program." << endl;
          system("PAUSE");
          goto choice9;
          break;
          default:
          cout << "Invalid choice." << endl;
          system("PAUSE");
          goto choice9;
          break;
     
          //TJ
          choice2:
          cout << "\nDecryption Menu" << endl;
          cout << "\nPlease 1 to decrypt a character." << endl;
          cout << "Please 2 to decrypt an integer." << endl;
          cout << "Please 3 to decrypt a real number." << endl;
          cout << "Please 9 to exit.\n" << endl;
          cout << "Press 1, 2, 3 or 9: ";   
          cin >> decryptchoice;  
          }
          
          switch (decryptchoice)    
          {  
          case '1':
          cout << "Enter a character to decrypt: ";
          cin >> character;
          cout << "The decrypted character is " << decrypt (character) << endl;
          system("PAUSE");
          break;
          case '2':
          cout << "Enter an integer to decrypt: ";
          cin >> integer;
          cout << "The decrypted number is " << decrypt (integer) << endl;
          system("PAUSE");
          break;
          case '3':
          cout << "Enter a real number to decrypt: ";
          cin >> real;
          cout << "The decrypted number is " << decrypt (real) << endl;
          system("PAUSE");
          break;
          case '9':
          cout << "Thank you for using the decryption program." << endl;
          default:
          cout << "Invalid choice." << endl;
          system("PAUSE");
          break;
          }
    
          choice9:
          cout << "\nThank you for using the encryption program." << endl;
          system("PAUSE");
          system("EXIT");
          }                     
    //Cliff
    char encrypt (char character)
    {
        return character + 4;
    }
    //Charlie
    int encrypt (int integer)
    {
        return integer + 4;
    
    }
    //TJ
    double encrypt (double real)
    {
        return real + 4;
    
    }
    //Cliff
    char decrypt (char character)
    {
        return character - 4;
    }
    //Charlie
    int decrypt (int integer)
    {
        return integer - 4;
    }
    //TJ
    double decrypt (double real)
    {
        return real - 4;
    }
    Last edited by cilu; March 20th, 2009 at 01:51 AM. Reason: code tags

  2. #2
    Join Date
    Feb 2009
    Location
    India
    Posts
    444

    Re: string together letters for encryption..

    Use <CODE></CODE> tags.
    «_Superman
    I love work. It gives me something to do between weekends.

    Microsoft MVP (Visual C++)

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: string together letters for encryption..

    there is a certain command if I remember correctly to imput multiple letters like if I say "hello" it will encrypt "hello" not just the "h" thats what I'm stuck doing right now here is my code. I know its something simple I just can't think of it.. this is supposed to be a very simple cipher so I'd like to keep the program the same. thanks for the help I'll keep digging.
    So what was the problem?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Mar 2009
    Posts
    7

    Re: string together letters for encryption..

    I appologize for that, I just started reading the faq... i will use code tags from now on

    basically if a user puts in a word for encryption, it will only encrypt the fist letter then dump the rest.

    as in the original post if I "cin >> hello" it only reads the "h" and drops the rest of the word and encrypts that "h" to "l" then displays it to screen

    I need it to encrypt the whole word not just "h"

    so "hello" should display "lipps" not just "l"

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: string together letters for encryption..

    Your menu doesn't seem to have an option to encrypt an entire word.....it only offers to encrypt a character. I'm not clear why you'd want to do something different than what the menu is promising?

  6. #6
    Join Date
    Mar 2009
    Posts
    12

    Re: string together letters for encryption..

    Encryption is usually done on the bit level, you know like XOR. I would not add or subtract values. This is more obfuscation than encryption.

  7. #7
    Join Date
    Mar 2009
    Posts
    7

    Re: string together letters for encryption..

    Quote Originally Posted by Lindley View Post
    Your menu doesn't seem to have an option to encrypt an entire word.....it only offers to encrypt a character. I'm not clear why you'd want to do something different than what the menu is promising?
    I will agree with you but it isn't that hard to change a menu option from character to a sentence, or sequence of numbers.

    I would like to know how I could allow user to input a sequence of numbers.

    as for the post above this I looked into XOR just now, and I'm not that far into my C++ class yet, were just starting to learn loops and such, its more of a cypher to be exact.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured