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 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 :)
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’...
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.
Problem 2: Caesar Cipher Decryption] Write a python method that takes two parameters: A parameter of...
Problem 2: Caesar Cipher Decryption] Write a python 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. Reverse the operations performed by the encryption method to obtain the plaintext message. The method’s header is as follows: def casesardecryption(s, key):
(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...
Cryptography: Using columnar cipher, find the plaintext and the key that generated this ciphertext: ykccjosaiawiekhriogrrlrni Keep...
Cryptography: Using columnar cipher, find the plaintext and the key that generated this ciphertext: ykccjosaiawiekhriogrrlrni Keep in mind that only letter j was used for padding. (Show your detailed work)
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the...
Programming Language C++ Encrypt a text file using Caesar Cipher. Perform the following operations: Read the console input and create a file. ['$' character denotes end of content in file.] Close the file after creation. Now encrypt the text file using Caesar Cipher (Use key value as 5). Display the contents of the updated file. #include <iostream> using namespace std; int main() { // write code here }
Binary file IO Suppose a file has been encrypted using the Caesar cipher as described above,...
Binary file IO Suppose a file has been encrypted using the Caesar cipher as described above, and you know the secret key. Write a program to decrypt (or decode) the file. Your program will prompt the user to enter an input file name for the encrypted file, an output file name for the unencrypted version of the input file, and the secret key. Create a DataInputStream for the input file and a DataOutputStreams for the output file. Next, read the...
1. Monoalphabetic substitution (using the Caesar Cipher tool right) Encipher (convert plaintext into ciphertext): meal times...
1. Monoalphabetic substitution (using the Caesar Cipher tool right) Encipher (convert plaintext into ciphertext): meal times  Decipher (convert ciphertext in to plaintext):  JR PHDQ JUHHQ 2. Polyalphabetic substitution (using the Vigenere Square in the lecture slide) Encipher: fall  Decipher:  VPX TWOKM
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT