subject

In this assignment you will write a chunk based decryption program. Download and save the attached code to your local computer. The code contains additional remarks about the system, please read them and the prompts below. Using Visual Studio, compile and execute the code. Study the code and make the following changes: Implement display_chunks(). Loop over each string in the array of message chunks (strings) and print it. Do not print the first character in each string since it is only used to store the order of the chunks. (Hint: use pointer arithmetic to skip a character.) [5 points]
Implement decrypt_chunks(). Loop over each string in the array and shift the characters in it by subtracting DECRYPTION_SHIFT value from them. Use pointer arithmetic to access individual characters but array access to the strings. Remember that C-style strings have a null terminator at the end. Do not apply the shift to the terminator. (Hint: to avoid doing double pointer arithmatic, save a char* pointer to the active chunk[?] in the outer loop but before the inner loop. Then the inner loop is only concerned with a single array of characters rather than an array of strings.) [10 points]
Implement sort_chunks(). Using your favorite sorting algorithm (we suggest selection sort), sort the array containing the message chunks. Sort based on the first character in the chunk - it will always be a number. We provide a swap_strings function that you may use. Example usage: swap_strings(chunks[0], chunks[1]) will swap the contents of the first and second string. [20 points]
//includes
#include
#include
//macros: constants
#define CHUNK_LENGTH 20+1 //each chunk has twenty characters, we add 1 so
//there is space for the null terminator.
#define NUMBER_OF_CHUNKS 4 //the message is spread across 4 chunks.
#define DECRYPTION_SHIFT 5 //this is the ASCII table shift used for decryption.
//forward declarations
void sort_chunks();
void decrypt_chunks();
void display_chunks();
char chunks[NUMBER_OF_CHUNKS][CHUNK_LENG TH];
int main()
{
//copy message into memory.
strcpy(chunks[0], "2~b%tzlmy%yt%gj%jstz");
strcpy(chunks[1], "1;95P%`tk%rfns%rjrtw");
strcpy(chunks[2], "4nqq%Lfyjx");
strcpy(chunks[3], "3lm%ktw%fs~gti~3%2%G");
//the format of a chunk is a single number indicating its order in overall
//message followed twenty encrypted characters.
//reorder chunks in message by sorting them based on the first digital
//they contain. looking above, one can see they are currently in the order
//2, 1, 4, 3 but should be ordered 1, 2, 3, 4.
sort_chunks();
//shift the characters in the message to produce the original characters.
decrypt_chunks();
//display the decrypted message.
display_chunks();
//pause the screen, uncomment if needed
//fflush(stdin);
//getchar();
return 0;
}
//given two strings, swaps their contents in memory.
void swap_strings(char* x, char* y)
{
//create a temporary holding place for the data so we don't lose it.
char temp[CHUNK_LENGTH];
strcpy(temp, x);
strcpy(x, y);
strcpy(y, temp);
}
//sorts the strings the global chunks variable by the first character they contain.
void sort_chunks()
{
//TODO: Implement sort_chunks(). Using your favorite sorting algorithm (we
// suggest selection sort), sort the array containing the message chunks.
// Sort based on the first character in the chunk - it will always be a
// number. We provide a swap_strings function that you may use. Example
// usage: swap_strings(chunks[0], chunks[1]) will swap the contents of
// the first and second string. [20 points]
}
//for each string in the global chunks variable, shifts the characters in it by
//DECRYPTION_SHIFT.
void decrypt_chunks()
{
//TODO: Implement decrypt_chunks(). Loop over each string in the array
// and shift the characters in it by subtracting DECRYPTION_SHIFT value
// from them. Use pointer arithmetic to access individual characters but
// array access to the strings. Remember that C-style strings have a null
// terminator at the end. Do not apply the shift to the terminator.
// (Hint: to avoid doing double pointer arithmatic, save a char* pointer
// to the active chunk[?] in the outer loop but before the inner loop.
// Then the inner loop is only concerned with a single array of
// characters rather than an array of strings.) [10 points]
}
//displays the strings in the global chunks variable
void display_chunks()
{
//TODO: Implement display_chunks(). Loop over each string in the array of
// message chunks (strings) and print it. Do not print the first
// character in each string since it is only used to store the order of
// the chunks. (Hint: use pointer arithmetic to skip a character.) [5 points]
}

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, littleprinces
Your task this week is to write a very simple spam classifier in python. it will classify messages as either spam (unwanted) or ham (wanted). the program will have a set of spam_words, words that are known to appear in spam messages. that set is included in the template file spam. pypreview the document. you will also define a spam threshold which reflects the allowed percentage of spam words in the message. you'll compute a 'spam indicator', which is the ratio of spam words to the total number of unique words in the message. if the spam indicator exceeds the spam threshold, the message is classified as spam. otherwise it is classified as ham. we'll assume that the spam threshold is a constant and has a value of 0.10. your program will prompt the user for a message and then will print the corresponding spam indicator with two decimal digits and the corresponding classification (spam or ham). the program will be case insensitive. the spam words are detected whether they are in lower case or upper case or mixed case. each word, spam or not, is counted once (even if it appears multiple times in the message.) the program will remove punctuation from the message before identifying the words and computing the spam indicator. for example '! ' must be identified as the spam word 'now'.
Answers: 3
image
Computers and Technology, 22.06.2019 18:00, alexj29227405
Write a method named addall that could be placed inside the hashintset class. this method accepts another hashintset as a parameter and adds all elements from that set into the current set, if they are not already present. for example, if a set s1 contains [1, 2, 3] and another set s2 contains [1, 7, 3, 9], the call of s1.addall(s2); would change s1 to store [1, 2, 3, 7, 9] in some order. you are allowed to call methods on your set and/or the other set. do not modify the set passed in. this method should run in o(n) time where n is the number of elements in the parameter set passed in.
Answers: 2
image
Computers and Technology, 23.06.2019 15:30, yanicas
Hey so i was just trying out some game hacks so i took a paste from online and built it in my visual studio and then suddenly my computer was working or clicking on stuff on its own am i hacked?
Answers: 1
image
Computers and Technology, 23.06.2019 18:00, teamroper35
Which finger presses the h key on the keyboard? index finger on the left hand pinky finger on the right hand index finger on the right hand thumb on the left hand
Answers: 1
You know the right answer?
In this assignment you will write a chunk based decryption program. Download and save the attached c...

Questions in other subjects:

Konu
Mathematics, 16.10.2020 09:01