请教加密代码原理

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 >>> 8);
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) {}
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值