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. Java version!

Solutions

Expert Solution

Thanks for the question, here are the two pogram that encrypt a number and another program that takes in the encrypted number and then decrypt back to the original number.

Here are the two classes -

=====================================================================

public class Encrypt {

    public static void encrypt(int number) {

        int firstDigit = number % 10;
        number = number / 10;
        int secondDigit = number % 10;
        number /= 10;
        int thirdDigit = number % 10;
        int fourthDigit = number / 10;

        int firstDigitRemainder = (firstDigit + 7) % 10;
        int secondDigitRemainder = (secondDigit + 7) % 10;
        int thirdDigitRemainder = (thirdDigit + 7) % 10;
        int fourthDigitRemainder = (fourthDigit + 7) % 10;
        System.out.println();

        int encryptedNumber = secondDigitRemainder * 1000 + firstDigitRemainder * 100 + fourthDigitRemainder * 10 + thirdDigitRemainder;

        System.out.println("Encrypted Number " + encryptedNumber);
    }




    public static void main(String[] args) {

        encrypt(1248);

    }
}

=====================================================================

public class Decrypt {

    public static void decrypt(int encrypted){

        int firstDigit = encrypted % 10;
        encrypted = encrypted / 10;
        int secondDigit = encrypted % 10;
        encrypted /= 10;
        int thirdDigit = encrypted % 10;
        int fourthDigit = encrypted / 10;

        int firstDigitDecrypted = firstDigit>=7?firstDigit-7:3+firstDigit;
        int secondDigitDecrypted = secondDigit>=7?secondDigit-7:3+secondDigit;
        int thirdDigitDecrypted = thirdDigit>=7?thirdDigit-7:3+thirdDigit;
        int fourthDigitDecrypted = fourthDigit>=7?fourthDigit-7:3+fourthDigit;

        int decryptedNumber = secondDigitDecrypted*1000+firstDigitDecrypted*100+fourthDigitDecrypted*10+thirdDigitDecrypted;

        System.out.println("Decrypted Number: "+decryptedNumber);
    }

    public static void main(String[] args) {

        decrypt(1589);
    }
}

=====================================================================


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...
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...
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                                                                     ...
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...
Mrs. Jay has asked you, the CFO of the company, to write a memo outlining the...
Mrs. Jay has asked you, the CFO of the company, to write a memo outlining the advantages and disadvantages of using debt relative to equity. She also wants the memo to cover the impact that his decision might have on the firm’s weighted cost of capital and overall firm value.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT