Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create (fill-in) the following 2 functions use c++ language 1. Crypto(string) -

ID: 3682498 • Letter: C

Question

Create (fill-in) the following 2 functions use c++ language

1. Crypto(string) - Class constructor which accepts a string password to be used in all encryption and decryption for these other functions.

Crypto::Crypto(const string& key_temp){
// TODO: Fill me in
}

2. letterFreqStDev(string) - Given a string, find the character counts (convert all to lowercase), and find the standard deviation of the character count list. The list will always be of length 26. The string ‘abcdefghijklmnopqrstuvwxyz’ should return the value 0 because each letter has an occurrence of 1. This function can be used to find how uniform the letter distribution of a string is. Distributions of an encrypted string are harder to crack if they have a lower standard deviation; if they are close to uniform.

double Crypto::letterFreqStDev(const string& input){
// TODO: Fill me in
return 0.0;
}

Explanation / Answer

Crypto::Crypto(const string& key_temp){
   //Assuming that the name of variable for storing the password in thr Crypto class is password
   password=key_temp;
}

double Crypto::letterFreqStDev(const string& input){
   //charCount will keed the count of each character
   int charCount[26];
   for(int i=0;i<input.length();++i)
   {
       //converting each character to lowercase
       char c=tolower(input[i]);
       //finding the ascii value of each character and accordingly finding index for which count is to be increased
       //example for b ascii is 98 and in charCount index 1 represents b,so 98-97 gives 1
       int x=(int)c-97;
       charCount[x]++;
   }
   int mean=0,sum_deviation=0;
   for(i=0;i<26;++i)
{
   mean+=data[i];
}
mean=mean/n;

    for(i=0; i<n;++i)
    {
        sum_deviation+=(charCount[i]-mean)*(charCount[i]-mean);
    }

    return sqrt(sum_deviation/n);

}