📄 encryption.cpp
字号:
// Exercise 19.12: Encryption.cpp
// Encrypts data entered by users.
#include <iostream> // required to perform C++ stream I/O
#include <string> // required to access string functions
using namespace std; // for accessing C++ Standard Library members
// function prototypes
void substitutionCipher( string & );
void transpositionCipher( string & );
// function main begins program execution
int main ()
{
// define variables
string input; // stores the plain text that the user enters
int selection; // stores a number corresponding to cipher type
cout << "\nEnter plain text: ";
getline( cin, input );
cout << "\nSelect the encryption type" << endl;
cout << "1 - Substitution cipher" << endl;
cout << "2 - Transposition cipher" << endl;
cout << "Enter selection: ";
cin >> selection;
// determine which encryption type to perform
if ( selection == 1 )
{
substitutionCipher( input ); // call substitutionCipher
} // end if
else if ( selection == 2 )
{
transpositionCipher( input ); // call transpositionCipher
} // end else if
else
{
cout << "\nError: Please enter a valid menu option.\n" << endl;
} // end else
return 0; // indicate that program ended successfully
} // end function main
// using the substitution cipher, display encrypted text
void substitutionCipher( string &plainText )
{
// normal alphabet string
string normalAlphabet = "abcdefghijklmnopqrstuvwxyz .!?,";
normalAlphabet += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// substitution alphabet string
string cipherAlphabet = "cdefg.hijk!lmn opqr?stuv,wxyzab";
cipherAlphabet += "CDEFG.HIJK!LMN OPQR?STUV,WXYZAB";
// define other local variables
string cipher = ""; // encrypted string
} // end function substitutionCipher
// using the transposition cipher, display encrypted text
void transpositionCipher( string &plainText )
{
// define local variables
string firstWord = ""; // stores the first word
string lastWord = ""; // stores the second word
} // end function transpositionCipher
/**************************************************************************
* (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
* Pearson Education, Inc. All Rights Reserved. *
* DISCLAIMER: The authors and publisher of this book have used their *
* best efforts in preparing the book. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these books. The authors *
* and publisher shall not be liable in any event for incidental or *
* consequential damages in connection with, or arising out of, the *
* furnishing, performance, or use of these programs. *
**************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -