Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Secret Channels A company uses public Internet to carry its phone service. The v

ID: 3903862 • Letter: S

Question

Secret Channels A company uses public Internet to carry its phone service. The voice data will be encrypted before sending to Internet. The encryption algorithm is as follows: For each four-digit decimal integer, 1) Add 5 to each digit, divide the sum by 10 and use the remainder to replace the digit, (2) Swap lst-digit with 4th-digit, (3) Swap 2nd-digit with 3rd-digit. (The program must be named as Encrypted.java) Implement a method as specified below: public static String encoding (String voiceData) This method encrypts voice data and return encrypted data Input: A series of lines. Each line is a positive four-digit decimal integer. Output: In each line, print the encrypted four-digit decimal integer Sample Input (sample data file is provided for your testing purpose): 0123 5890 Sample Output 8765 5430

Explanation / Answer

public class Encrypted {

   public static String encoding(String voiceData) {

       String temp = "";

       for(int i=voiceData.length()-1; i >=0; i--) {

           char ch = voiceData.charAt(i);

           int n = ((ch - '0') + 5) % 10;

           temp += n;

       }

      

       return temp;

   }

  

   public static void main(String args[]) {

       System.out.println(encoding("0123"));

       System.out.println(encoding("5890"));

       System.out.println(encoding("9999"));

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote