Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming Random monoalphabet cipher. The caeser cipher, which shifts all

ID: 3761092 • Letter: C

Question

C++ Programming Random monoalphabet cipher.

The caeser cipher, which shifts all letters by a certain amount, is easy to decipher. Try this, instead of numbers use letters.

Consider this, the word is FEATHER. Remove duplicate letters, making FEATHR, and append the rest of the letters of the alphabet in reverse order.

Write a C++ program that encrypts or decrypts a file using this cipher.

For example, crypt –d –kFEATHER encrypt.txt output.txt decrypts a file using the keyword FEATHER. You must always supply a keyword.

Explanation / Answer

Explanation:
Suppose the key word is FEATHER. Then you first remove duplicate letters, yielding FEATHR, and append the
other letter of the alphabet in reverse order:
F E A T H R Z Y X W V U S Q P O N M L K J I G D C B
Now encryption can be described as a mapping shown below:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

F E A T H R Z Y X W V U S Q P O N M L K J I G D C B
Here, the upper row represents each of the original letters in a text and the lower row describes the
corresponding cipher letter in the encrypted text. As such, encrypting a file is to substitute a cipher letter for
each letter in the file as shown above and decrypting an encrypted file is just to do the opposite

program:

string MonoSubsitutionEncrypt(string line)
{
string original = "abcdefghijklmnopqrstuvwxyz";
string excrypt = original;
random_shuffle(encrypt.begin(), encrypt.end());
map<char, char> m;
for (int i = 0;i < original.length(); i++)
m.insert(make_pair(original[i],encrypt[i]));
string result;
for (int i = 0; i < line.length(); i++)
result += m[line[i]];
return result;
}
string MonoSubsitutionEncrypt(string line)
{
string original = "abcdefghijklmnopqrstuvwxyz";
string excrypt = original;
random_shuffle(encrypt.begin(), encrypt.end());
map<char, char> m;
for (int i = 0;i < original.length(); i++)
m.insert(make_pair(original[i],encrypt[i]));
string result;
for (int i = 0; i < line.length(); i++)
result += m[line[i]];
return result;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote