Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need the completed cpp files of encrypt.cpp ,decrypt.cpp and histogram.cpp` `encrypt.cpp` This file should implement shift cipher encryption as described in the introduction. I

i need the completed cpp files of encrypt.cpp ,decrypt.cpp and histogram.cpp`

`encrypt.cpp`

This file should implement shift cipher encryption as described in the introduction. I have given you a "skeleton" to complete:

``` #include #include

int main() { FILE* input = stdin; FILE* output = stdout; char c,k='K'; while ((c=getc(input)) != EOF) { //YOUR CODE HERE// putc(c,output); } } ```

There is basically only one line missing. Note that the key is K by default. You can test your code in the following way:

``` ~/Crypto_Spring_18/proj1$ cat x.clean | ./encrypt > yy.txt ~/Crypto_Spring_18/proj1$ diff yy.txt y.txt ~/Crypto_Spring_18/proj1$ ``` If your code works correctly then `yy.txt` should be identical to `y.txt`. The fact that this is so is confirmed by the fact that `diff` produces no output.

#### `decrypt.cpp`

This program converts a shift ciphertext back to the corresponding plaintext. Let's look at the code you have:

``` int main(int argc,char* argv[]) { check(argc,argv); char k = argv[1][0]; printf("key = %c ",k); FILE* input = stdin; FILE* output = stdout; char c; while ((c=getc(input)) != EOF) { /*YOUR CODE HERE*/ putc(c,output); } } ```

#### `histogram.cpp`

The starting point of any statistical attack on a substitution cipher is to first find the probability distribution of each of the characters that occur. We can approximate this for long inputs by analyzing the relative frequency of each letter. For example try this command.

``` ./hist < x.clean ```

You should see the following output.

``` A: 0.079 B: 0.015 C: 0.025 D: 0.045 E: 0.129 F: 0.026 G: 0.020 H: 0.065 I: 0.063 J: 0.001 K: 0.007 L: 0.037 M: 0.026 N: 0.063 O: 0.077 P: 0.018 Q: 0.001 R: 0.065 S: 0.061 T: 0.096 U: 0.029 V: 0.009 W: 0.024 X: 0.001 Y: 0.017 Z: 0.001 ```

This means that the character A is 7.9 percent of all letters in the file, E is 12.9 percent, etc. Technically the relative frequency of A is defined by

$$rf(A) = \frac{\text{number of occurrences of A}}{\text{total number of letters}}$$

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analytics And Quality Management Fundamental Tools

Authors: Joseph Nguyen

1st Edition

B0CNGG3Y2W, 979-8862833232

More Books

Students also viewed these Databases questions