大神。等待你来放大招!java解密.求解救!!!(标题一定要长。。。)

壹爱 发布于 2014/03/14 21:22
阅读 199
收藏 0

先上源码! 各位大神,请上眼.....

public static void main(String[] args) {
		String code ="username=111111&sign=87ed049818bc62da28bea8ffd5b0ede6&serverip=127.0.0.1&port=9900&url=http://127.0.0.1:8080";
		try {
			String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
			code = new String(org.apache.commons.codec.binary.Hex.encodeHex(code.getBytes("utf-8")));
			code = code.toLowerCase();
			char[] chs = new char[code.length()];
			for (int i = 0; i < code.length(); i++) {
				int addx = i % 62;
				int c = code.charAt(i);;
				int dx = chars.indexOf(c);
				dx += addx;
				dx %= 62;
				chs[i] = chars.charAt(dx);
			}
			System.out.println(new String(chs));
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}



我的问题是:想把加密以后的串,逆推回来!

奈何水平有限。看了半天代码都没看的懂。。。。。。。。 求勿喷.

加载中
0
vidy_tu
vidy_tu
import org.apache.commons.codec.binary.Hex;

public class TestEnc {
	public static String enc(String code, String chars) throws Exception {
		code = new String(Hex.encodeHex(code.getBytes("utf-8")));
		code = code.toLowerCase();
		char[] chs = new char[code.length()];
		for (int i = 0; i < code.length(); i++) {
			int addx = i % 62;
			int c = code.charAt(i);
			;
			int dx = chars.indexOf(c);
			dx += addx;
			dx %= 62;
			chs[i] = chars.charAt(dx);
		}
		return new String(chs);
	}

	public static String dec(String code, String chars) throws Exception {
		char[] chs = new char[code.length()];
		for (int i = 0; i < code.length(); i++) {
			int dx = chars.indexOf(code.charAt(i));
			char addx = (char) (i % 62);
			dx = (char) ((dx + 62 - addx) % 62);
			char c = chars.charAt(dx);
			chs[i] = c;
		}
		byte[] tmp = Hex.decodeHex(chs);
		return new String(tmp, "utf-8");
	}

	public static void main(String[] args) throws Exception {
		String code = "username=111111&sign=87ed049818bc62da28bea8ffd5b0ede6&serverip=127.0.0.1&port=9900&url=http://127.0.0.1:8080";
		String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		String encCode = enc(code, chars);
		System.out.println(encCode);
		String decCode = dec(encCode, chars);
		System.out.println(decCode);
	}
}



壹爱
壹爱
哦。忘了说 very thank 。么么哒。。。
壹爱
壹爱
大神。你为何这么吊啊。
返回顶部
顶部