Ask Question
17 May, 21:36

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 app 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 display the encrypted integer. Write a separate app that inputs an encrypted four-digit integer and decrypts it (by reversing the encryption scheme) to form the original number. Use the format specifier D4 to display the encrypted value in case the number starts with a 0

+5
Answers (1)
  1. 17 May, 22:32
    0
    The output of the code:

    Enter a 4 digit integer : 1 2 3 4

    The decrypted number is : 0 1 8 9

    The original number is : 1 2 3 4

    Explanation:

    Okay, the code will be written in Java (programming language) and the file must be saved as "Encryption. java."

    Here is the code, you can just copy and paste the code;

    import java. util. Scanner;

    public class Encryption {

    public static String encrypt (String number) {

    int arr[] = new int[4];

    for (int i=0; i<4; i++) {

    char ch = number. charAt (i);

    arr[i] = Character. getNumericValue (ch);

    }

    for (int i=0; i<4; i++) {

    int temp = arr[i];

    temp + = 7;

    temp = temp % 10;

    arr[i] = temp;

    }

    int temp = arr[0];

    arr[0] = arr[2];

    arr[2] = temp;

    temp = arr[1];

    arr[1] = arr[3];

    arr[3] = temp;

    int newNumber = 0;

    for (int i=0; i<4; i++)

    newNumber = newNumber * 10 + arr[i];

    String output = Integer. toString (newNumber);

    if (arr[0]==0)

    output = "0"+output;

    return output;

    }

    public static String decrypt (String number) {

    int arr[] = new int[4];

    for (int i=0; i<4; i++) {

    char ch = number. charAt (i);

    arr[i] = Character. getNumericValue (ch);

    }

    int temp = arr[0];

    arr[0]=arr[2];

    arr[2]=temp;

    temp = arr[1];

    arr[1]=arr[3];

    arr[3]=temp;

    for (int i=0; i<4; i++) {

    int digit = arr[i];

    switch (digit) {

    case 0:

    arr[i] = 3;

    break;

    case 1:

    arr[i] = 4;

    break;

    case 2:

    arr[i] = 5;

    break;

    case 3:

    arr[i] = 6;

    break;

    case 4:

    arr[i] = 7;

    break;

    case 5:

    arr[i] = 8;

    break;

    case 6:

    arr[i] = 9;

    break;

    case 7:

    arr[i] = 0;

    break;

    case 8:

    arr[i] = 1;

    break;

    case 9:

    arr[i] = 2;

    break;

    }

    }

    int newNumber = 0;

    for (int i=0; i<4; i++)

    newNumber = newNumber * 10 + arr[i];

    String output = Integer. toString (newNumber);

    if (arr[0]==0)

    output = "0"+output;

    return output;

    }

    public static void main (String[] args) {

    Scanner sc = new Scanner (System. in);

    System. out. print ("Enter a 4 digit integer:");

    String number = sc. nextLine ();

    String encryptedNumber = encrypt (number);

    System. out. println ("The decrypted number is:"+encryptedNumber);

    System. out. println ("The original number is:"+decrypt (encryptedNumber));

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your 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 ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers