Substitution ciphers can be compared with transposition ciphers. In a transposition cipher, the units of the plaintext are rearranged in a different and usually quite complex order, but the units themselves are left unchanged. By contrast, in a substitution cipher, the units of the plaintext are retained in the same sequence in the ciphertext, but the units themselves are altered.
There are a number of different types of substitution cipher. If the cipher operates on single letters, it is termed a simple substitution cipher; a cipher that operates on larger groups of letters is termed polygraphic. A monoalphabetic cipher uses fixed substitution over the entire message, whereas a polyalphabetic cipher uses a number of substitutions at different positions in the message, where a unit from the plaintext is mapped to one of several possibilities in the ciphertext and vice versa.
Here is source code of the C++ Program to Implement the Monoalphabetic Cypher. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
// the rot13 function
std::string rot13(std::string s)
static std::string const lcalph = "abcdefghijklmnopqrstuvwxyz", ucalph =
for (std::string::iterator it = s.begin(); it != s.end(); ++it)
if ((pos = lcalph.find(*it)) != std::string::npos)
result.push_back(lcalph[(pos + 13) % 26]);
else if ((pos = ucalph.find(*it)) != std::string::npos)
result.push_back(ucalph[(pos + 13) % 26]);
// function to output the rot13 of a file on std::cout
// returns false if an error occurred processing the file, true otherwise
// on entry, the argument is must be open for reading
int rot13_stream(std::istream& is)
while (std::getline(is, line))
if (!(std::cout << rot13(line) << "\n"))
// the main program
int main(int argc, char* argv)
if (argc == 1) // no arguments given
return rot13_stream(std::cin) ? EXIT_SUCCESS : EXIT_FAILURE;
for (int i = 1; i < argc; ++i)
std::cerr << argv << ": could not open for reading: " << argv[i]
// no error occurred for file, so the error must have been in output
std::cerr << argv << ": error writing to stdout\n";
std::cerr << argv << ": error reading from " << argv[i]
std::cerr << argv << ": warning: closing failed for " << argv[i]
$ g++ MonoalphabeticCipher.cpp $ a.out Dharmendra Qunezraqen Hingu Uvath Sanfoundry Fnasbhaqel ------------------ (program exited with code: 0) Press return to continue
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.