Skip to content

Instantly share code, notes, and snippets.

@stephenjtong
Last active December 13, 2015 20:29
Show Gist options
  • Save stephenjtong/4970583 to your computer and use it in GitHub Desktop.
Save stephenjtong/4970583 to your computer and use it in GitHub Desktop.
字符串编码,解码使用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