WEB开发网
开发学院WEB开发Jsp JAVA:附加码生成器(图片) 阅读

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

 2008-01-05 09:00:22 来源:WEB开发网   
核心提示:〔Picture.java〕package creator.common.attachLogin;import java.io.*;public class Picture{ final int key=1; final String error_format_int= "format of color

  〔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 \"2122320\"";

final String error_color_input="format of color(numnumnum): 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++;

}

Tags:JAVA 附加 生成器

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接