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

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

ID: 3682491 • Letter: C

Question

Create (fill-in) the following 6 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. caesarEncrypt(string) - Given a string, return the caesar cypher encrypted string. Use the saved key in any way you want to generate an offset number. A good way to generate the offset is to sum up the ascii values in the key.

string Crypto::caesarEncrypt(const string& input){
// TODO: Fill me in
return "";
}
3. caesarDecrypt(string) - Given a string, return the caesar decrypted string. See encrypt for key description.

string Crypto::caesarDecrypt(const string& input){
// TODO: Fill me in
return "";
}

4. vigenereEncrypt(string) - Given a string, return the vigenere cypher encrypted string.

string Crypto::vigenereEncrypt(const string& input){
// TODO: Fill me in
return "";
}
5. vigenereDecrypt(string) - Given a string, return the vigenere cypher decrypted string.

string Crypto::vigenereDecrypt(const string& input){
// TODO: Fill me in
return "";
}
6. 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

string Crypto::caesarEncrypt(const string& input)
{
   string input;

    cout<<"String to encrypt: ";
    cin>>input;
   
    for (int i = 0; i < input.length(); i++){
        input[i] = input[i] + shift;
    }

    return input;
}

string Crypto::caesarDecrypt(const string& input)
{

   
        cout<<"String to decrpt: ";
    cin>>input;
   
    result = input;
       for (size_t i = 0; i < input.length(); i++)
         result[i] ^= input % passwordLength;
return input;
}

string Crypto::vigenereEncrypt(const string& input)
{

   char c, k;
   int i(0), len(key.length());
   for (it = plain.begin(); it != plain.end(); ++it)
   {
       c = *it;
       k = key.at(i%len);
       x_key.append(1, k);
       k = x_key.at(i);
       crypt.append(1, ((int)c + (int)k- 2*(int)'A')%26 + (int)'A');
       i++;
   }

}

string Crypto::vigenereDecrypt(const string& input)
{
char p, k;
   int i(0), len(key.length());
   for (it = crypt.begin(); it != crypt.end(); ++it)
   {
       p = *it;
       k = key.at(i%len);
       x_key.append(1, k);
       k = x_key.at(i);
       if (((int)p - (int)k) < 0 ) p+= 26;
       plain.append(1, ((int)p - (int)k)%26 + (int)'A');
       i++;
   }
}