Question

In: Computer Science

Your country is at war and your enemies are using a secret code to communicate. You...

Your country is at war and your enemies are using a secret code to communicate. You have managed to intercept a message that reads as follows: ,vtaNm a_"dabp!! The message is 16 characters long. The message is encrypted using the enemy’s secret code. You have just learned that the encryption algorithm is to take the original message, treat each group of 4 bytes like an integer, add a secret key to the integer, then copy the resulting number to the encrypted message treating it like four characters. For example, if the original string is “HI THERE” and the secret key is the number 2, then the algorithm would:

 Take the first four characters, which are the first four bytes, which are “HI T”.

 If these four bytes are typecast to a 4 byte int (the size of an int on most machines) then it has the value 1411402056.

 Add the secret key of 2 to the value resulting in the value 1411402058

 Typecast the 1411402058 back as a 4 character string, resulting in “JI T” (basically it just increases the leftmost character by 2 in the ASCII code)

The process is repeated for the next group of 4 characters, “HERE”:

 These four bytes are typecast to a 4 byte int which is the value 1163019592

 Add the secret key of 2 to the value resulting in the value 1163019594

 Typecast 1163019594 back as a 4 character string, resulting in “JERE” The entire encrypted string would be “JI TJERE”

In the case of ,vtaNm a_"dabp!! you have figured out that the secret key is a number between 1 and 500.

Write a function that decrypts an encrypted message using a key that input as a parameter. From main, call the function with numbers between 1 and 500 for the key, printing out the resulting decrypted text each time. When you hit the correct key you will get a message that makes sense and have cracked the code! You should implement your function/program with pointers that uses typecasting to map back and forth between (char *) and (int *) as appropriate. What is the secret key and the decrypted message?

Solutions

Expert Solution

UPDATE: converted to C++

Well commented program in C++:

#include<iostream>
#include<string.h>
using namespace std;

int main(){
    string encrpt_msg = ",vtaNm a_\"dabp!!";

    char curr_block[4];

    //looping for all secret keys 1 to 500
    for(int i = 1; i <= 500; i++){

         //decoding the msg for secret key i
        char decrpt_msg[16];

        //reading the encrpt_msg in blocks of 4

        for(int j = 1; j <= 16; j++){

            curr_block[(j - 1) % 4] = encrpt_msg[j - 1];

            //when we have a block of 4
            if(j % 4 == 0){

                //converting the block to int
                int *temp = (int*)curr_block;

                //subtracting secret key from int
                *temp = *temp - i;


                //converting int back to char

                char* temp1 = (char*)temp;
                for(int k = 0; k < 4; k++){
                    decrpt_msg[j - 4 + k] = temp1[k];
                }
            }
        }
        decrpt_msg[16] = '\0';
       cout<<"Key: "<<i<<"\tDecrypted msg: "<<decrpt_msg<<endl;

    }

    return 0;
}

Output:

The secret key is: 491

decrypted msg: Attack at dawn!!

If this helps you, do upvote as it motivates us a lot!


Related Solutions

C++ Your country is at war and your enemies are using a secret code to communicate....
C++ Your country is at war and your enemies are using a secret code to communicate. You have managed to intercept a message that reads as follows: ,vtaNm a_"dabp!! The message is 16 characters long. The message is encrypted using the enemy’s secret code. You have just learned that the encryption algorithm is to take the original message, treat each group of 4 bytes like an integer, add a secret key to the integer, then copy the resulting number to...
Whales communicate with one another using sound. What are the benefits of using sound to communicate...
Whales communicate with one another using sound. What are the benefits of using sound to communicate underwater? What are the costs?
Before the Civil War, the South was the wealthiest region in the country. After the war,...
Before the Civil War, the South was the wealthiest region in the country. After the war, it was the poorest, especially the cotton states of Georgia, Alabama, Mississippi, Louisiana and South Carolina. This poverty would remain characteristic of the region for more than a century. Discuss the reasons why the South fell into poverty and remained there for such a long time.
A) In your LAN, you want to allow the external host to communicate only with your...
A) In your LAN, you want to allow the external host to communicate only with your internal Telnet server (TCP / 23). External hosts are not allowed to establish TCP connection with other internal servers. Write the appropriate filtering rules for the security policy. [15 points] Required fields for the filtering rule: RuleID, SourceIP, DestIP, SourcePort, DestPort, Protocol, SYN, ACK, Action B) Assume that the firewall in question A) is a stateless firewall. Give an example of a packet that...
In your accounting career you will be required to analyse current accounting issues and communicate your...
In your accounting career you will be required to analyse current accounting issues and communicate your theoretical understanding to your professional colleagues and your clients. For this assignment assume that you are the senior accountant working for a major firm. Question 1 - 9 marks (1,500 words) The CEO has forwarded to you an interesting article and requires you to provide her with a deeper theoretical understanding of the issues discussed so that she can fully engage in the lively...
In your LAN, you want to allow the external host to communicate only with your internal...
In your LAN, you want to allow the external host to communicate only with your internal Telnet server (TCP / 23). External hosts are not allowed to establish TCP connection with other internal servers. Write the appropriate filtering rules for the security policy. [15 points] Required fields for the filtering rule: RuleID, SourceIP, DestIP, SourcePort, DestPort, Protocol, SYN, ACK, Action
A secret pass code is made of 6 letters none of which are repeated. What is...
A secret pass code is made of 6 letters none of which are repeated. What is the probability that the code starts with B?
CODE IN PYHTON Write a program which DECRYPTS the secret messages which are created by the...
CODE IN PYHTON Write a program which DECRYPTS the secret messages which are created by the ENCRYPT program which we went over in class. It should first prompt the user for the scrambled alphabet which was created by ENCRYPT (which you should be able to copy & paste from the preceeding program's run). It then should ask for the secret message. Finally, it outputs the unscrambled version. Note that there are exactly 26 characters input for the scrambled alphabet. All...
The code that creates this program using Python: Your program must include: You will generate a...
The code that creates this program using Python: Your program must include: You will generate a random number between 1 and 100 You will repeatedly ask the user to guess a number between 1 and 100 until they guess the random number. When their guess is too high – let them know When their guess is too low – let them know If they use more than 5 guesses, tell them they lose, you only get 5 guesses. And stop...
Your ability to communicate effectively as a business professional gives both you and your employer benefits...
Your ability to communicate effectively as a business professional gives both you and your employer benefits in
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT