String加密解密 2017.07.26
1.代码如下:
package com.xuzhiwen.test1; public class AddAndReadPass { public static void main(String[] args) { String str = "beibidewomen"; char key = '?'; String str_ = ""; //加密 for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); char temp = (char)(ch^key); str_ += String.valueOf(temp); System.out.print(temp); } System.out.println(); //解密 for (int i = 0; i < str_.length(); i++) { char ch = str_.charAt(i); char temp = (char)(ch^key); System.out.print(temp); } } }
2.运行结果如下: