//数字解密
//原加密过程
// 1.每位数字加五
//2.再每位对10取模
//3.反转数字
Scanner sc = new Scanner(System.in);
System.out.println("请输入需要解密的数字:");
int number = sc.nextInt();
int temp = number;
int count = 0;
while(number != 0){
number = number / 10;
count ++;
}
int[] arr = new int[count];
for (int i = 0; i < arr.length; i++) {
int a = temp % 10;
temp = temp / 10;
arr[i] = a;
}
System.out.println("存入的数组并反转为:");
for (int j = 0; j < arr.length; j++) {
System.out.print(arr[j] + " ");
}
System.out.println(" ");
int index = 0;
int[] newarr = new int[arr.length];
//模10解密
for(int k = 0; k < arr.length ; k++)
{
for(int a = 5;a <= 14; a++){
if(a % 10 == arr[k]){
newarr[index] = a;
index ++;
}
}
}
System.out.println("模10解密:");
for (int n = 0; n < arr.length; n++) {
System.out.print(newarr[n] + " ");
}
System.out.println(" ");
//减去5解密
for (int m = 0; m < arr.length; m++) {
newarr[m] = newarr[m] - 5;
}
//打印解密结果 8 3 4 6 结果应该为 1983
System.out.println("打印解密结果:");
for (int n = 0; n < arr.length; n++) {
System.out.println(newarr[n] + " ");
}
//将数组里的取出来
int result = 0;
for (int a = 0; a < newarr.length; a++) {
int wei = newarr[a];
result = result * 10 + wei;
}
System.out.println("最终结果为:");
System.out.println(result);