Question

In: Computer Science

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 second digit with the fourth. Print the encrypted integer on the screen.  Write a separate application where an encrypted four-digit integer is entered and decrypted (reversing the encryption scheme) and finds the original number.

Note: code should be written in Java Language.

Solutions

Expert Solution

Summary:

The program wriiten here is very simple, just go through the comments and print statements for better understanding.

Note:- This program works perfectly as per your requirement but there is no proper way to reverse the encryption method given in question to decrypt the value.

---------------------------------------------Encryption.java----------------------------------------

import java.util.Scanner;

public class Encryption {
    public static int encrypt(int number) {

        int[] digits = new int[4];
        for (int i = 0; i < 4; i++) {
            digits[i] = ((number % 10) + 6) % 10; // replace each digit with remainder of new value divided by 10 by adding 6 to the digit.
            number = number / 10;
        }

        // Replacing digit 1 with digit 3 and digit 2 with digit 4
        String str = "" + digits[1] + digits[0] + digits[3] + digits[2];
        return Integer.parseInt(str);
    }

    public static int decrypt(int encryptedNumber) {
        int[] digits = new int[4];
        int temp = 0;
        for (int i = 0; i < 4; i++) {
            temp = (encryptedNumber % 10);
            if (temp == 0) {
                digits[i] = 10 - 6;
            }
            else if (temp == 2) {
                digits[i] = 6;
            } else if (temp == 5) {
                digits[i] = 9;
            } else if (temp == 4) {
                digits[i] = 8;
            } else if (temp == 3) {
                digits[i] = 7;
            } else if (temp == 6) {
                digits[i] = 0;
            } else if (temp == 1) {
                digits[i] = 5;
            } else
                digits[i] = temp - 6;
            encryptedNumber = encryptedNumber / 10;
        }

        System.out.println("" + digits[3] + digits[2] + digits[1] + digits[0]);

        String str = "" + digits[1] + digits[0] + digits[3] + digits[2];
        return Integer.parseInt(str);
    }

    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter 4 digit number to encrypt");
        int number = scanner.nextInt();
        int encryptedNumber = encrypt(number);
        System.out.println("After Encryption: " + encryptedNumber);
        int decriptedNumber = decrypt(encryptedNumber);
        String result = String.valueOf(decriptedNumber);
        if (result.length()!=4)
            System.out.println("After Decryption: 0" + decriptedNumber);
        else
            System.out.println("After Decryption: " + decriptedNumber);
    }
}

Both encrypt and decrypt methods are implemented in the same class Encryption.

Code Screenshot:

Output:

Its one of the most difficult problem to revert the modulos of two number as their is no direct answers for that.

I tried by best to solve this problem to work perfectly correct.

Please rate thumbs up if you like the answer.

Thanks you!!!!


Related Solutions

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...
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...
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...
For encryption, what does it mean for data to be in transition and in use? What...
For encryption, what does it mean for data to be in transition and in use? What are the major security concerns with data encryption?
If two applications use TCP to send data but only send 10 bytes per segment (e.g....
If two applications use TCP to send data but only send 10 bytes per segment (e.g. by using the push operation), what is the maximum percent of the network bandwidth they will have for their data?
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.
C++. How do I reverse this encryption? Here is the question: "A company that wants to...
C++. How do I reverse this encryption? Here is the question: "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 program should read a four-digit integer in main() entered by the user and encrypt it as follows: 1. Replace each digit with the result of adding 7 to the digit and...
Internet Marketing: Whats internet Marketing? Discuss an existing company that use internet marketing? how it use...
Internet Marketing: Whats internet Marketing? Discuss an existing company that use internet marketing? how it use Internet marketing to promote one of its products? which product and why? what are the benefit of internet marketing ? Support Information: As in any new industry or concept, the Internet has its share of confusing buzzwords and jargon. A website produced by Matisse Enzer, presents a comprehensive glossary of Internet terms. http://www.matisse.net/files/glossary.html Many traditional elements of marketing easily translate into Internet marketing such...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT