Question

There is a simple encryption scheme that is called “Caesar Cipher”. In a “Caesar Cipher”, the...

There is a simple encryption scheme that is called “Caesar Cipher”. In a “Caesar Cipher”, the letters in a message are replaced by the letters of a “shifted” alphabet. A “Caesar Cipher” encodes a message by shifting each letter in a message by a constant amount of k. If k is 5, A becomes F, B becomes G, C becomes H and so on.
Let's use Queue to encode and decode the encrypt message. Set k as -5 and decipher the following codes by using Linear Queue.
Encrypt message: H T S L W F Y Z Q F Y N T S X
NOTE: Assume the following functions have been implemented in the Queue class. You may USE or CALL any of these functions.
• void Enqueue(char kod);
• void Dequeue();
• char QueueFront();
• char QueueRear();
• bool Empty();
• bool Full();
a. Write the code snippet for main() function to decode the encrypt message. Then, insert the decoded message into the Queue and display the message from the Queue.
The encrypt message is stored as the following:- char code[16] = "HTSLWFYZQFYNTSX";

b. State the result of your output.

I need the code in C++

Homework Answers

Answer #1

#include <iostream>
#include <cstdlib>
#include<cstring>
using namespace std;

// define default capacity of the queue
#define SIZE 20

// Class for queue
class queue
{
   char *arr;     // array to store queue elements
   int capacity;   // maximum capacity of the queue
   int front;     // front points to front element in the queue (if any)
   int rear;     // rear points to last element in the queue
   int count;     // current size of the queue
  
public:
   queue(int size = SIZE);   // constructor
   ~queue();                   // destructor

   void dequeue();
   void enqueue(char x);
   bool Empty();
   bool Full();
   char QueueFront();
};

// Constructor to initialize queue
queue::queue(int size)
{
   arr = new char[size];
   capacity = size;
   front = 0;
   rear = -1;
   count = 0;
}

// Destructor to free memory allocated to the queue
queue::~queue()
{
   delete[] arr;
}

// Utility function to remove front element from the queue
void queue::dequeue()
{
   // check for queue underflow
   if (Empty())
   {
       cout << "UnderFlow\nProgram Terminated\n";
       exit(EXIT_FAILURE);
   }

  
   front = (front + 1) % capacity;
   count--;
}

// Utility function to add an item to the queue
void queue::enqueue(char item)
{
   // check for queue overflow
   if (Full())
   {
       cout << "OverFlow\nProgram Terminated\n";
       exit(EXIT_FAILURE);
   }


   rear = (rear + 1) % capacity;
   arr[rear] = item;
   count++;
}


// Utility function to check if the queue is empty or not
bool queue::Empty()
{
   return (count == 0);
}

char queue::QueueFront()
{
   if (Empty())
   {
       cout << "UnderFlow\nProgram Terminated\n";
       exit(EXIT_FAILURE);
   }
   return arr[front];
}

// Utility function to check if the queue is full or not
bool queue::Full()
{
   return (count == capacity);
}

//Required Part

int main()
{
   // create a queue of capacity 5
   char code[16] = "HTSLWFYZQFYNTSX";
   queue q;
   for(int i=0;i<strlen(code);i++)
   {
       q.enqueue(code[i]);
   }
   queue q1;
   for(int i=0;i<strlen(code);i++)
   {
       char c=q.QueueFront()-5;
       q.dequeue();
       if(c>'Z')
       {
           int a = c-'Z';
           c = 64+a;
       }
       if(c<'A')
       {
           int a = 'A'-c;
           c = 90+a;
       }
       q1.enqueue(c);
   }
   while(!q1.Empty())
   {
       cout<<q1.QueueFront();
       q1.dequeue();
   }
  
   return 0;
}

//Output

Know the answer?
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
Similar Questions
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 by a letter chosen to be n places later in the alphabet. The number of places, n, is called the cipher key. For example, if...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is...
USE C programming (pls label which file is libcipher.h and libcipher.c) Q4) A shift cipher is one of the simplest encryption techniques in the field of cryptography. It is a cipher in which each letter in a plain text message is replaced by a letter some fixed number of positions up the alphabet (i.e., by right shifting the alphabetic characters in the plain text message). For example, with a right shift of 2, ’A’ is replaced by ’C’, ’B’ is...
Use python language please #One of the early common methods for encrypting text was the #Playfair...
Use python language please #One of the early common methods for encrypting text was the #Playfair cipher. You can read more about the Playfair cipher #here: https://en.wikipedia.org/wiki/Playfair_cipher # #The Playfair cipher starts with a 5x5 matrix of letters, #such as this one: # # D A V I O # Y N E R B # C F G H K # L M P Q S # T U W X Z # #To fit the 26-letter alphabet into...