日期:2014-05-20 浏览次数:21126 次
package d_port_package;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
public class Lib {
static InputStream inputstream = null;
static OutputStream outputstream = null;
static String MyKey = "CJCO5882";
static PrintStream ps;
static BufferedReader br;
static String buffer0;
static OutputStream os = null;
static String readsocketUTF(Socket s){
String info = "";
// 启用输入流
InputStream is = null;
try {
is = s.getInputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
InputStreamReader isr = new InputStreamReader(is);
br = new BufferedReader(isr);
try {
buffer0 = br.readLine() + "\r\n";
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
info = Systemcrypt.HloveyRC4(buffer0.trim(),MyKey);
return info;
}
static void write(Socket s,String str0){
try {
os = s.getOutputStream();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ps = new PrintStream(os);
String str = Systemcrypt.HloveyRC4(str0,MyKey);
try {
os = s.getOutputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ps.println(str);
}
}
package d_port_package;
public class Systemcrypt{
public static String HloveyRC4(String aInput,String aKey)
{
int[] iS = new int[256];
byte[] iK = new byte[256];
for (int i=0;i<256;i++)
iS[i]=i;
int j = 1;
for (short i= 0;i<256;i++)
{
iK[i]=(byte)aKey.charAt((i % aKey.length()));
}
j=0;
for (int i=0;i<255;i++)
{
j=(j+iS[i]+iK[i]) % 256;
int temp = iS[i];
iS[i]=iS[j];
iS[j]=temp;
}
int i=0;
j=0;
char[] iInputChar = aInput.toCharArray();
char[] iOutputChar = new char[iInputChar.length];