加密解密

/**
 *<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;
  }
//解密完毕

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值