In: Computer Science
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.
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter a 4-digit number");
int n= sc.nextInt(); //input of the number
int ar[]=new int[4]; //array to store all digits
int i=3; //counter variable
while(n>0) //loop to store each digit in the array
{
ar[i]=n%10;
n/=10;
i--;
}
for( i=0;i<4;i++) //loop to calculate the original digit of the number
{
ar[i]= (ar[i]+6)%10;
}
int temp=ar[2]; //swapping 1st and 3rd digit
ar[2]=ar[0];
ar[0]=temp;
temp=ar[3]; //swapping 2nd and 4th digit
ar[3]=ar[1];
ar[1]=temp;
System.out.println("The original number is :");
for( i=0;i<4;i++) //loop to ptint original digits of the number.
System.out.print(ar[i]);
}
}