100%准确“预测”涨停股的Java程序

文章来源:http://blog.csdn.net/cping1982/article/details/5786759

首先声明,小弟绝对不是标题党。事实上,这是昨天小弟看到的某条新闻后(《100%准确预测涨停股?——新型股票诈骗伎俩揭秘》,原文地址:http://bit.ly/aYC8pd),有感而发杜撰的Java版闲暇之作。

这个小程序的作用非常之简单,也就是向原文中所描述的那样,加密文本文件,而后将内容以“你所需要的方式”展示出来。


下载地址(源码在jar中):http://greenvm.googlecode.com/files/Fraud.jar

 

主程序如下:

 

  1. package org.text.fraud;  
  2. import java.io.ByteArrayInputStream;  
  3. import java.io.ByteArrayOutputStream;  
  4. import java.io.DataInputStream;  
  5. import java.io.DataOutputStream;  
  6. import java.io.File;  
  7. import java.io.FileInputStream;  
  8. import java.io.FileNotFoundException;  
  9. import java.io.FileOutputStream;  
  10. import java.io.IOException;  
  11. import java.io.InputStream;  
  12. /** 
  13.  * @author chenpeng 
  14.  * @email:ceponline@yahoo.com.cn 
  15.  * @version 0.1 
  16.  */  
  17. public class Fool {  
  18.     // crc32参数表,共有256项  
  19.     final static private long[] crcTable = new long[256];  
  20.     // 静态初始化参数表  
  21.     static {  
  22.         long crc;  
  23.         int n, k;  
  24.         for (n = 0; n < 256; n++) {  
  25.             crc = (long) n;  
  26.             for (k = 0; k < 8; k++) {  
  27.                 if ((crc & 1) == 1) {  
  28.                     crc = 0xEDB88320L ^ (crc >> 1);  
  29.                 } else {  
  30.                     crc = crc >> 1;  
  31.                 }  
  32.             }  
  33.             crcTable[n] = crc;  
  34.         }  
  35.     }  
  36.     private static final byte[] DIGITS = { '0''1''2''3''4''5''6',  
  37.             '7''8''9''A''B''C''D''E''F' };  
  38.     private static final byte[] FILE_FLAG_ID = { 'W''S''P''Z' };  
  39.     private boolean checkCRC = true;  
  40.     private byte[] passBytes;  
  41.     final static private String EMPTY_CONTEXT = "我是骗子我怕谁?";  
  42.     /** 
  43.      * 解密byte[] 
  44.      *  
  45.      * @param array 
  46.      * @return 
  47.      */  
  48.     private byte[] decode(byte[] array) {  
  49.         return decode(new String(array).toCharArray());  
  50.     }  
  51.     /** 
  52.      * 解密char[] 
  53.      *  
  54.      * @param data 
  55.      * @return 
  56.      */  
  57.     private byte[] decode(char[] data) {  
  58.         if (passBytes == null) {  
  59.             throw new RuntimeException("Password is null");  
  60.         }  
  61.         // 将16进制字符串转化为原始byte[]  
  62.         int len = data.length;  
  63.         byte[] out = new byte[len >> 1];  
  64.         for (int i = 0, j = 0; j < len; i++) {  
  65.             int f = toDigit(data[j]) << 4;  
  66.             j++;  
  67.             f = f | toDigit(data[j]);  
  68.             j++;  
  69.             out[i] = (byte) (f & 0xFF);  
  70.         }  
  71.         // 为了防止向新闻中那样轻易被人试出规律,此示例以password混淆内容  
  72.         // 一个password只能解密一种信息。  
  73.         int keyindex = passBytes.length;  
  74.         int outindex = out.length;  
  75.         byte buffer[] = new byte[outindex / 2];  
  76.         for (int i = 0; i < outindex; i += 2) {  
  77.             int index = (i / 2) % keyindex;  
  78.             int k = out[i] - passBytes[index];  
  79.             if (k < 0) {  
  80.                 k = k + 256;  
  81.             }  
  82.             buffer[i / 2] = (byte) k;  
  83.         }  
  84.         return buffer;  
  85.     }  
  86.     /** 
  87.      * 将字符转化为指定进制数字 
  88.      *  
  89.      * @param ch 
  90.      * @return 
  91.      */  
  92.     private static int toDigit(char ch) {  
  93.         int digit = Character.digit(ch, 16);  
  94.         if (digit == -1) {  
  95.             throw new RuntimeException("digit is -1");  
  96.         }  
  97.         return digit;  
  98.     }  
  99.     /** 
  100.      * 解密byte[] 
  101.      *  
  102.      * @param data 
  103.      * @return 
  104.      */  
  105.     private byte[] encode(byte[] data) {  
  106.         if (passBytes == null) {  
  107.             throw new RuntimeException("Password is null");  
  108.         }  
  109.         // 以password加密byte[]  
  110.         int keyindex = passBytes.length;  
  111.         int insindex = data.length;  
  112.         byte buffer[] = new byte[2 * insindex];  
  113.         for (int i = 0; i < insindex; i++) {  
  114.             int index = i % keyindex;  
  115.             int k = data[i] + passBytes[index];  
  116.             int d = (int) (255 * Math.random());  
  117.             if (k > 255) {  
  118.                 k = k - 255;  
  119.             }  
  120.             buffer[2 * i] = (byte) k;  
  121.             buffer[2 * i + 1] = (byte) d;  
  122.         }  
  123.         // 将加密后信息转化为16进制字符串(想要乱码效果就不用转了……)  
  124.         int l = buffer.length;  
  125.         byte[] out = new byte[l << 1];  
  126.         for (int i = 0, j = 0; i < l; i++) {  
  127.             out[j++] = DIGITS[(0xF0 & buffer[i]) >>> 4];  
  128.             out[j++] = DIGITS[0x0F & buffer[i]];  
  129.         }  
  130.         return out;  
  131.     }  
  132.     /** 
  133.      * 加密指定字符串 
  134.      *  
  135.      * @param string 
  136.      * @return 
  137.      */  
  138.     public final String encrypt(String string) {  
  139.         return new String(encode(string.getBytes()));  
  140.     }  
  141.     /** 
  142.      * 解密指定字符串 
  143.      *  
  144.      * @param string 
  145.      * @return 
  146.      */  
  147.     public final String decrypt(String string) {  
  148.         return new String(decode(string.getBytes()));  
  149.     }  
  150.     /** 
  151.      * 以CRC32方式加密指定数据 
  152.      *  
  153.      * @param buf 
  154.      * @param startPos 
  155.      * @param endPos 
  156.      * @return 
  157.      */  
  158.     private String CRC32(final byte[] buf, final int startPos, final int endPos) {  
  159.         long c = 0xFFFFFFFFL;  
  160.         for (int i = startPos; i < endPos; i++) {  
  161.             c = (crcTable[(int) ((c ^ buf[i]) & 0xFF)] ^ (c >> 8));  
  162.         }  
  163.         return String.valueOf(Math.abs((int) (c ^ 0xFFFFFFFFL)));  
  164.     }  
  165.     public void checkCRC(boolean bool) {  
  166.         this.checkCRC = bool;  
  167.     }  
  168.     /** 
  169.      * 为防止如新闻中那样轻易被人试出规律,密码采用CRC校验方式存在。 
  170.      *  
  171.      * @param pass 
  172.      */  
  173.     public void makePassword(String pass) {  
  174.         if (checkCRC) {  
  175.             int size = pass.length();  
  176.             byte[] bytes = new byte[size];  
  177.             for (int i = 0; i < size; i++) {  
  178.                 bytes[i] = (byte) pass.charAt(i);  
  179.             }  
  180.             this.passBytes = CRC32(bytes, 0, size).getBytes();  
  181.         } else {  
  182.             this.passBytes = pass.getBytes();  
  183.         }  
  184.     }  
  185.     /** 
  186.      * 从文件中读取byte[] 
  187.      *  
  188.      * @param dis 
  189.      * @param size 
  190.      * @return 
  191.      * @throws Exception 
  192.      */  
  193.     public static byte[] readByteArray(DataInputStream dis, int size)  
  194.             throws Exception {  
  195.         byte[] readBytes = new byte[size];  
  196.         for (int i = 0; i < size; i++) {  
  197.             readBytes[i] = dis.readByte();  
  198.         }  
  199.         return readBytes;  
  200.     }  
  201.     /** 
  202.      * 写入byte[]到文件中 
  203.      *  
  204.      * @param bytes 
  205.      * @param dos 
  206.      * @throws Exception 
  207.      */  
  208.     public static void writeByteArray(byte[] bytes, DataOutputStream dos)  
  209.             throws Exception {  
  210.         for (int i = 0; i < bytes.length; i++) {  
  211.             dos.writeByte(bytes[i] ^ 0x01);  
  212.         }  
  213.     }  
  214.     /** 
  215.      * 读取文件数据至byte[] 
  216.      *  
  217.      * @param dis 
  218.      * @return 
  219.      */  
  220.     private static byte[] read(DataInputStream dis) {  
  221.         ByteArrayOutputStream bos = new ByteArrayOutputStream();  
  222.         byte[] bytes = new byte[8192];  
  223.         try {  
  224.             int read;  
  225.             while ((read = dis.read(bytes)) >= 0) {  
  226.                 bos.write(bytes, 0, read);  
  227.             }  
  228.             bytes = bos.toByteArray();  
  229.         } catch (IOException e) {  
  230.             return null;  
  231.         }  
  232.         return bytes;  
  233.     }  
  234.     /** 
  235.      * 读取一个【WSPZ】类型的加密文本文件 
  236.      *  
  237.      * @param fileName 
  238.      * @param password 
  239.      * @return 
  240.      */  
  241.     public String readFile(String fileName, String password) {  
  242.         String context = null;  
  243.         InputStream in = null;  
  244.         DataInputStream dis = null;  
  245.         try {  
  246.             File file = new File(fileName);  
  247.             in = new FileInputStream(file);  
  248.             dis = new DataInputStream(in);  
  249.             if (!verify(dis, password)) {  
  250.                 throw new RuntimeException("Password error");  
  251.             }  
  252.             byte[] bytes = read(dis);  
  253.             context = new String(decode(bytes));  
  254.         } catch (Exception e) {  
  255.             e.printStackTrace();  
  256.         } finally {  
  257.             try {  
  258.                 if (dis != null) {  
  259.                     dis.close();  
  260.                     dis = null;  
  261.                 }  
  262.             } catch (Exception e) {  
  263.             }  
  264.         }  
  265.         return context;  
  266.     }  
  267.     /** 
  268.      * 读取一个【WSPZ】类型的加密文本信息 
  269.      *  
  270.      * @param context 
  271.      * @param password 
  272.      * @return 
  273.      */  
  274.     public String readContext(String context, String password) {  
  275.         String text = null;  
  276.         ByteArrayInputStream bis = null;  
  277.         DataInputStream dis = null;  
  278.         try {  
  279.             bis = new ByteArrayInputStream(context.getBytes());  
  280.             dis = new DataInputStream(bis);  
  281.             if (!verify(dis, password)) {  
  282.                 throw new RuntimeException("Password error");  
  283.             }  
  284.             byte[] bytes = read(dis);  
  285.             text = new String(decode(bytes));  
  286.         } catch (Exception e) {  
  287.             e.printStackTrace();  
  288.         } finally {  
  289.             try {  
  290.                 if (dis != null) {  
  291.                     dis.close();  
  292.                     dis = null;  
  293.                 }  
  294.             } catch (Exception e) {  
  295.             }  
  296.         }  
  297.         return text;  
  298.     }  
  299.     /** 
  300.      * 验证指定【WSPZ】类型数据的密码是否正确 
  301.      *  
  302.      * @param context 
  303.      * @param password 
  304.      * @return 
  305.      */  
  306.     public boolean verifyContext(String context, String password) {  
  307.         ByteArrayInputStream bis = null;  
  308.         try {  
  309.             bis = new ByteArrayInputStream(context.getBytes());  
  310.             DataInputStream dis = new DataInputStream(bis);  
  311.             readByteArray(dis, 4);  
  312.             makePassword(password);  
  313.             byte[] crc = readByteArray(dis, passBytes.length);  
  314.             if (checkCRC) {  
  315.                 if (new String(crc).equals(CRC32(password.getBytes(), 0,  
  316.                         password.length()))) {  
  317.                     return true;  
  318.                 }  
  319.             } else {  
  320.                 if (new String(crc).equals(password)) {  
  321.                     return true;  
  322.                 }  
  323.             }  
  324.         } catch (Exception e) {  
  325.             e.printStackTrace();  
  326.         } finally {  
  327.             try {  
  328.                 bis.close();  
  329.             } catch (IOException e) {  
  330.                 // TODO Auto-generated catch block  
  331.                 e.printStackTrace();  
  332.             }  
  333.         }  
  334.         return false;  
  335.     }  
  336.     /** 
  337.      * 验证指定文件的密码是否正确 
  338.      *  
  339.      * @param fileName 
  340.      * @param password 
  341.      * @return 
  342.      */  
  343.     public boolean verify(DataInputStream dis, String password) {  
  344.         try {  
  345.             readByteArray(dis, 4);  
  346.             makePassword(password);  
  347.             byte[] crc = readByteArray(dis, passBytes.length);  
  348.             if (checkCRC) {  
  349.                 if (new String(crc).equals(CRC32(password.getBytes(), 0,  
  350.                         password.length()))) {  
  351.                     return true;  
  352.                 }  
  353.             } else {  
  354.                 if (new String(crc).equals(password)) {  
  355.                     return true;  
  356.                 }  
  357.             }  
  358.         } catch (Exception e) {  
  359.             e.printStackTrace();  
  360.         }  
  361.         return false;  
  362.     }  
  363.     /** 
  364.      * 验证指定文件的密码是否正确 
  365.      *  
  366.      * @param fileName 
  367.      * @param password 
  368.      * @return 
  369.      */  
  370.     public boolean verify(String fileName, String password) {  
  371.         try {  
  372.             File file = new File(fileName);  
  373.             FileInputStream fis = new FileInputStream(file);  
  374.             DataInputStream dis = new DataInputStream(fis);  
  375.             return verify(dis, password);  
  376.         } catch (FileNotFoundException e) {  
  377.         }  
  378.         return false;  
  379.     }  
  380.     /** 
  381.      * 构建一个【WSPZ】类型的加密文本文件 
  382.      *  
  383.      * @param fileName 
  384.      * @param password 
  385.      * @param context 
  386.      */  
  387.     public void makeFile(String fileName, String password, String context) {  
  388.         // 构建密码  
  389.         makePassword(password);  
  390.         String text = encrypt(context);  
  391.         FileOutputStream os = null;  
  392.         DataOutputStream dos = null;  
  393.         try {  
  394.             File file = new File(fileName);  
  395.             os = new FileOutputStream(file);  
  396.             dos = new DataOutputStream(os);  
  397.             dos.write(FILE_FLAG_ID);  
  398.             dos.write(passBytes);  
  399.             dos.write(text.getBytes());  
  400.         } catch (Exception e) {  
  401.             e.printStackTrace();  
  402.         } finally {  
  403.             if (dos != null) {  
  404.                 try {  
  405.                     dos.close();  
  406.                     dos = null;  
  407.                 } catch (IOException e) {  
  408.                 }  
  409.             }  
  410.         }  
  411.     }  
  412.     /** 
  413.      * 获得CRC32化的密码信息 
  414.      *  
  415.      * @return 
  416.      */  
  417.     public String getPassCRC32() {  
  418.         return new String(passBytes);  
  419.     }  
  420.     /** 
  421.      * 构建一个(骗人)的信息文件 
  422.      *  
  423.      * @param fileName 
  424.      * @param password 
  425.      */  
  426.     public static void makeFoolFile(String fileName, String password) {  
  427.         Fool fool = new Fool();  
  428.         fool.makeFile(fileName, password, EMPTY_CONTEXT);  
  429.     }  
  430. }  

 

具体操作如下图所示:

 

1、生成一个“涨价股”信息(当然,里面写什么都无所谓)

 

00

 

2、生成的文本信息如下(我将其转为16进制保存)

 

01

3、这是一个“正版”的“解密锁”没有的功能,那就是在仅仅输入密码时,会将加密的文本文件真正解密出来。

 

02

 

 

4、如果输入为“需要解密的内容”(也就是密码和加密文档的混合体),则会按照输入的内容输出(嗯,也就是学骗子那样,输入什么就显示什么)。

 

04

 

5、说起来这个小应用比“正版”稍稍“顽强”一些,那就是当输入的密码信息,与压缩文件里包含的密码不相同时,系统不会“解密文件”(至少不会像新闻里那样,被随便拼凑的信息能混过关了……)。

 

05

 


下载地址(源码在jar中):http://greenvm.googlecode.com/files/Fraud.jar


严格意义上讲,小弟从来不愿意将这类低级犯罪归结到智能犯罪中,因为这种骗局实在太过肤浅。任凭文章中分析了多少,其实也就是做个加密的文件糊弄事,然后把第二天实际的涨停股“解密”到文件中的小把戏罢了。别的因素且不说,换个稍微有点计算机常识的人遇到这种事,至少也会想想,对方难道不可以用7z或rar这种现成的工具压缩文件吗?如果有20位或以上的密码,就算是CIA级别的机构也未必能在一天内破解出真实内容来,更别说普通人,根本就用不着自己写个解密器嘛(况且它那个解密器要是新出炉的木马,一双击不就杯具了……)。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值