/**
*<br> Title:密码的加密和解密类
*<br> Description: 密码的加密和解密
* <br>Copyright: Copyright (c) 2002
* <br>Company:china-e2
* @author renj
* @version 2.0
* gggggggggggggg
*/
public class Password {
private String strSql="";
/**
* 类名的打印输出
*/
public Password(){
//DBOperate.writeClassName(this.getClass().getName());
}
public static void main(String[] args) {
Password doc=new Password();
System.out.println(Password.Decode_PSW("gynkawwwwaknyg"));
// String en_psw=doc.Encode_PSW("com.microsoft.jdbc.sqlserver.SQLServerDriver");
// System.out.println(en_psw);
System.out.println(doc.Encode_PSW("wangy"));
}
/**
* 下面加密
* @param psw
* @return
*/
public static String Encode_PSW(String psw){
psw=psw+"kw"; //一、尾巴上加'kw'
int psw_length=psw.length();
String new_psw="";
for(int i=0;i<psw_length;i++){ //二、加尾注后的数据与自身的倒序错位对插
new_psw=new_psw+psw.substring(i,i+1)+psw.substring(psw_length-1-i,psw_length-i);
}
new_psw=new_psw.substring(psw_length,psw_length*2)+new_psw.substring(0,psw_length);
return new_psw;
}
/**
* 解密
* @param psw
* @return
*/
public static String Decode_PSW(String psw){
String decode_psw="";
if(psw.length()>=6){
int psw_length=psw.length()/2; //一、数据对半掉换位置
String new_psw=psw.substring(psw_length,psw_length*2)+psw.substring(0,psw_length);
for(int i=0;i<psw_length;i++){ //二、读出奇数位的数据
decode_psw=decode_psw+new_psw.substring(i*2,i*2+1);
} //三、去掉最后两位
decode_psw=decode_psw.substring(0,decode_psw.length()-2);
}else{
decode_psw=psw;
}
return decode_psw;
}
//解密完毕
}