How to Use exclusive or operations for simple encryption and decryption

Source: Internet
Author: User
Tags sca

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.