Question

Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...

Caesar Cipher v3 Decription

Description A Caesar cipher is one of the first and most simple encryption methods. It works by shifting all letters in the original message (plaintext) by a certain fixed amount (the amounts represents the encryption key). The resulting encoded text is called ciphertext.

Example Key (Shift): 3 Plaintext: Abc Ciphertext: Def

Task Your goal is to implement a Caesar cipher program that receives the key and an encrypted paragraph (with uppercase and lowercase letters, punctuations, and spaces) and decrypt it.

Requirements Only letters must be decrypted, any other character must remain unchanged

Note: The whole paragraph is going to be given to you as a string (char array). Review the template code for more details.

//Code Given

#include <stdio.h>

#include <stdbool.h>

#include <string.h>

#include <ctype.h>

// ---------------------- DO NOT MODIFY THIS SECTION --------------------------------

#define MAX_PGRAPH_LENGTH 100

#define MAX_WORD_LENGHT 20

int main(void) {

// definitions

char plaintext[MAX_PGRAPH_LENGTH];

char ciphertext[MAX_PGRAPH_LENGTH] = "";

char input[MAX_WORD_LENGHT];

// read the key

int key;

scanf("Key: %d, ", &key);

// read text

scanf("Input: ");

while (true)

{

scanf("%s", input);

if (strlen(ciphertext) + strlen(input) + 1 > MAX_PGRAPH_LENGTH)

break;

strcat(ciphertext, input);

strcat(ciphertext, " ");

}

ciphertext[strlen(ciphertext) - 1] = '\0';

// ---------------------- -----------------------------------------------------------

/*

Your code goes here!

*/

// ---------------------- DO NOT MODIFY THIS SECTION --------------------------------

printf(" Key: %d\n", key);

printf(" Input: %s\n", ciphertext);

printf("Output: %s\n", plaintext);

// ---------------------- -----------------------------------------------------------

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
//Code Given

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

// ---------------------- DO NOT MODIFY THIS SECTION --------------------------------
#define MAX_PGRAPH_LENGTH 100
#define MAX_WORD_LENGHT 20

int main(void) {

        // definitions
        char plaintext[MAX_PGRAPH_LENGTH];
        char ciphertext[MAX_PGRAPH_LENGTH] = "";
        char input[MAX_WORD_LENGHT];

        // read the key
        int key;
        scanf("Key: %d, ", &key);

        // read text
        scanf("Input: ");
        while (true) {
                scanf("%s", input);
                if (strlen(ciphertext) + strlen(input) + 1 > MAX_PGRAPH_LENGTH)
                        break;

                strcat(ciphertext, input);
                strcat(ciphertext, " ");
        }

        ciphertext[strlen(ciphertext) - 1] = '\0';
        // ---------------------------------------------------------------------------------

        int len = strlen(ciphertext);
        //key = key % 26;
        for(int i=0; i<len; i++) {
                if(ciphertext[i] <= 'Z' && ciphertext[i] >= 'A') {
                        plaintext[i] = 'A' + (((int)(ciphertext[i] - 'A') - key + 26) % 26);
                } else if(ciphertext[i] <= 'z' && ciphertext[i] >= 'a') {
                        // if lower case letters
                        plaintext[i] = 'a' + (((int)(ciphertext[i] - 'a') - key + 26) % 26);
                } else {
                        // it is not alphabate.. do not decrypt
                        plaintext[i] = ciphertext[i];
                }
        }

        // ----------------------DO NOT MODIFY THIS SECTION-------------------------------

        printf("   Key: %d\n", key);
        printf(" Input: %s\n", ciphertext);
        printf("Output: %s\n", plaintext);

        // ---------------------- -----------------------------------------------------------

}

Hi. please find the complete code.. i have given code comments so that it is very easy for you to understand the flow. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!

saved share gcc version 4.6.3 Key: 4, kadjksanjd adsaj dsadjsa jdas jksndjnajskd j asjd sa dhjas djksa hd djhsa djsa djh ashd

Add a comment
Know the answer?
Add Answer to:
Caesar Cipher v3 Decription Description A Caesar cipher is one of the first and most simple...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text an...

    I need Help to Write a function in C that will Decrypt at least one word with a substitution cipher given cipher text and key My Current Code is: void SubDecrypt(char *message, char *encryptKey) { int iteration; int iteration_Num_Two = 0; int letter; printf("Enter Encryption Key: \n");                                                           //Display the message to enter encryption key scanf("%s", encryptKey);                                                                   //Input the Encryption key for (iteration = 0; message[iteration] != '0'; iteration++)                               //loop will continue till message reaches to end { letter = message[iteration];                                                      ...

  • This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following...

    This code should be Runnable on MARS (MIPS Assembler and Runtime Simulator) IDE Convert the following c code into mips #include <stdio.h> #include <string.h> char cipherText[200] = "anything"; int countNumberOfCharInCipher(char*); int countNumberOfCharInCipher(char* cText) { return strlen(cText);    } int countSpaces(int numberOfChar, char input[]) { int spaceCounter =0; for(int i=0; i < numberOfChar; i++) { if(input[i] == 32) spaceCounter++; } return spaceCounter; } void decrypt(int numberOfChar, int key, char * cipherText, char * plainText) { int j = 0; int i =0;...

  • Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is...

    Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php.   Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...

  • 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, and decrypt the...

  • Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption                     void SubEncrypt(cha...

    Question: Please Provide Comments on each Line of code explaining what the C Function is doing throughout the code. // Function used for substitution encryption                     void SubEncrypt(char *message, char *encryptKey) { int iteration = 0; printf("Enter Aphabet Encryption Key: \n"); scanf("%s", encryptKey);    for (iteration = 0; iteration < strlen(message); iteration++) { char letter = message[iteration]; if (letter >= 'A' && letter <= 'Z') {    letter = encryptKey[letter - 'A']; } message[iteration] = letter; } printf("CipherText message: %s\n", message); } //_________________________________________________________________________________________________________________________________________________...

  • Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D....

    Computer Science C++ Help, here's the question that needs to be answered (TASK D): Task D. Decryption Implement two decryption functions corresponding to the above ciphers. When decrypting ciphertext, ensure that the produced decrypted string is equal to the original plaintext: decryptCaesar(ciphertext, rshift) == plaintext decryptVigenere(ciphertext, keyword) == plaintext Write a program decryption.cpp that uses the above functions to demonstrate encryption and decryption for both ciphers. It should first ask the user to input plaintext, then ask for a right...

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

  • 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...

  • Using the website Repl.it Write a Java program that can perform the Caesar cipher for English...

    Using the website Repl.it Write a Java program that can perform the Caesar cipher for English messages that include both upper and lowercase alphabetic characters. The Caesar cipher replaces each plaintext letter with a different one, by a fixed number of places down the alphabet. The program should be able to shift a specific number of places based on the user's input number. For example Plaintext: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG. Ciphertext: QEBNRFZH YOLTK CLU GRJMP...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT