Java bit encryption

Source: Internet
Author: User

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:

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.