Instantly share code, notes, and snippets.

@sdpfoue sdpfoue/DC_encode.java
Last active Dec 13, 2015

Embed
What would you like to do?
字符串编码,解码使用dc -e密文P
//decode result with dc command like dc -e0000P
import java.math.BigInteger;
public class DC_encode {
public static void main(String[] args) {
String a="";
String b=args[0]+"\n";
for(int i=0;i<b.length();i++){
if(Integer.toBinaryString(b.charAt(i)).length()==8)
a=a+Integer.toBinaryString(b.charAt(i));
else{
for(int n=0;n<8-Integer.toBinaryString(b.charAt(i)).length();n++)//补位
a=a+'0';
a=a+Integer.toBinaryString(b.charAt(i));
}
}
//System.out.println(a);
BigInteger bigInt = new BigInteger(a,2);
System.out.println(bigInt);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment