zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    luogu2253 好一个一中腰鼓!
    luogu2948 滑雪课
    luogu1556 幸福的路
    luogu1900 自我数
    luogu1632 点的移动
    luogu1999 高维正方体
    树状数组模板
    杜教筛
    [比赛|考试] 9月第一周的考试
    历年NOIP真题总结
  • 原文地址:https://www.cnblogs.com/ziwuxian/p/4177476.html
Copyright © 2011-2022 走看看