Creates a class, and carries out an exclusive or operation between a string and a specified value through the "^" XOR operator in the bitwise operation, thus changing the value of each character in the string, in this way, an encrypted string is obtained. When the encrypted string is used as the input content of the program, and then the specified value is used for exclusive or operation, the encrypted string is restored to the original string value.
Import java. util. extends; public class Example {public static void main (String [] args) {implements scan = new loads (System. in); System. out. println ("enter an English String or decryption String"); String password = scan. nextLine (); // obtain the user input char [] array = password. toCharArray (); // obtain the character array for (int I = 0; I <array. length; I ++) {// traverses the character array [I] = (char) (array [I] ^ 20000 ); // perform an exclusive or operation on each array element} System. out. println ("the encryption or decryption result is as follows:"); System. err. println (new String (array); // output key }}
Effect: