zoukankan      html  css  js  c++  java
  • uzqp文件的加解密

    帮朋友做的,根据python版本翻译成的java版本,记录一下代码

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    
    /**
     * @author xirtam
     * @data 2015年03月26日19:49:39
     *
     */
    public class Tool {
    
        public static int[] xorstr = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
                1, 13, 14, 15, 16 };
    
        /**
         * 加密/解密,如果inpath传uzqp,outPath传png,则解密,反之加密
         * 
         * @param inPath
         * @param outPath
         */
        public static void decodeAndEncode(String inPath, String outPath) {
            try {
                StringBuilder target = new StringBuilder();
                FileInputStream fis = new FileInputStream(new File(inPath));
                byte[] bytes = new byte[fis.available()];
                fis.read(bytes);
                char[] chars = new char[bytes.length];
                for (int i = 0; i < chars.length; i++) {
                    chars[i] = (char) bytes[i];
                    target.append(chr((byte) (ord(chars[i]) ^ (xorstr[i
                            % (xorstr.length)]))));
                }
                fis.close();
                System.out.println("i: " + chars.length);
                System.out.println("o: " + target.toString().length());
                FileOutputStream fos = new FileOutputStream(new File(outPath));
                byte[] fuck = new byte[chars.length];
                for (int i = 0; i < target.length(); i++) {
                    fuck[i] = (byte) target.toString().charAt(i);
                }
                fos.write(fuck);
                fos.flush();
                fos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static char chr(byte c) {
            return (char) c;
        }
    
        public static byte ord(char c) {
            return (byte) c;
        }
    
        public static void main(String[] args) {
            decodeAndEncode(
                    "/Users/corleone/Documents/temp/testpy/btn_menu111.png.uzqp",
                    "/Users/corleone/Documents/temp/testpy/Bubble3333.png");
    
            // decodeAndEncode("/Users/corleone/Documents/temp/testpy/Bubble3.png",
            // "/Users/corleone/Documents/temp/testpy/btn_menu111.png.uzqp");
        }
    
    }

    python版本

    def fun():  
      fn1='./btn_menu1.png.uzqp'  
      xorstr='x01x02x03x04x05x06x07x08x09x0ax0bx01x0dx0ex0fx10'  
      with open(fn1,'rb') as f:  
        data = f.read();  
        data0=""  
        print len(data)
        for i in range(len(data)): 
          data0  += chr( ord(data[i]) ^ ord(xorstr[i % (len(xorstr))]))  
      
      fn2='Bubble2.png'  
      with open(fn2,'wb') as f:  
        f.write(data0)  
      
    if __name__ == '__main__':  
      fun()  
  • 相关阅读:
    $(document).Ready()方法 VS OnLoad事件 VS $(window).load()方法
    ASP.NET MVC之文件上传【二】
    ASP.NET MVC之文件上传【一】
    [JSOI2009]球队收益
    Codeforces 323 B Tournament-graph
    2017 [六省联考] T6 寿司餐厅
    [CQOI2014]数三角形
    Hdoj 3506 Monkey Party
    Loj #125. 除数函数求和(2)
    Codeforces 235 E Number Challenge
  • 原文地址:https://www.cnblogs.com/xirtam/p/4371335.html
Copyright © 2011-2022 走看看