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

Random monoalphabet cipher. The caeser cipher, which shifts all letters by a cer

ID: 3763059 • Letter: R

Question

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.

Now encrypt the letters as follows:

Now, write a 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.

Remember that your usage should be:

crypt –d -kFEATHER encrypt.txt output.txt

Specifically:

[-e] (for encrypt), [-d] (for decrypt), [WORD] (provides the encrypt/decryp key), infile, outfile

Your main() should probably look as follows:

int main(int argc, char* argv[]) //int argc is ## of arguments, argv is argument variables

Then, at the top of your main() you can check the number of arguments. Based on the usage above, you should have 5

if (argc != 5) //if all command line values not provided
{
    // Call a function that tells the user what the usage is
}

Based on whether the user is using -d or -e, you should call the corresponding method (e.g. encryption() or decryption()).

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
string rem_Duplicate(string str1)
{
string str2;
int pos;
for (int i = 0; i < str1.length(); i++)
{
if ((pos = str2.find(str1[i])) < 0)
str2 += str1[i];
}
cout << str2 << endl;
return str2;
}

int main()
{
ofstream output_file;
ifstream input_file("output.txt");
output_file.open("input.txt");
string FEATHER;
string key = FEATHER;
cout << "Enter the Key: ";
cin >> key;
key = rem_Duplicate(key);

input_file.close();
output_file.close();

cin.clear();
cin.ignore();
cin.get();

return 0;
}