Question

In: Computer Science

A company that wants to send data over the Internet has asked you to write a...

A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then print the encrypted integer. Write a separate application that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number.

Solutions

Expert Solution

Code: java Encryption

import java.util.*;
class Encryption{
   public static void main(String args[]){
       Scanner s=new Scanner(System.in);
       System.out.print("Enter number: "); //asking integer from user.
       int n=s.nextInt(),e=0,i,r;
       for(i=1;i<=4;i++){
           r=(n%10)+7;
           e=(e*10)+(r%10);      //calculating encrypted integer
           n=n/10;
       }
       n=0;
       while(e>0){
           r=e%10;
           n=(n*10)+r;
           e=e/10;
       }
       System.out.println("The encrypted integer is "+n); //printing encrypted integer.

   }
}

Output:

Code: java Decryption

import java.util.*;
class Decryption{
   public static void main(String args[]){
       Scanner s=new Scanner(System.in);
       System.out.print("Enter encrypted integer: "); //asking encrypted integer from user.
       int n=s.nextInt(),e=0,i,r;
       for(i=1;i<=4;i++){
           r=(n%10)-7;
           e=(e*10)+(r+20)%10;      //calculating decrypted integer
           n=n/10;
       }
       n=0;
       while(e>0){
           r=e%10;
           n=(n*10)+r;
           e=e/10;
       }
       System.out.println("The original number is "+n); //printing original number.

   }
}

Output:


Related Solutions

A company that wants to send data over the Internet has asked you to write a...
A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be transmitted more securely. All the data is transmitted as four-digit integers. Your application should read a four-digit integer entered by the user and encrypt it as follows: Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first...
Your manager has asked you to put together a survey that you are to send to...
Your manager has asked you to put together a survey that you are to send to all employees regarding topics they would like to be trained on. Write at least 10 effective questions and add them to the survey Examples: What areas do you feel as though you have deficiencies within that you would benefit from additional training? What topics do your peers most frequently ask you questions regarding? These questions will be challenging to think of, but that is...
General Chemistry please write it by your own don't copy from the internet send it by...
General Chemistry please write it by your own don't copy from the internet send it by email [email protected] Analysis Based: [Any 2 in less than 200 words] 1. The sun emits a lot of heat and light, what kind of reaction happens in the sun. 2. List out 5 activities/phenomenon where you see the influence of chemistry your daily life 3. Has Chemistry benefitted Human Life? Support your view with 2 important incidents from history. 4. Research and write the...
JAVA - The Westfield Carpet Company has asked you to write an application that calculates the...
JAVA - The Westfield Carpet Company has asked you to write an application that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor(width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960. (12 X 10...
The accountant for a company wants you to check over his work as he has never...
The accountant for a company wants you to check over his work as he has never compiled a multi-step income statement before. He provides you with the following partial income statement beginning with operating expenses (NOT income from continuing operations): Net Sales                                                                                                         $4,500,000       Operating Expenses                                                                                         (1,500,000) Operating Income                                                                                            $3,000,000 Depreciation Expense                                                                                           (20,000) Extraordinary loss from tornado, unusual and infrequent                                               (750,000) Cost of Goods sold                                                                                               (170,000) Gain on Translation of foreign currency                                                                     ...
A researcher wants to examine the impact of internet use on heart rate. Students are asked...
A researcher wants to examine the impact of internet use on heart rate. Students are asked how much they used the internet the hour prior to beginning the study and then grouped into three categories( 31-60 minutes per hour, 1-30 minutes per hour, and no internet use.) The researcher then measured their heartbeat per minute. Assume a two-tailed test and .05 level of significance. Time N Mean Standard Deviation 31-60 mins 10 66.00 9.66092 1-30 mins 10 54.00 8.43274 no...
12. When you send someone an e-mail address, it travels across the Internet to the ____________________...
12. When you send someone an e-mail address, it travels across the Internet to the ____________________ e-mail server at your ISP, then to the incoming e-mail server at your recipient's ISP.
Over the next couple of weeks, you are asked to write a 700-900 word essay on...
Over the next couple of weeks, you are asked to write a 700-900 word essay on a biomedical ethics subject or event of your choosing, which in some way relates to one or more of the materials we have so far studied. It can be from your chosen course of study, an area of interest you have, or an experience you went through as a patient or caregiver. You will not be given a written assignment for the next two...
Write a program using interrupts to get data serially and send it to P2 while at...
Write a program using interrupts to get data serially and send it to P2 while at the same time Timer 0 is generating a square wave of 5 kHz. We've been basing our code on the Intel 8051 microntroller and assembly language.
How much money do you spend to send a single packet to the Internet? How much...
How much money do you spend to send a single packet to the Internet? How much money do you spend to send 1 billion packets to the Internet? Try to explain how do you get these numbers? Try to discuss whether it is a reasonable business model or not?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT