A company uses a public telephone to pass data, and the data is a four-bit integer that is encrypted during delivery.
The encryption rules are as follows: Each digit is prefixed with 5, and the remainder is replaced with and divided by 10, then the first and fourth bits are exchanged, and the second and third bits are exchanged.
The number after the encryption is obtained.
Public Static voidMain (string[] args) {f (2345); } Public Static voidFintnum) { int[] C =New int[4]; if(num > 999 && num < 10000) {c[0] = num/1000; c[1] = (num/100)% 10; c[2] = (NUM/10)% 10; c[3] = num% 10; for(intj = 0; J < 4; J + +) {C[j]+ = 5; C[J]%= 10; } for(intj = 0; J <= 1; J + +) { inttemp =C[j]; C[J]= C[3-J]; c[3-J] =temp; } System.out.print ("The number after encryption is:"); for(intj = 0; J < 4; J + +) System.out.print (C[j]); } Else{System.out.println ("The data transmitted is wrong, please retry!!!" "); } }
Java Common algorithm question (34)---Calculate the phone number after encryption