一封加密情书

时间:2023-02-12 18:58:44
/**
 * 加解密算法
 * @author leiwei  2012-01-12
 *
 */
public class EncodeAndDencode {

	/**
	 * 
	 * @param encodeInfo 要加密的信息
	 */
	public void encode(String encodeInfo) {
		String encodeResult = "";
		for (int i = 0; i < encodeInfo.length(); i++) {
			if(i<(encodeInfo.length()-1)){
				encodeResult += encodeInfo.charAt(i)*73 + 123 +"%";
			}else{
				encodeResult += encodeInfo.charAt(i)*73 + 123 +"";
			}
		}
		System.out.println(encodeResult);
	}
	
	/**
	 * 
	 * @param dencodeInfo 需要解密的信息
	 */
	public void dencode(String dencodeInfo) {
		String dencodeResult = "";
		String[] chars = dencodeInfo.split("%");
		for(int i=0;i<chars.length;i++){
			dencodeResult += (char)((Integer.parseInt(chars[i])-123)/73);  
		}
		System.out.println(dencodeResult);
	}
	
	public static void main(String[] args) {
		//new EncodeAndDencode().encode("我爱你");
		new EncodeAndDencode().dencode("1832788%2134132%1483483");
	}
}