C++ help
dzaikiIf you were to encrypt a file using the cipher of Exercise P9.2, the letters will mixed up, and will appear as that you cannot decrypt it without the keyword. Also, it would seem illogical to try and guess the keyword, but someone who is trained in decryption would have no trouble breaking the cipher. The average letter frequencies of English letters are common knowledge. The most common letter E, occurs about 13% of the time.
- See Exhibit B.
- Write a program that reads as an input file and shows the letter frequencies in the file. This tool is invaluable to a code breaker. If the most frequent letters are H and K there is a high probability that they are the encryptions of E and T.
I have this code
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
void count_frequencies(string str,int list[],int size)
{
for(int i=0; i<str.length(); i++)
{
if(str[i]>='A' && str[i]<='Z')
list[str[i]-'A']++;
else if(str[i]>='a' && str[i]<='z')
list[str[i]-'a']++;
else continue;
}
}
int main()
{
ifstream infile;
string file_name;
int list[26] = { 0 };
string str;
cout <<"Enter file name to letter frequencies in the file. :";
cin >> file_name; cout << endl;
infile.open(file_name.c_str());
if(!infile)
{
cout <<"Unable to open file . So Exiting from program :" << endl;
return 0;
}
while(!infile.eof())
{
infile >> str;
count_frequencies(str,list, 26);
}
infile.close();
cout <<"Letter \t Count " << endl;
int max = list[0];
for(int i=0; i<26; i++)
{
cout << static_cast<char> (i+'a') <<" \t " << list[i] << endl;
if(list[i] > max ) max = list[i];
}
cout <<"Most occured letter is " << static_cast<char> (max+'a') << endl;
cout << "So E is Encrypted to " << static_cast<char> (max+'a') << endl;
//system("pause");
return 0;
}
but it does not work correclty.I need this ASAP
- 8 years ago
- 20
Purchase the answer to view it
- runningcode.png
- input.txt
- encrytion.doc
Purchase the answer to view it
- coding.zip
- kochulem.docx
- Entomology1
- Payment - MA/WA
- Acc 543 Week One Individual Assignment Exercise 24-6A Determining net present value
- Week 1 - Discussion 2
- Assig
- Children: For Better or Worse
- I need help with a business management project? Its for my organizational behavior class
- case study assignment
- ECT 246 Week 4 Lab - New 2015
- Using the web pages associated with the Foundation for Critical Thinking website,choose one of the four topics below and respond to the aspects of the prompt in at least 400 words. The essay must be 400 words in length, excluding title and reference pag