Implementation of simple data encryption algorithm (JavaSE)

First look at the requirements of the subtopics, similar ideas are probably like this

First, reverse the order of the data, then add 5 to each digit, then use the remainder of the sum divided by 10 to represent the number, and finally exchange the first and last digits. Please give any integer less than 8 digits, and then , Print out the encrypted result on the console

Idea: Let the user enter a string of numbers to encrypt, then use the nextLine() method to get the string type of the number, and then convert it to an array (directly use split("")) to directly operate, use the array Reverse the order and then exchange.

The code is lazy and not commented. It is a very simple way to deal with it. Come on and work hard to learn it!!!

The approximate code is as follows:

public class SETest {
    
    
	public static void main(String[] args) {
    
    
		SETest seTest = new SETest();
		System.out.println("请输入一个小于8位的整数,然后会将整数加密后输出");
		Scanner sc = (new Scanner(System.in));
		String number = sc.nextLine();
		int[] array1 = seTest.intArray(number);
		int[] password = seTest.addPassword(array1);
		System.out.println("加密后的结果为:   ");
		for (int i : password) {
    
    
			System.out.print(i);
		}
		
	}
	public int[] intArray(String a) {
    
    
		String[] split = a.split("");
		int[] aa = new int[split.length];
		int num = 0;
		for (int i = split.length-1; i >= 0; i--) {
    
    
			aa[num] = Integer.parseInt(split[i]);
			num++;
		}
		return aa;
	}
	public int[] addPassword(int[] a) {
    
    
		for (int i = 0; i < a.length; i++) {
    
    
			a[i] = (a[i]+5)%10;
		}
		int temp = a[0];
		a[0] = a[a.length-1];
		a[a.length-1] = temp;
		return a;
	}
}

You turned to the end again, huh

Guess you like

Origin blog.csdn.net/xiaole060901/article/details/108207759