Explore BrainMass

C++ program for variation of Caesar's substitution cipher

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

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.

This is what I have so far:

#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");
string FEATHER;
string key = FEATHER;
cout << "Enter the Key: ";
cin >> key;
key = rem_Duplicate(key);



return 0;

Thank you for your time.

© BrainMass Inc. brainmass.com March 22, 2019, 3:00 am ad1c9bdddf

Solution Preview

Please find attached 597359.zip that contains following files:
- 597359.cpp
- input.txt
- encrypted.txt
- decrypted.txt

Code was tested using g++ compiler version ...

Solution Summary

Solution checks for validity of the arguments provided at the command line. It transforms only the alphabets in the input file while retaining their (upper/lower) case.