Question

In: Computer Science

In this lab you will be encrypting a message. It is a simple encryption described in...

In this lab you will be encrypting a message. It is a simple encryption described in the problem. To program it remember that the ASCII code for ‘A’ is 65 and the other capital letters are in order 66, 67, 68, … The ASCII code for ‘a’ is 97 and the lowercase continues 98, 99, and so on. The hint is that a if a user type in a char with an ASCII code between 65 and 90, or 97 and 122 then add 5 and print out the result. Otherwise, have a sequence of if-statements to encrypt the punctuation marks as given in the problem. Keep looping until the character typed in is a ‘#’ symbol.

1. Write a C++ program that encrypts a message. The program should read in a character, “encrypt” the character by giving the numeric place the character has in the alphabet then add 5. The program should then printout the encrypted message to the screen. The program should continue taking in characters until the user types in a # symbol. Punctuation should be handled as follows: . A , B ? C ! D. No other characters will be encrypted.

Solutions

Expert Solution

Following is the code for the problem:

#include<iostream>
using namespace std;
int main()
{
    cout<<"Enter a character; enter # to exit.\n";
    while(true)
    {
        char c;
        cin>>c;
        if(c=='#')
            break;
        cout<<"Encrypted message: ";
        if((c>=65&&c<=90)||(c>=97&&c<=122))
            cout<<((int)c+5)<<endl;
        else if(c=='.')
            cout<<"A\n";
        else if(c==',')
            cout<<"B\n";
        else if(c=='?')
            cout<<"C\n";
        else if(c=='!')
            cout<<"D\n";
        else
            cout<<"Invalid character.";
    }
    return 0;
}

Following are the outputs for sample inputs:


Related Solutions

Cryptography*** Let’s assume you do DES double encryption by encrypting a plaintext twice with K1 and...
Cryptography*** Let’s assume you do DES double encryption by encrypting a plaintext twice with K1 and K2 respectively. Is this method more secure than the regular single DES encryption? Please explain your reason.
Secret-Key Encryption Lab
Secret-Key Encryption Lab
write a C program which performs encryption and decryption of a message
write a C program which performs encryption and decryption of a message
Write a C program A simple method for encrypting data is that of ROT 13. The...
Write a C program A simple method for encrypting data is that of ROT 13. The method takes each latin letter of plain text and moves it to the next letter 13 times in latin alphabet (wrapping around if necessary). For those of you who are unaware the latin alphabet is the following a b c d e f g h i j k l m n o p q r s t u v w x y z This...
Draft a message about the news described Suppose you are an executive at a company that...
Draft a message about the news described Suppose you are an executive at a company that suddenly has to lay off 250 employees within three days or risk financial disaster. For months the company has been reassuring the employees that no one was going to be out of a job. You don’t want to appear impersonal or insensitive.
Your task is to write a C program which performs encryption and decryption of a message...
Your task is to write a C program which performs encryption and decryption of a message using the substitution cipher algorithm. Write a C program which performs encryption and decryption using the substitution cipher algorithm. Your program must be fully automated (ie: it does not take any interactive user input) and either encrypt or decrypt depending on the files which exist in the program’s directory. If message.txt exists your program should read that file, encrypt the contents, and write the...
Question 5: How public key encryption is used to ensure confidentiality of a message. Use a...
Question 5: How public key encryption is used to ensure confidentiality of a message. Use a diagram to explain.
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the...
Alice is sending message “HIDE” to Bob. Perform encryption and decryption using RSA algorithm, with the following information: parameters p=11,q=5, e=7 Present all the information that you will need to encrypt and decrypt only the first letter from text
Using randomized encryption, convert an AES and RSA message (m) with 128 bits into a secured...
Using randomized encryption, convert an AES and RSA message (m) with 128 bits into a secured version with an initialization vector (IV). Show how to encrypt (m) with secured AES.
Answer in python! 5.16 LAB: Cryptographic Hashing Algorithms Encrypting text allows us to encrypt and decrypt...
Answer in python! 5.16 LAB: Cryptographic Hashing Algorithms Encrypting text allows us to encrypt and decrypt the text using a special key. Another method of encrypting text / passwords is called hashing. Hashing uses special algorithms to 'scramble' text so that it is tougher to hack. The hash function can take numbers, letters, and symbols then uses one of the special algorithms to output scrambled text. The longer the output string, the harder to hack the data. The difference between...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT