hcipher.java~

来自「文件加密解密程序。内含公开暗号(RAS)加解密工具」· JAVA~ 代码 · 共 77 行

JAVA~
77
字号
/* * HCipher.java * * Created on 2003?月19日, 下?:39 */package HUtil.HCipher;/** * * @author  H */public class HCipher {        public static final int MODE1 = 1;    public static final int MODE2 = 2;    private int mode;    public final String Version = "2.01";        /** Creates a new instance of HCipher */    public HCipher(int md) {        mode = md;    }        /** Creates a new instance of HCipher */    public HCipher() {        mode = MODE2;    }        private String createPassword(String pswd) throws Exception{        String re;        if (mode==this.MODE1){            int password = Math.abs(pswd.hashCode());            re = password + "";        //}else if(mode==MODE2){        }else{            byte[] temp = pswd.getBytes();            StringBuffer sb = new StringBuffer();            for(int i=0;i<temp.length;i++){                sb.append(temp[i]+"");            }            re = sb.toString();        }        return re;    }        public byte[] cipher(byte[] input, String pswd, String operation_type) throws Exception{        pswd = this.createPassword(pswd);        int count = pswd.length();        int[] s_pswd = new int[count];        int loopcnt = input.length;        for(int i=0;i<count;i++){            s_pswd[i] = Integer.valueOf(pswd.substring(i,i+1)).intValue();        }        int pswd_count = 0;        for (int i=0;i<loopcnt;i++){            input[i] = (byte)cipher((int)input[i], s_pswd[pswd_count], operation_type);            pswd_count ++;            if (pswd_count>=count){                pswd_count = 0;            }        }        return input;    }        public int cipher(int input, int password, String operation_type){        int output_resource;        if (operation_type.equals("E")){            output_resource = input - password;        }else{            output_resource = input + password;        }        return output_resource;    }    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?