In this assignment you will write the code for two functions

In this assignment, you will write the code for two functions, and demonstrate your functions are correct with drivers. The first function checks that a password is valid. To be valid, a password must Be at least 8 characters and at most 10 characters Have at least one upper case letter, one lower case letter, one digit and one special character. A special character is one of the following characters: a, &, Not contain any character which is not a letter, digit or special character. The second function encrypts an original string of characters into another string of characters. The encryption scheme will be an adapted version of the Caesar cipher. 1. Additional Requirements a) Functions You are required to implement your program with the following functions. You can implement additional functions, as you see fit, to make your program more modular isValidPassword: takes as argument a string and returns true if the string is a valid password. Else it returns false. encrypt takes as arguments a string, an encryption key, encrypts it, and returns the encrypted result, which is a string. b) Style Make sure you follow the style requirements, especially regarding the comment header for functions, to avoid losing points. c) Adapted Caesar cipher Caesar cipher is a type of encryption in which each letter in the plaintext is replaced by aletter some fixed number of positions down the alphabet. For example, with an offset of 3, D would be replaced by A,Ewould become B, and so on. The offset value is the encryption key. We adapt the scheme to encrypt all characters whose ASCII code is MIN RANGE (set to 33) to MAX RANGE (set to 122) inclusive. These include all the alphabet letters, upper case and lower case, and all the digits, but exclude the non printable characters. To encrypt, we convert the ASCII code by adding the offset to the ASCII code. If the converted code is in the MIN RANGE to MAX RANGE,the character whose ASCII code is equal to the converted code is the encrypted character. If the converted code is outside the range, we wrap around the value so that it falls within the

Solution

//Feb_3_encryptPwd.h

#include<string.h>

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string>
const int MIN_RANGE = 33;
const int MAX_RANGE = 122;
//function declaration of isValidPassword and encrypt functions
bool isValidPassword(char *s, char spec[], int size);
char *encrypt(char *s, int key);
bool isspecial(char c, char spec[], int size);

-------------------------------------------------------------------------------------------------

//Feb_3_encryptPwd.cpp

#include\"Feb_3_encryptPwd.h\"

//function definition of isValidPassword and encrypt functions
bool isValidPassword(char *s,char spec[],int size)
{
   int i, CapitalCnt = 0, LowerCnt = 0, DigitCnt = 0, SplCnt = 0, otherCnt =0;

   if (strlen(s) < 8)
   {
       //printf(\"Password must be 8 characters\ \");
       return false;
   }
   if (strlen(s) > 10)
   {
       //printf(\"Password must be 10 characters at most\ \");
       return false;
   }
  
   for (i = 0; i < strlen(s); i++)
   {
       if (!isupper(s[i]) && !islower(s[i]) && !isdigit(s[i]) && !isspecial(s[i], spec, size))
           otherCnt++;
       if (isupper(s[i]))
           CapitalCnt++;
       if (islower(s[i]))
           LowerCnt++;
       if (isdigit(s[i]))
           DigitCnt++;
       //if (s[i] == \'#\' || s[i] == \'$\' || s[i] == \'%\' || s[i] == \'&\' || s[i] == \'!\' || s[i] == \'?\' || s[i] == \'@\')
       if ( isspecial(s[i],spec,size))
           SplCnt ++;
      
   }
   if (CapitalCnt < 1)
   {
       //printf(\"Password should contain atlease one capital character\ \");
       return false;
   }
   if (LowerCnt < 1)
   {
       //printf(\"Password should contain atlease one lower character\ \");
       return false;
   }
   if (DigitCnt < 1)
   {
       //printf(\"Password should contain atlease one digit character\ \");
       return false;
   }
   if (SplCnt < 1)
   {
       //printf(\"Password should contain atlease one special character\ \");
       return false;
   }
   if (otherCnt >0)
   {
       //printf(\"Password contains character which is not letter , digit or special character\ \");
       return false;
   }

   return true;

}
char *encrypt(char *s, int key)
{
   int i;
   char *str ;

   str = (char*)malloc(strlen(s)*sizeof(char));

   for (i = 0; i < strlen(s); i++)
   {
       if (s[i] >= MIN_RANGE && s[i] <= MAX_RANGE)
           str[i] = s[i] - key;
       else
           str[i] = s[i];
   }
   str[i] = \'\\0\';
   return str;
}

bool isspecial(char c, char spec[], int size)
{
  
   int i = 0;
   bool found = false;

   for (i = 0; i < size; i++)
   {
       if (c == spec[i])
       {
           found = true;
       }
   }

   return found;

}

----------------------------------------------------------------------

//main.cpp

#include<iostream>
#include\"Feb_3_encryptPwd.h\"
using namespace std;

int main()
{
  
   char special[] = { \'%\', \'$\', \'%\', \'&\', \'!\', \'?\', \'@\' };
   int numSpecial = sizeof(special) / sizeof(char);
  
   //driver for isValidPassword
   //array of strings
   char s[4][12] = { \"@Jan12kl\", \"12Bhjk\", \"_6bH?jkl\", \"%1Bhtyjk12n\" };
   int ret;
   //check each string of password
   cout << \"Driver for isValidPassword\" << endl;
   for (int i = 0; i < 4; i++)
   {
       ret = isValidPassword(s[i], special, numSpecial);
       if (ret)
       {
           cout << s[i] << \" is valid password\" << endl;
       }
       else
           cout << s[i] << \" is not valid password\" << endl;
   }
}

---------------------------------------------------------------------------------

//output for isValidPassword

Driver for isValidPassword
@Jan12kl is valid password
12Bhjk is not valid password
_6bH?jkl is not valid password
%1Bhtyjk12n is not valid password

---------------------------------------------------

//output for encrypt

 In this assignment, you will write the code for two functions, and demonstrate your functions are correct with drivers. The first function checks that a passwo
 In this assignment, you will write the code for two functions, and demonstrate your functions are correct with drivers. The first function checks that a passwo
 In this assignment, you will write the code for two functions, and demonstrate your functions are correct with drivers. The first function checks that a passwo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site