Question

In: Computer Science

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or...

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet.

Given an arbitrary cipher text file, you need to write a C++ program to find out the value of the shift going down the alphabet and decrypt the cipher text to plaintext. You must not hard code the cipher text nor any shift values in your program. Test your program with the sample cipher text below (only the alphabetic letters are changed):

Ty ncjaezrclasj, pyncjaetzy td esp acznpdd zq eclydqzcxtyr tyqzcxletzy (cpqpccpo ez ld awltyepie) fdtyr ly lwrzctesx (nlwwpo ntaspc) ez xlvp te fycplolmwp ez lyjzyp pinpae eszdp azddpddtyr dapntlw vyzhwporp, fdflwwj cpqpccpo ez ld l vpj. Esp cpdfwe zq esp acznpdd td pyncjaepo tyqzcxletzy (ty ncjaezrclasj, cpqpccpo ez ld ntaspcepie).

Solutions

Expert Solution

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

// Used to shift the alphabets in an character array

void shift_char_array(char array[], int shift)

{

char * arr = (char *) malloc (sizeof(array));

      int i;

      for(i = 0; i < strlen(arr); i++)

      {

// Shift the alphabets if it is a letter or a capitalised letter

if(array[i] >= 'a' && array[i] <= 'z')

arr[i] = 'a' + (array[i] - 'a'+ shift) %26;

else if(array[i] >= 'A' && array[i] <= 'Z')

arr[i] = 'A' + (array[i] - 'A' + shift) % 26;

else

arr[i] = array[i];

      }

return arr;

}

// Fuction to take input string

char * getmessage()

{

char * data = (char *) malloc(1000);

      printf("Enter a String:\t");

      scanf("%[^\n]s", data);

return data;

}

int main()

{

char * data = getmessage();

// Print every shifted message

for(int i = 0; i < 26; i++)

{

char * shifted_msg = shift_char_array(data, i);

printf("text with shift %d", i);

printf("%s\n", shifted_ms);

free(shifted_msg);

}

// Further more you can find all of the above words in an dictionary to determine the exact shift or select manually which of the above 26 text is right

return 0;

}


Related Solutions

In cryptography, Caesar cipher is one of the simplest encryption techniques. The key idea of this...
In cryptography, Caesar cipher is one of the simplest encryption techniques. The key idea of this method is to replace each plaintext letter with one fixed number of places down the alphabet. Below is an example with a shift of three: Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz Cipher: DEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABC To cipher a string, ‘A’ is replaced by ‘D’, ‘B’ is substituted by ‘E’, and so on. To decode a string, ‘A’ is replaced by ‘x’, etc. By using python with vs code: Write a...
A Caesar cipher encrypts a message by shifting letters in the alphabet. For example, a shift...
A Caesar cipher encrypts a message by shifting letters in the alphabet. For example, a shift of 4 maps 'a' to 'e' and maps 'p' to 't' Here is a famous line from Shakespeare encrypted with a shift of 4: 'vq dg qt pqv vq dg: vjcv ku vjg swguvkqp.' (a) Write a program that takes as input a string to be encrypted and an integer encrpytion shift (such as 4 mentioned earlier), and prints the encrypted string. [Hint: zip()...
Julius Caesar used one of the earliest known cipher systems to communicate with Cicero in Rome...
Julius Caesar used one of the earliest known cipher systems to communicate with Cicero in Rome while he was conquering Europe. Caesar knew that there was a very high risk of ambush or spies when sending messages; therefore, he developed a cryptographic system now known as the Caesar cipher. Primary Task Response: Please provide a detailed response to the below to include specific details and examples. What is the Caesar ROT3 Cipher? How does it work? Although the Caesar cipher...
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 :)
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed...
The mathematical expression of the encryption and decryption process of a Caesar cipher algorithm is expressed respectively as: c=Ep, k=p+k%26                                                                                                                         (1) p=Dc,k=c-k%26                                                                                                                         (2) Please do the following: Write at least two paragraphs to explain the principle of operation of the algorithm. For a full credit, your explanation must show the architectural diagram of the encryption and decryption process. Write a program to implement the Caesar algorithm Code must have two functions; encryption and decryption Test your codes with p as...
Subject : Cryptography (computer science) After reading chapter 3, Analyze the history of Caesar Cypher and...
Subject : Cryptography (computer science) After reading chapter 3, Analyze the history of Caesar Cypher and its impact on cryptography. The initial post should be at least 400 words.
research the Caesar Cipher, and document your research in 2-3 pages in a Word document with...
research the Caesar Cipher, and document your research in 2-3 pages in a Word document with illustrations in your document and provide an example of how the Caesar Cipher works while encrypting and decrypting a sample message. Also, add its history and its internal workings. Summary of the areas to complete: - Research the Caesar Cipher. - Show its Encryption Method in details. - Show its Decryption Method in details. - Describe its History and what it was used for....
Caesar Cipher Encryption] Write a method that takes two parameters: A parameter of type str and...
Caesar Cipher Encryption] Write a method that takes two parameters: A parameter of type str and a parameter of type int. The first parameter is the plaintext message, and the second parameter is the encryption key. The method strictly does the following tasks: a. Convert the string into a list (let us refer to it as lista). An element in the generated list is the position of the corresponding letter in the parameter string in the English alphabet. Example: ‘C’...
Write an Java/C program code to perform known-plaintext attack on Permutation Cipher. This program can be...
Write an Java/C program code to perform known-plaintext attack on Permutation Cipher. This program can be used to determine the length of the permutation m and the key permutation.
(a) Briefly describe what is meant by the word cryptography. (b) Briefly describe the Vigenere cipher,...
(a) Briefly describe what is meant by the word cryptography. (b) Briefly describe the Vigenere cipher, including a discussion of the encryption and decryption processes. (c) Describe what is meant by a ‘Feistel Cipher’. (d) DES includes S-boxes as part of its encryption and decryption steps. Each of eight S-boxes is a fixed 4 × 16 array, whose entries come from the integers 0, 1, . . . , 15. Describe in detail how DES transforms a 48-bit string into...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT