Question
Do this using the C language. show me the code being executed and also copy and paste the code so i can try it out for myseld
Instructions A cipher is mirrored algorithm that allow phrases or messages to be obfuscated (ie. scrambled). Ciphers were a
progf skeleton 11 #include stdio.h> 12 #include <stdlib.h> 13 char shirt_letter (char letter, int shirt_amount) 15 char caesa
progl skeletons new position - 26 new position new position - 97 + new position: 85 86 37 return new_position; 89 90 91 It is
0 0
Add a comment Improve this question Transcribed image text
Answer #1

prog6_skeleton.c

#include<stdio.h>
#include<stdlib.h>
char shift_letter(char letter,int shift_amount);
char* caesar_encode(char* message,int message_size,int caesar_shift);
char* caesar_decode(char* encoded_message,int message_size,int caesar_shift);

int main(){

  
   char message[] ="It's a great day to be a bulldog!";
   int size = sizeof(message)/sizeof(message[0]);
  
   int shift_amount = 6;
  
   char *encoded_message=caesar_encode(message,size,shift_amount);
  
   char *decoded_message=caesar_decode(encoded_message,size,shift_amount);
  
   printf("Original message: %s\n",message);
  
   printf("Encoded message: %s\n",encoded_message);
  
   printf("Decoded message: %s\n",decoded_message);
  
   free(encoded_message);
   free(decoded_message);
}

char shift_letter(char letter,int shift_amount){
   int char_index= (int)letter;
  
   if(char_index>=97 && char_index <=122){
      
       int new_posititon=(char_index-97)+shift_amount;
      
       if(new_posititon>=0){
           new_posititon%=26;
           new_posititon=97+new_posititon;
       }else{
      
           new_posititon=26+new_posititon;
           new_posititon=97+new_posititon;
       }
      
       return new_posititon;
   }
  
   else if(char_index>=65 && char_index <=90){
      
       int new_posititon=(char_index-65)+shift_amount;
      
       if(new_posititon>=0){
      
           new_posititon%=26;
           new_posititon=65+new_posititon;
       }else{
      
           new_posititon=26+new_posititon;
           new_posititon=65+new_posititon;
       }
      
       return new_posititon;
   }
   else{

       return letter;  
   }
}

char* caesar_encode(char* message,int message_size,int caesar_shift){

   char* new_message = (char*)malloc(message_size);
   int i;
   for(i=0;i<message_size;i++){
       new_message[i]=shift_letter(message[i],caesar_shift);
   }
  
   return new_message;

}

char* caesar_decode(char* encoded_message,int message_size,int caesar_shift){

   char* new_message = (char*)malloc(message_size);
  
   int i;
   for(i=0;i<message_size;i++){
       new_message[i]=shift_letter(encoded_message[i],-caesar_shift);
   }
  
   return new_message;

}

Output:

original message: Its a great day to be a bulldog! Encoded message: Ozy g mxkgz jge zu hk g harrjum! Decoded message: Its

Add a comment
Know the answer?
Add Answer to:
Do this using the C language. show me the code being executed and also copy and...
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
  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • Q16-Decoder (0.5 points) Write a code block to decode strings from secret encodings back to reada...

    Q16-Decoder (0.5 points) Write a code block to decode strings from secret encodings back to readable messages. To do so: Initialize a variable called decoded as an empty string . Use a for loop to loop across all characters of a presumed string variable called encoded Inside the loop, convert the character to another character o Get the unicode code point for the character (using ord o Subtract the value of key to that code point (which should be an...

  • original letter (input) Fig. 12: Graph of a code In problems 15 18, rules are given for encoding a 6 letter alphabet. F...

    original letter (input) Fig. 12: Graph of a code In problems 15 18, rules are given for encoding a 6 letter alphabet. For each problem: (a) Is the encoding rule a function? (b) Is the encoding rule one-to-one? (c) Encode the word "bad. (d) Write a table for decoding the encoded letters and use it to decode your answer to part (c). (e) Graph the encoding rule and the decoding rule. (Fig. 12 shows the graphs for the code in...

  • Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...

    Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program is required that allows a user to encode text using any of three possible ciphers. The three ciphers you are to offer are: Caesar, Playfair and Columnar Transposition. • The program needs to loop, repeating to ask the user if they wish to play with Caesar, Playfair or Columnar Transposition until the user wishes to stop the program. •For encoding, the program needs to...

  • MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...

    MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an abstract class that will be the base class for other two classes. It should have: A...

  • In C++ Having heard you have gotten really good at programming, your friend has come to...

    In C++ Having heard you have gotten really good at programming, your friend has come to ask for your help with a simple task. She would like you to implement a program to encrypt the messages she exchanges with her friends. The idea is very simple. Every letter of the alphabet will be substituted with some other letter according to a given key pattern like the one below. "abcdefghijklmnopqrstuvwxyz" "doxrhvauspntbcmqlfgwijezky" // key pattern For example, every 'a' will become a...

  • Can someone please help me for this assignment? Cryptography — the science of secret writing —...

    Can someone please help me for this assignment? Cryptography — the science of secret writing — is an old science; the first recorded use was well before 1900 B.C. An Egyptian writer used previously unknown hieroglyphs in an inscription. We will use a simple substitution cypher called rot13 to encode and decode our secret messages. ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in...

  • cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...

    cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...

  • Python program Use the provided shift function to create a caesar cipher program. Your program s...

    python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

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