JAVA:附加码生成器(图片)

2008-02-23 10:07:28来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

〔Picture.Java〕

package creator.common.attachLogin;

import java.io.*;

public class Picture{

final int key=1;

final String error_format_int= "format of color is not rgb.sample \"212|232|0\"";

final String error_color_input="format of color(num|num|num): num in 0-255";

/**格式化输出数据**/

public String manage(String temp){

String returnStr="";

temp = encrypt(temp);

byte[] by =temp.getBytes();

for(int i=0;i<by.length;i ){

returnStr=returnStr (byte)by[i] "|";

}

return returnStr;

}

/**格式化输入数据**/

public byte[] disManage(String temp){

int len=0,index=0,i=0,first=0;

while(( i=temp.indexOf("|",first))>-1){

len ;

first=i 1;

}

byte[] by=new byte[len];

first=0;

while(( i=temp.indexOf("|",first))>-1){

by[index]=Byte.parseByte(temp.substring(first,i));

index ;

first=i 1;

}

return by;

}

/**随机生成四位的附加码**/

public String getRandom(){

int i1 = (int)(java.lang.Math.random()*10);

int i2 = (int)(java.lang.Math.random()*10);

int i3 = (int)(java.lang.Math.random()*10);

int i4 = (int)(java.lang.Math.random()*10);

return String.valueOf(i1) String.valueOf(i2) String.valueOf(i3) String.valueOf(i4);

}

/**加密1:错位处理**/

public String encrypt(String randomStr){

String para=random() randomStr.substring(0,1) random() random() randomStr.substring(1,2);

para= para random() randomStr.substring(2);

return jiaMi(para);

}

/**得到随机数0-9之间**/

private String random(){

String temp = String.valueOf((int)(java.lang.Math.random()*10));

return temp;

}

/**加密2:加密处理,此方法可以自己修改**/

private String jiaMi(String str){

byte[] by = str.getBytes();

ByteArrayInputStream in = new ByteArrayInputStream(by);

int ch;

int index=0;

byte[] temp = new byte[in.available()];

while((ch=in.read())!=-1){

temp[index]=(byte)(ch-key);

index ;

}

ByteArrayInputStream ins = new ByteArrayInputStream(temp);

BufferedReader fReader = new BufferedReader(new InputStreamReader(ins));


try{ return fReader.readLine();}catch(Exception e){return "";}

}

/**从给的数字里得到正确的数字**/

public String discrypt(String temp){

String para = jieMi(disManage(temp));

return para.substring(1,2) para.substring(4,5) para.substring(6,8);

}

/**解密处理**/

private String jieMi(byte[] by){

ByteArrayInputStream in = new ByteArrayInputStream(by);

int ch;

int index=0;

byte[] temp = new byte[in.available()];

while((ch=in.read())!=-1){

temp[index]=(byte)(ch key);

index ;

}

ByteArrayInputStream ins = new ByteArrayInputStream(temp);

BufferedReader fReader = new BufferedReader(new InputStreamReader(ins));

try{ return fReader.readLine();}catch(Exception e){return "";}

}

/**分解rgb格式的颜色 num|num|num**/

public int[] masterData(String temp){

int index_len=0,index=0,next_index=0;

int[] return_arr=new int[3];

boolean break_error=false;

if(getMax(temp,"|")==2){

while((index_len=temp.indexOf("|",next_index))>-1){

if(getInt(temp.substring(next_index,index_len))==256){

break_error = true;

}else{

return_arr[index]=getInt(temp.substring(next_index,index_len));

next_index=index_len 1;

index ;

}

if(break_error) break;

}

if(break_error){

return null;

}else{

return_arr[index] = getInt(temp.substring(next_index));

return return_arr;

}

}else{

System.out.println(error_format_int ":" temp);

return null;

}

}

private int getMax(String temp,String temp2){

int index=0,index_len=0,index_next=0;

while((index=temp.indexOf(temp2,index_next))>-1){

index_len ;

index_next=index 1;

}

return index_len;

}

private int getInt(String temp){

try{

return Integer.parseInt(temp);

}catch(Exception e){

System.out.println(error_color_input ":" temp);

return 256;

}

}

}

〔CreateImage.java〕

package creator.common.attachLogin;

import java.io.*;

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:strutsr源码解读

下一篇:JAVA:Filter编码器