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.

2)  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

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

import java.util.Scanner;

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));
  }
}

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...
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...
SnoopPro is a global company specializing in communications security. The company monitors over 1 billion Internet...
SnoopPro is a global company specializing in communications security. The company monitors over 1 billion Internet messages per day and recently reported that 70% of emails are spam. Suppose your inbox contains 25 messages. Let X be the number of messages that are spam. What is P(16 ≤ X ≤ 20)? If a sample of size n = 64 is selected from a population with mean E(X) = 50 and standard deviation SD(X) = 8, then the probability that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT