Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//URGENT HELP // Code to work on #include #include #include #define MAX_LIMIT 100 int main(void){ /** * An c-string array of size 100 named message

image text in transcribedimage text in transcribed

//URGENT HELP

// Code to work on

#include #include #include #define MAX_LIMIT 100 int main(void){

/** * An c-string array of size 100 named message is declared below */ char message[MAX_LIMIT]; //asking user to enter the message to encode printf("Enter the message to encode "); fgets(message,MAX_LIMIT,stdin);

int i=0; int length = strlen(message)-1; char cipher[length-1]; /*iterating through the string message character by * character in for loop */ printf(" "); for(i = 0; i 0; j++) { bits[j] = temp % 2; temp = temp / 2; } bits[7] = 0; //prints the binary of given input from MSB TO LSB for(j = 7; j >= 0; j--) { printf("%d",bits[j]); } printf(" = %d ",value); /* flip the bits and calculate the value */ j=0; int flipBits[8]; int newValue = 0; //Reverse the input binary and stored in another array //And calculate the equivalent binary of reversed binary //Example to convert binary to decimal //if binary MSB is 1,then multiply with -1 //11010 : (-1*(2^4) + 1*(2^3) + 0*(2^2) + 1*(2^1) + 0*(2^0)) = -6 for(j = 0,k=7; j = 0; j--) { printf("%d", flipBits[j]); } printf(" = %d ",newValue); cipher[i] = (char)newValue; } printf("Cipher = \""); i = 0; //Displays the ascii code of reverse binary for(i = 0; i (3) The Nibble-Swap Cipher Copy your cipher2.c code to a file called cipher3.c and adjust cipher3.c so that it creates a cipher that takes each character of m and swaps the low 4 bits with the high 4 bits to get the cipher character. e.g., if m= "ABC", then the cipher is: "24", where 2 is not displayable ... as follows: "A' = 10 100 000 1 'B' = 0 1 0 0 0 0 1 0 'C' = 0 1 0 0 0 1117 000 10100 = 'O' 00 100 100 = '$' 00110100 = '4' Swap low 4 bits with high 4 bits Cipher is "$ 4" but it will display differently on the terminal window as $4 The code should create output that shows the binary representation of the characters and their ASCII codes and also shows the cipher characters in binary format and their ASCII codes. It should look as (3) The Nibble-Swap Cipher Copy your cipher2.c code to a file called cipher3.c and adjust cipher3.c so that it creates a cipher that takes each character of m and swaps the low 4 bits with the high 4 bits to get the cipher character. e.g., if m= "ABC", then the cipher is: "24", where 2 is not displayable ... as follows: "A' = 10 100 000 1 'B' = 0 1 0 0 0 0 1 0 'C' = 0 1 0 0 0 1117 000 10100 = 'O' 00 100 100 = '$' 00110100 = '4' Swap low 4 bits with high 4 bits Cipher is "$ 4" but it will display differently on the terminal window as $4 The code should create output that shows the binary representation of the characters and their ASCII codes and also shows the cipher characters in binary format and their ASCII codes. It should look as

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

ISBN: B01366W6DS, 978-0133058352

Students also viewed these Databases questions