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...
1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1) A company that wants to send data over the Internet will use an encryption program...
1) A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
1. A company that wants to send data over the Internet will use an encryption program...
1. A company that wants to send data over the Internet will use an encryption program to ensure data security. All data will be transmitted as four-digit integers. The application should read a four-digit integer entered by the user and encrypt it as follows:  Replace each digit with the remainder of the new value divided by 10 by adding 6 to the digit. Then replace the number in the first digit with the third, and the number in the...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT