Question

In: Computer Science

USE C++: Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to...

USE C++: Encryption and Decryption are two cryptographic techniques. Encryption is used to transform text to meaningless characters, and decryption is used to transform meaningless characters into meaningful text. The algorithm that does the encryption is called a cipher. A simple encryption algorithm is Caesar cipher, which works as follows: replace each clear text letter with a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if the cipher key is 3, the clear text“HELLO THERE” becomes “KHOOR WKHUH”.Here, we restrict ourselves to encrypting/decrypting digits (0...9), lowercase, and uppercase alphabetic characters. As you know from the ASCII table, the set of these characters correspond to the integers 48to 122.Hint: The following formula can be used to encrypt a character C using the Caesar cipher algorithm: E = (C –‘0’ + k) % 75+ ‘0’ [where k is the cipher key]You need to figure out the formula for decrypting text on your own.NOTE: Use cipher key = 7.Write a C++ program for encrypting and decrypting a given string. Since this program performs two different functionalities (encryption and decryption), prompt the user to select the type of cryptographic technique as shown below: Welcome to Cryptographic Techniques ProgramPlease enter your selection:1. Encrypt2. DecryptWhen the user selects 1 or 2, s/he will be asked to specify an input and output message. Here is an example: Assume that the user enters the following message: HOW ARE YOU DOING? If the user selects to encrypt the message (i.e. option 1), the program will encrypt the original message and outputs an encrypted text. If the user selects to decrypt a message (i.e. option 2), the program will decrypt the encrypted text and outputs the decrypted text on the screen. The program should give the user the option of whether to continue with encrypting/decrypting messages (i.e. entering the letter ‘C’) or exit the program (i.e. entering the letter‘E’).

Solutions

Expert Solution

Program:

#include<string.h>
#include "stdio.h"
#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;

//Note: we are using gets hence used char array in the program wherever needed

//function that will be converting the plain text to the cipher text
//default value of k is set to be 7
void encryption(int k=7){
    //will hold the plain text, user would enter
    char plain_text[100];
    //will hold the converted cipher text
    string cipher_text;
    //will hold ascii value for each character
    int c;
    //will hold the converted ascii value
    int e;

    //asking user to enter plain text
    cout<<"\n\nEnter the plain text: ";
    gets(plain_text);
    //traversing in the plain_text and converting to cipher text
    for (int i=0; plain_text[i] != '\0'; i++){
        c = int(plain_text[i]);

        e = (c - '0' + k )%75 + '0';

        cipher_text += char(e);
    }

    //printing the converted cipher text
    cout<<"\nCipher text is: "<<cipher_text;
}

//function that will be converting the cipher text to the plain text
//default value of k is set to be 7
void decryption(int k=7){
    //will hold the cipher text, user would enter
    char cipher_text[100];
    //will hold the converted plain text
    string plain_text;
    //will hold ascii value for each character
    int c;
    //will hold the converted ascii value
    int e;

    //asking user to enter plain text
    cout<<"\n\nEnter the cipher text: ";
    gets(cipher_text);
    //traversing in the cipher_text and converting to plain text
    for (int i=0; cipher_text[i] != '\0'; i++){
        c = int(cipher_text[i]);

        e = (c - '0' - k )%75 + '0';    //notice '-' in the formula

        if (c>=48 && c<=(48+k-1))
            e = (c - '0' - k )%75 + 75 + '0';   // because of negative value after mod

        plain_text += char(e);
    }

    //printing the converted cipher text
    cout<<"\nCipher text is: "<<plain_text;

}
int main(){

    char select[2] = "C";    //"C" means user will continue entering values
    int selection;           //will hold user selected encryption or decryption

    //welcome message
    cout<<"\nWelcome to Cryptographic Techniques Program";
    //code run until user is entering 'C'
    while (1){

        //asking user's choice
        cout<<"\n\nPlease enter your selection: ";
        cout<<"\n1. Encrypt";
        cout<<"\n2. Decrypt\n";
        cin>>selection;
        cin.ignore(); //^^this is necessary for handling buffer

        //based upon the user selection, we'll perform the encryption or decryption
        switch(selection){
            case 1: encryption();
                break;
            case 2: decryption();
                break;
            default: cout<<"\nYou have entered the wrong choice!!";
                break;
        }

        //asking the user to continue or exit
        cout<<"\n\nWant to continue encrypting/decrypting?";
        cout<<"\nPress 'C' to continue and 'E' to exit\n";
        cin>>select;

        if(strcmpi(select, "C") != 0)
            exit(0);

    }

    return 0;
}

Output:

1.

2.


Related Solutions

We like to apply text encryption and decryption as follows. In text encryption, for each letter...
We like to apply text encryption and decryption as follows. In text encryption, for each letter and numeric character in the plaintext (i.e., a-z, A-Z and 0-9), it is “shifted” a certain number of places down the alphabet or numbers. For example, assuming a shifted key offset of 3 is used, ‘A’ would be substituted by ‘D’, ‘B’ would become ‘E’, and so on. Similarly, ‘0’ would become ‘3’ and so on. Note that wrap-around will be applied at the...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means...
My question below Write a complete program that performs encryption/decryption of a text file. Encryption means you need to scramble the words of a file to become secure. Decryption means you need to apply some rules to an encrypted file in order to find the original file with its original content. An example of encryption is to replace each letter in a file with its consecutive letter in the alphabet. Therefore, ‘a’ is replaced by ‘b’, ‘b’ is replaced by...
In addition to cryptographic techniques, identify and explain the suite of techniques that are increasingly used...
In addition to cryptographic techniques, identify and explain the suite of techniques that are increasingly used to provide authentication to hospital information systems.
write a C program which performs encryption and decryption of a message
write a C program which performs encryption and decryption of a message
use C++ You will implement the following encryption and decryption functions/programs for the Caesar cipher. Provide...
use C++ You will implement the following encryption and decryption functions/programs for the Caesar cipher. Provide the following inputs and outputs for each function/program: EncryptCaesar Two inputs: A string of the plaintext to encrypt A key (a number) ▪ For the Caesar cipher: This will indicate how many characters to shift (e.g. for a key=3, A=>D, B=>E, ..., X=>A, Y=>B, Z=>C). Note that the shift is circular. One output: ◦ A string of the ciphertext or codeword DecryptCaesar Two inputs:...
What encryption/decryption and hashing algorithms are used in PGP and how are they used? write at...
What encryption/decryption and hashing algorithms are used in PGP and how are they used? write at least 500 words of your explanation and reference.
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The...
In C++, write a program to implement the Caesar Cipher for both encryption and decryption. The program should be able to handle different keys by deciding the key at run time. Thank you :)
Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A...
Write a program in c++ that can perform encryption/decryption. In the following let the alphabet A be A={A, a, B, b, . . ., “ ”, “.”,“’ ”}. The encoding is A→0, a→1, B→2, b→4, . . ., Z→50, z→51, “ ”→52, “.”→53 and “’”→54.
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...
Introduction to Cryptographic Methods - 61314 COURSE PROJECT CHOICES AND TECHNOLOGY INTRODUCTION Encryption—Symmetric Techniques Substitution Ciphers...
Introduction to Cryptographic Methods - 61314 COURSE PROJECT CHOICES AND TECHNOLOGY INTRODUCTION Encryption—Symmetric Techniques Substitution Ciphers Transposition Ciphers Classical Ciphers: Usefulness and Security The Data Encryption Standard (DES) The Advanced Encryption Standard (AES) Confidentiality Modes of Operation Key Channel Establishment for Symmetric Cryptosystems
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT