Question

Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...

Help write down below program with C++ language!!! Please...

The Cipher Program Requirements An interactive program is required that allows a user to encode text using any of

three possible ciphers. The three ciphers you are to offer are: Caesar, Playfair and Columnar Transposition.

• The program needs to loop, repeating to ask the user if they wish to play with Caesar, Playfair or Columnar Transposition

until the user wishes to stop the program.

•For encoding, the program needs to read input phrases (you can limit these to a max of250 characters) and the selected c

ipher to apply from:

o the keyboard

o from an input file § For file input, the file may contain multiple phrases to encode.

o When encoding the option should exist for the original text phrase(s), the key and the encoded phrase to be

written to the screen as well as always being logged (written) to an output file.The program will write each encoded message and key for decoding to a file dedicated to each cipher type. The user may select a filename and to it the program will attach the text: Caesar/playfair/colTransto complete the file name. Thus, after the program runs there will be at most three encoded data files generated-one for each cipher type–each of which contains all the encoded data and associated keys needed to decode. This file should be readable as an input file to the decode option.

• For decoding, the program should accept:

o a keyboard entered encoded phrase and key for decoding

o a file with one or more sets of codes to decode consisting of: key information and the encoded phrase to decode.

oWhen decoding the option should exist for the original encoded message(s), the key and the decoded phrase to be logged (written) to an output file for later examination.

Important general requirements to take note of and related grading:

1.Your submission must be submitted by the required date and time indicated in Canvas.

2.The program must compile and run (0 credit if it doesn’t compile)

3.The program must have comment headers for the program and each function; descriptive comments w/in the function bodies. (0 credit if no or relatively useless comments)

4.The program may NOT contain:

a. global variables,

b. more than 1 return statement per function,

c. only/majority of functions with 0 parameters

d. exit, continue or goto statements.

e. Break statements other than standard use w/in a switch statement case.(0 credit for global variables, 50% loss of credit for other)

5.Unless previously discussed with your instructor you may only make use of C++ techniques found in chapters 1-7 of your text. (No pointers, structs, classes, vectors,etc...)

6.The final project program must contain at least 10 functions that modularize the project.

The functions will illust rate your command of parameter passing. (0 credit if fewer than 10 meaningful functions).

7.The due date/time is a hard date–no late assignments accepted–0 credit for late submissions.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Source code: -
------------------------------
#include <string.h>
#include <stdlib.h>
#include<fstream>
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
class Encoding
{
    public:
        map<int,int> keyMap;
        string const key="venky";
    public:
        void setOrder()
        {           
            for(int i=0; i < key.length(); i++)
            {
                keyMap[key[i]] = i;
            }
        }
    public:
        string encryptMessage(string msg)
        {
            int row,col,j;
            string cipher = "";
            col = key.length();
            row = msg.length()/col;
            if (msg.length() % col)
                row += 1;
            char matrix[row][col];
            for (int i=0,k=0; i < row; i++)
            {
                for (int j=0; j<col;)
                {
                    if(msg[k] == '\0')
                    {
                             matrix[i][j] = '_';
                         j++;
                    }
                    if( isalpha(msg[k]) || msg[k]==' ')
                    {
                        matrix[i][j] = msg[k];
                        j++;
                    }
                    k++;
                }
            }
            for (map<int,int>::iterator ii = keyMap.begin(); ii!=keyMap.end(); ++ii)
            {
                j=ii->second;
                for (int i=0; i<row; i++)
                {       
                    if( isalpha(matrix[i][j]) || matrix[i][j]==' ' || matrix[i][j]=='_')
                    cipher += matrix[i][j];
                }
            }
            return cipher;
        }
    public:
        string decryptMessage(string cipher)
        {
            int col = key.length();
            int row = cipher.length()/col;
            char cipherMat[row][col];
            for(int j=0,k=0; j<col; j++)
            for (int i=0; i<row; i++)
            cipherMat[i][j] = cipher[k++];
            int index = 0;
            for(map<int,int>::iterator ii=keyMap.begin(); ii!=keyMap.end(); ++ii)
                ii->second = index++;
            char decCipher[row][col];
            map<int,int>::iterator ii=keyMap.begin();
            int k = 0;
            for (int l=0,j; key[l]!='\0'; k++)
            {
                j=keyMap[key[l++]];
                for (int i=0; i<row; i++)
                {
                    decCipher[i][k]=cipherMat[i][j];
                }
            }
            string msg = "";
            for (int i=0; i<row; i++)
            {
                for(int j=0; j<col; j++)
                {
                    if(decCipher[i][j] != '_')
                    msg += decCipher[i][j];
                }
            }
            return msg;
        }
    public:
    string Caesar_Cipher(char text[], int s)
    {
        string result = "";
        int length=strlen(text);
        for (int i=0;i<length;i++)
        {
            if (isupper(text[i]))
                result += char(int(text[i]+s-65)%26 +65);
            else
                result += char(int(text[i]+s-97)%26 +97);
        }
        return result;
    }
   
};
int main()
{
    Encoding obj;
    string cipher;
    char Ciher_text[100],Playpair[100],Columnar[100];
    int shift=4,option;
    ifstream playpair_text,caeser_text,Columnar_text;
    caeser_text.open("Caeser.txt",ios::in);
    Columnar_text.open("Columnar.txt",ios::in);
    playpair_text.open("PlayFair.txt",ios::in);
    cout<<"\nWelcome to the Encoding Techniques"<<endl;
    while(true)
    {
        cout<<"\nMENU"<<endl;
        cout<<"\n1.CaeserCipher"<<endl;
        cout<<"\n2.PlayFair"<<endl;
        cout<<"\n3.Columnar Transposition"<<endl;
        cout<<"\n4.stop/exit"<<endl;
        cout<<"\nPlease select any Option "<<endl;
        cin>>option;
        switch(option)
        {
            case 1:
                caeser_text>>Ciher_text;
                cout<<"\nPlain Text is:"<<Ciher_text<<endl;
                cout<<"\nshift: "<<shift<<endl;
                cout<<"\nCipher Text: "<<obj.Caesar_Cipher(Ciher_text,shift);
                break;
            case 2:
                playpair_text>>Playpair;
                cout<<"\nPlain Text is:"<<Playpair<<endl;
                break;
            case 3:
                Columnar_text>>Columnar;
                cout<<"\nPlain Text is:"<<Columnar<<endl;
                obj.setOrder();
                cipher = obj.encryptMessage(Columnar);
                cout<<"\nEncrypted Message is: "<<cipher<<endl;
                cout<<"\nDecrypted Message is: "<<obj.decryptMessage(cipher)<<endl;
                break;
            case 4:
                exit(0);
            default:
                cout<<"\n Invalid Option"<<endl;
        }
    }
    return 0;
}


Sample Output: -
------------------------

Welcome to the Encoding Techniques

MENU

1.CaeserCipher

2.PlayFair

3.Columnar Transposition

4.stop/exit

Please select any Option
1

Plain Text is:WelcometotheWolrd

shift: 4

Cipher Text: AipgsqixsxliAspvh
MENU

1.CaeserCipher

2.PlayFair

3.Columnar Transposition

4.stop/exit

Please select any Option
3

Plain Text is:Received10000Rupees

Encrypted Message is: eee_eRs_cde_Rvp_iu__

Decrypted Message is: ReceivedRupees

MENU

1.CaeserCipher

2.PlayFair

3.Columnar Transposition

4.stop/exit

Please select any Option
4

--------------------------------
Process exited after 12.48 seconds with return value 0
Press any key to continue . . .

Welcome to the Encoding Techniques MENU 1.CaeserCipher 2.PlayFair з.columnar Transposition 4.stop/exit Please select any Opti

shift: 4 Cipher Text AipgsqixsxliAspvh ENU 1.CaeserCipher 2.PlayFair 3.Columnar Transposition 4.stop/exit Please select any O

Add a comment
Know the answer?
Add Answer to:
Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a doc...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • USING C LANGUAGE Write a program to compute a Caesar Cipher . You must read in...

    USING C LANGUAGE Write a program to compute a Caesar Cipher . You must read in a file of text and convert some of the letters to another letter using the following array: char key[27] = “efghijklmnopqrstuvwxyzabcd”; This means that if you encounter the letter ‘a’, then you will replace it with the letter ‘e’,etc. If you encounter any other characters in the input file (example: ‘A’ or space, etc, you will write them as is. You will write each...

  • Do this using the C language. show me the code being executed and also copy and...

    Do this using the C language. show me the code being executed and also copy and paste the code so i can try it out for myseld Instructions A cipher is mirrored algorithm that allow phrases or messages to be obfuscated (ie. "scrambled"). Ciphers were an early form of security used to send hidden messages from one party to another. The most famous and classic example of a cipher is the Caesar Cipher. This cypher worked by shifting each letter...

  • Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is...

    Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php.   Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...

  • Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user...

    Assignment 7: Caesar Cipher Assignment 7 You will create a Caesar cipher which allows the user to specify the key and the text to be encrypted. A Caesar cipher is a simple substitution cipher wherein each letter in the message is shifted a certain number of spaces down the alphabet -- this number is called the key. a b c d e f g h i j k l m n o p q r s t u v w...

  • Can someone please help me for this assignment? Cryptography — the science of secret writing —...

    Can someone please help me for this assignment? Cryptography — the science of secret writing — is an old science; the first recorded use was well before 1900 B.C. An Egyptian writer used previously unknown hieroglyphs in an inscription. We will use a simple substitution cypher called rot13 to encode and decode our secret messages. ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in...

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT