|
-
March 19th, 2009, 11:11 PM
#1
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|