论坛首页 入门技术论坛

请教加密代码原理

浏览 1475 次
该帖已经被评为新手帖
作者 正文
   发表时间:2008-02-21  
import java.io.*;

public class WriteBin {

public static void main(String[] str) {
readTest();
for(int i=0; i<=3;i++){
System.out.println("nDrawPos=" + nDrawPos[i]);
nDrawPos[i]=jiami(nDrawPos[i]);
System.out.println("after=" + nDrawPos[i]);
}

writenDrawPos("c:/miglove.bin");
}

static String nDrawPos[];

//----------------------------------------------------------------------------
public static String jiami(String s){
String ss = "";
byte[] b = s.getBytes();
for(int i=0; i<b.length;i++){
b[i] = (byte)(b[i] + 7);
}
return new String(b);
}

//----------------------------------------------------------------------------读

public static void readTest() {
try {
DataInputStream is = new DataInputStream(new FileInputStream("c:/test.txt"));
nDrawPos = new String[19];
readLine(is);
for (int i = 0; i < nDrawPos.length; i++) {
nDrawPos[i] = readLine(is);
}
is.close();
is = null;
}
catch (Exception ex) {}

}

public static String readLine(InputStream is) throws IOException {
try {
byte[] data;
String str;
int b;
ByteArrayOutputStream baos;
baos = new ByteArrayOutputStream();
b = 0;
while ( (b = is.read()) != -1) {
if (b == 10) {
break;
}
if (b != 13) {
baos.write(b);
}
}
baos.close();
data = baos.toByteArray();
if (data.length > 0) {
str = convertFromUTF8(data);
}
else if (b != -1) {
str = null;
}
else {
str = "";
}
baos = null;
return str;
}
catch (Exception e) {
return "x";
}
}

public static String convertFromUTF8(byte[] data) {
if (data == null) {
return null;
}
try {
int len = data.length;
byte[] newdata = new byte[len + 2];
newdata[0] = (byte) (len >>>;
newdata[1] = (byte) len;
System.arraycopy(data, 0, newdata, 2, len);
ByteArrayInputStream bis = new ByteArrayInputStream(newdata);
DataInputStream dis = new DataInputStream(bis);
return dis.readUTF();
}
catch (Exception e) {
// System.out.println(e + " Bad UTF8 string");
return null;
}
}

//----------------------------------------------------------------------------写
private static void writenDrawPos(String fileName) {
try {
DataOutputStream dos = new DataOutputStream(new FileOutputStream(fileName));
dos.writeShort(nDrawPos.length);

for (int i = 0; i < nDrawPos.length; i++) {
String temp = nDrawPos[i];
dos.writeUTF(temp);
}

dos.flush();
dos.close();
}
catch (Exception ex) {}
}

}
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics