Question

Its a c++ program and please use basic code, I am a begineer. Please do show aall the stepsRandom monoalphabet cipher. The Caesar cipher, which shifts all letters by a fixed amount, is far too easy to crack. Here is a better idea. As the key, dont use numbers but words. Suppose the key word is FEATHER. Then first remove duplicate letters, yielding FEATHR, and append the other letters of the alphabet in reverse order: Now encrypt the letters as follows: A B C D E F G H 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. It is an error not to supply a keyword

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

Answer

c++ programm

#include <iostream>

#include <fstream>

#include<iomanip>

using namespace std;

//encryption

void lEncrypt(string,istream&,ostream&);

//decryption

void lDecrypt(string,istream&,ostream&);

string ladjust(string a);

int main(int argc, char * argv[])

{

     ifstream in;

     ofstream out;

     string lkey;

     in.open(argv[3]);

     if(in.fail())           

     {

          cout<<"file error\n";

          system("pause");

          return 1;

     }

     out.open(argv[4]);

     lkey=argv[2];

     if(lkey[0]!='-'&&lkey[1]!='k')

     {

          cout<<"missing lkey\nprogram aborted\n";

          return 1;

     }

     lkey=ladjust(lkey);

     cout<<lkey<<endl;

     if(strcmp(argv[1],"-d")==0)

     lDecrypt(lkey,in,out);

     else

     lEncrypt(lkey,in,out);   

     in.close();

     out.close();

     return 0;

}

string ladjust(string lkey)

{

     int lcount[26]={0};

     char lc;

     int li;

     bool lfound;

     string lnewkey="";

     for(li=2;lkey[li]!='\0';li++)

     {

          lkey[li]=toupper(lkey[li]);

          lcount[lkey[li]-'A']++;

     }

     for(li=0;li<26;li++)

     cout<<(char)('A'+li)<<" "<<lcount[li]<<endl;

     for(li=2;lkey[li]!='\0';li++)

     if(lcount[lkey[li]-'A']!=0)

     {

          lnewkey=lnewkey+lkey[li];

          lcount[lkey[li]-'A']=0;

     }

     int lLen=lnewkey.length();

     for(lc='Z';lc>='A';lc--)

     {

          lfound=false;

          cout<<lnewkey<<" "<<lnewkey.length()<<endl;

          for(li=0;li<lLen;li++)

          if(lc==lkey[li])

          {

              lfound=true;

              cout<<lc<<" "<<li<<endl;

          }

          cout<<lc<<" "<<lfound<<endl;    

          if(!lfound)   

          lnewkey=lnewkey+lc;

     }

     cout<<lnewkey<<endl;   

     return lnewkey;

}

void lEncrypt(string lw,istream& in,ostream& out)

{

     string lbuffer;

     int li;

     getline(in,lbuffer);

     while(in)

     {

          for(li=0;lbuffer[li]!='\0';li++)

          if(isalpha(lbuffer[li]))

          {

              out<<lw[toupper(lbuffer[li])-'A'];

              cout<<toupper(lbuffer[li])-'A'<<" "<<lw[toupper(lbuffer[li])-'A']<<" "<<li<<" "<<lbuffer[li]<<endl;

          }

          else

          out<<lbuffer[li];

          out<<endl;

          getline(in,lbuffer);

     }

}

void lDecrypt(string lw,istream& in,ostream& out)

{

     string lbuffer;

     int li,lj;

     getline(in,lbuffer);

     while(in)

     {

          for(li=0;lbuffer[li]!='\0';li++)

          if(isalpha(lbuffer[li]))

          {

              for(lj=0;lj<lw.length();lj++)

              if(toupper(lbuffer[li])==lw[lj])

              out<<(char)('A'+lj);

          }

          else

          out<<lbuffer[li];

          out<<endl;

          getline(in,lbuffer);

     }

}

Add a comment
Know the answer?
Add Answer to:
Its a c++ program and please use basic code, I am a begineer. Please do show...
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
  • Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could...

    Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could you possibly make it as simple as you can without losing functionality. please include comments, that would help me better understand Example of PlayFair Cipher: https://en.wikipedia.org/wiki/Playfair_cipher The Playfair cipher uses a 5 by 5 table containing a key word or phrase. Memorization of the keyword and 4 simple rules was all that was required to create the 5 by 5 table and use the...

  • C++ Code

    "For two thousand years, codemakers have fought to preserve secrets while codebreakers have tried their best to reveal them." - taken from Code Book, The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography by Simon Singh.The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The convention in cryptography is to write the plain text in lower case letters and the encrypted text in upper case...

  • Write the programming C please, not C++. The main function should be to find the offset...

    Write the programming C please, not C++. The main function should be to find the offset value of the ciper text "wPL2KLK9PWWZ7K3ST24KZYKfPMKJ4SKLYOKRP4KFKP842LK0ZTY43 " and decrypt it. In cryptography, a Caesar Cipher is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be...

  • Please answer this problem without using iostream and without strings or arrays. Just use stdio.h and...

    Please answer this problem without using iostream and without strings or arrays. Just use stdio.h and math.h. 57677 1 Caesar's Cipher (70 points) The Caesar's cipher is a cryptographic method for encrypting text such that it becomes unreadable to a party with- out access to the cryptographic key. It is named after Julius Caesar, who allegedly used it to protect messages of military significance. The encryption and decryption operations are simple shifts of the alphabet letters in a cyclic fashion....

  • ****************************************************************************************************************8 I want it same as the output and with details please and comments "For two...

    ****************************************************************************************************************8 I want it same as the output and with details please and comments "For two thousand years, codemakers have fought to preserve secrets while codebreakers have tried their best to reveal them." - taken from Code Book, The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography by Simon Singh. The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • Please help me write this Java program. I had posted this question before, but got an...

    Please help me write this Java program. I had posted this question before, but got an answer that was totally wrong. We are using the latest version of Java8. Thank You! -------------------------------------------------------------------------------------- Write a Java program that can successfully DECRYPT a string inputted by the user which has been encrypted using a Caesar Cipher with a unknown shift value(key). You can use brute force to do a for loop through all the 26 shift values, however, your program should only...

  • JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the...

    JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...

  • Develop a Java application that uses a type of encrypted alphabet, called a random monoalphabetic cipher,...

    Develop a Java application that uses a type of encrypted alphabet, called a random monoalphabetic cipher, to encrypt and decrypt a message. Your encryption key and message are to be read in from two different files and then the encrypted message will be output to third file. Then the encrypted message is read in and decrypted to a fourth file. A monoalphabetic cipher starts with an encryption word, removes the redundant letters from the word, and assigns what’s left to...

  • **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the...

    **DO IT AS PYTHON PLEASE** The Trifid Cipher General Problem Description The Trifid cipher (not to be confused with the creatures from the classic science-fiction film "The Day of the Triffids") is an algorithm that enciphers a plaintext message by encoding each letter as a three-digit number and then breaking up and rearranging the digits from each letter's encoded form. For this assignment, you will create a set of Python functions that can encode messages using this cipher (these functions...

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