Use the "^" exclusive or operation to encrypt the string
Idea: 1. first, create the token of the string input; 2. use char [] array = password. toCharArray (); // get the character array; 3. to traverse character arrays, We need to traverse all elements in the array. For example, if you want to output all the information in the array, we need to use them. 4. perform exclusive or operations
Detailed code:
Package com. lixiyu; import java. util. extends; public class Example {public static void main (String [] args) {extends sca = new extends (System. in); System. out. println ("enter an English String or decryption String"); String line = sca. nextLine (); // obtain the user input. char [] array = line. toCharArray (); // obtain the character array for (int I = 0; I <array. length; I ++) {// array of calendar characters array [I] = (char) (array [I] ^ 20000 ); // perform an exclusive or operation on each element of the array} System. out. println ("the encryption and decryption results are as follows:"); System. out. println (new String (array); // output key }}
Enter a string of running results as needed:
Enter an English string or a decryption string abcdefghijk. the encryption and decryption results are as follows:
Copy and paste the encrypted result to the input box and decrypt it:
Please enter an English string or decryption string. the encryption and decryption results are as follows: abcdefghijk
Encryption is so simple!
This article is from the "ToBeContinued" blog, please be sure to keep this source http://leexy.blog.51cto.com/4136883/1302853