- public class EncTest
- {
- public static void main(String[] args)
- {
- System.out.println(cipherText(9460));
- }
- /**
- * get ciphertext of plaintext
- */
- private static int cipherText(int plainText){
- //Processing the number using String
- StringBuilder sb = new StringBuilder(String.valueOf(plainText));
- for(int i = 0; i < sb.length(); i++){
- sb.setCharAt(i,String.valueOf((Integer.parseInt(sb.charAt(i)+"")+5)%10).charAt(0));
- }
- //Cache number 4.
- char temp = sb.charAt(3);
- //Exchange.
- sb.setCharAt(3,sb.charAt(0));
- sb.setCharAt(0,temp);
- //The same as the below steps.
- temp = sb.charAt(2);
- sb.setCharAt(2,sb.charAt(1));
- sb.setCharAt(1,temp);
- return Integer.parseInt(sb.toString());
- }
- }
复制代码 |