Question

1. Write a C++ program called Password that handles encrypting a password.

2. The program must perform encryption as follows:

a. main method

i. Ask the user for a password.

ii. Sends the password to a boolean function called isValidPassword to check validity.

1. Returns true if password is at least 8 characters long

2. Returns false if it is not at least 8 characters long

iii. If isValidPassword functions returns false

1. Print the following error message “The password must be at least 8 characters long.”

2. Loop and ask for password again and recheck it.

iv. If isValidPassword returns true then continue.

v. Ask the user for a key

vi. Send key to a boolean function called isValidKey.

1. Returns true if key is between 1 and 10 (inclusive

2. Returns false if not between 1 and 10 (inclusive)

vii. If isValidKey returns false, then print the following error message and ask for the password again and recheck it. The key must be between 1 and 10, you entered X. (X is the number entered)

viii. If isValidKey returns true continue.

ix. Send the password to function called encrypt that

1. Encrypts password using the formula below.

2. Returns a string representing the encrypted password.

x. Display the password and the encrypted password in a nicely formatted String such as: Your password is letmeinz the encrypted version of your password is rkzskot& with a key of 6.

Encryption Algorithm

a. Implement a simple shift cipher.

b. A shift cipher is a form of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.

For example, with shift of 3, A would be replaced by D, B would become E, and so on.

X Y ZLAB[CDELE

c. The shift for this program will be the key entered by the user.

d. The password may be any of the characters in the ASCII table from character 33 the exclamation point ‘!’ to character 122 the lower case ‘z’.

e. If the shift causes the character to be greater than 122, the shift will continue starting with character 33.

f. Remember char can be treated like integers so adding to a char is allowed. See example code posted with this project.

g. Example: If the user entered 8 as the key and a letter in the password is lower case ‘x’ (char 120) a shift of 8 would result in the character ‘&’ (char 38).

h. Be careful as the ASCII table max char decimal number is 127, so any char that is greater than 127 will yield unexpected results.

4. C++ string functions

a. The project requires use of the std::string class and its functions.

b. std::string length functions returns an integer representing the length.

c. std::string at function takes in an integer representing the char placement in the string and returns that char.

d. Attached to the project will be some sample code demonstrating the std::string functions needed.

5. The project requires one files to be turned in - password.cpp (the source code of your Password program)

6. Be sure to follow the Programming Project Submission Instructions posted by your instructor on the elearning site. The submission requirements are part of the grading for this assignment.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>
#include<string>
using namespace std;
bool isValidPassword (string);
bool isValidKey(int);
string encrypt(string,int);
int main()
{
   string password;
   int key;
   while(true)
   {
       cout<<"Enter a password: ";
       cin>>password;
       if(isValidPassword(password))
           break;
       cout<<"The password must be at least 8 characters long."<<endl<<endl;
   }
   while(true)
   {
       cout<<"Enter a key: ";
       cin>>key;
       if(isValidKey(key))
           break;
       cout<<"The key must be between 1 and 10, you entered "<<key<<"."<<endl<<endl;
   }
   cout<<"\n\nYour password is "<<password<<" the encrypted version of your password is "<<encrypt(password,key)<<" with a key of "<<key<<".\n"<<endl;
}

bool isValidPassword(string pass)
{
   return pass.length()>=8;
}
bool isValidKey(int key)
{
   return (key>=1 && key<=10);
}
string encrypt(string pass,int key)
{
   string encryptedCipher="";
   for(int i=0;i<pass.length();i++)
   {
       int value=pass[i]+key;
       if(value>122)
           value=value-122+33-1;
       encryptedCipher+=value;
   }
   return encryptedCipher;
}

output

- x C. C:\WINDOWS\system32\cmd.exe Enter a password: letmeinz Enter a key: 6 Your password is letmeinz the encrypted version

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
1. Write a C++ program called Password that handles encrypting a password. 2. The program must...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1.     This project will extend Project 3 and move the encryption of a password to a...

    1.     This project will extend Project 3 and move the encryption of a password to a user designed class. The program will contain two files one called Encryption.java and the second called EncrytionTester.java. 2.     Generally for security reasons only the encrypted password is stored. This program will mimic that behavior as the clear text password will never be stored only the encrypted password. 3.     The Encryption class: (Additionally See UML Class Diagram) a.     Instance Variables                                                i.     Key – Integer...

  • C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or...

    C program (Not C++, or C#) Viginere Cipher 1)Ask the user if we are encrypting or decrypting. 2) Ask the user to enter a sentence to be transformed. 3) Ask the user to enter a sentence that will be used as the encryption or decryption key. 4) The sentences (array of characters) should end with a NULL terminator '\0'. 5) The range of values will be all printable characters on the ASCII chart starting with a SPACE - Value 32,...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Write the Code in C program. Create a random password generator that contains a user-specified number...

    Write the Code in C program. Create a random password generator that contains a user-specified number of characters. Your program should prompt the user for the desired length of the password. Length of password: To create your password, use the random number generator in the stdlib.h C library. To generate random numbers, you will need the srand() and rand() functions. srand(seed) is used to "seed" the random number generator with the given integer, seed. Prompt the user for the seed...

  • Design a Java program to reset a user's password. The password must consist of exactly six...

    Design a Java program to reset a user's password. The password must consist of exactly six characters, of which one must be a digit, one must be an uppercase letter, and one must be a lowercase letter. Tell the user if the password is correct or if incorrect tell them what is wrong with it. For example, you could say: "Not valid! the password must have 6 characters! Goodbye!" Can't contain loops. Using Boolean, String, Int, char

  • Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher...

    Write a program that implements an elementary bit stream cipher. An elementary level bit stream cipher is an encryption algorithm that encrypts 1 byte of plain text at a time. This one uses a given 4-bit bit pattern as the key. The size of the encrypted message that we want to be able to send has a maximum length of 200 characters. You must: 1. prompt the user to input the clear text to be encrypted. You must use printf()...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT