December 7th, 2004, 11:21 AM
|
#1 (permalink)
|
| Ultimate Member
Join Date: Oct 2003 Location: Aztec, New Mexico
Posts: 1,608
|
My C++ class this semester is almost over, and just to experiment with it, I made this program: Code: #include <iostream>
#include <string>
using namespace std;
int a = 0;
int b = 0;
string inString;
int choice;
string encrypt(string & inString)
{
for(a = 0; a <= 3; a++)
{
inString[a] = inString[a] + 3;
}
return inString;
}
string decrypt(string & inString)
{
for(a = 0; a <= 3; a++)
{
inString[a] = inString[a] - 3;
}
return inString;
}
int main()
{
if(b == 0)
{
cout << "Would you like to:" << endl;
cout << "1) Encrypt a string" << endl;
cout << "2) Decrypt a string" << endl;
cout << "3) Quit" << endl; "? ";
cin >> choice;
if(choice == 1)
{
cout << "Enter a string to be encrypted: ";
cin >> inString;
cout << "The encrypted string is: " << encrypt(inString) << endl;
}
else if(choice == 2)
{
cout << "Enter an encrypted string to decrypt: ";
cin >> inString;
cout << "The decrypted string is: " << decrypt(inString) << endl;
}
else if(choice == 3)
{
b == 1;
}
else
{
cout << "Invalid input, please try again." << endl;
}
}
return 0;
} I call it 'encrypt', but it actually just raises the value of each letter in the string inputted, by 3. A becomes D, and so forth.
It doesn't stay open after selecting '1', or '2' when ran through windows, but the .EXE file is in here: http://www.jonbuder.us/files/encrypt.rar |
| |