• Java简单的加密解密算法,使用异或运算


    package cn.std.util;
    
    import java.nio.charset.Charset;
    
    
    public class DeEnCode {
    
        private static final String key0 = "FECOI()*&<MNCXZPKL";
        private static final Charset charset = Charset.forName("UTF-8");
        private static byte[] keyBytes = key0.getBytes(charset);
        
        public static String encode(String enc){
            byte[] b = enc.getBytes(charset);
            for(int i=0,size=b.length;i<size;i++){
                for(byte keyBytes0:keyBytes){
                    b[i] = (byte) (b[i]^keyBytes0);
                }
            }
            return new String(b);
        }
        
        public static String decode(String dec){
            byte[] e = dec.getBytes(charset);
            byte[] dee = e;
            for(int i=0,size=e.length;i<size;i++){
                for(byte keyBytes0:keyBytes){
                    e[i] = (byte) (dee[i]^keyBytes0);
                }
            }
            return new String(e);
        }
    
        public static void main(String[] args) {
            String s="you are right";
            String enc = encode(s);
            String dec = decode(enc);
            System.out.println(enc);
            System.out.println(dec);
        }
    }
  • 相关阅读:
    class和struct
    类内初始值(c++11)
    默认初始化、值初始化
    聚合类
    对象
    排序算法的比较
    快速排序
    堆排序
    ubunu设置java命令为全局的命令-添加到全局环境变量
    Mina笔记
  • 原文地址:https://www.cnblogs.com/ziwuxian/p/4177476.html
Copyright © 2020-2023  润新知