加密与解密算法

加密与解密

import java.util.Scanner;

public class Main {

/**

 * @作者:聆听

 * 功能:加密与解密

 * 时间:2017.3.11

 */

public static void main(String[] args) {

Scanner cin=new Scanner(System.in);

try {

String value=cin.nextLine();

char secret='@';

byte[] encrypt=Main.EAndU(value,secret);

System.out.println(encrypt);

String uncrypt=Main.EAndU(encrypt,secret);

System.out.println(uncrypt);

} catch (Exception e) {                  

System.out.println("SOMETHING ERROR");

}

cin.close();

}

private static String EAndU(byte[] encrypt, char secret) {

for(int i=0;i

encrypt[i]=(byte)(encrypt[i]^(int)secret);

}

return new String(encrypt,0,encrypt.length);

}

private static byte[] EAndU(String value, char secret) {

byte []bt=value.getBytes();

for(int i=0;i

bt[i]=(byte)(bt[i]^(int)secret);

}

return bt;

}

}

你可能感兴趣的:(小小程序)