java base64


public static String decode(String str62) {
String[] ss = split(str62, 4);
StringBuilder sb = null;
for (String s : ss) {
s = toDecString(s);
if (sb == null) {
sb = new StringBuilder(s);
} else {
sb.append(format(s, 7));
}
}
return sb.toString();
}


private static String format(String str, int len) {
if (len <= str.length()) {
return str;
}
char[] cs = new char[len];
Arrays.fill(cs, '0');
return String.copyValueOf(cs, 0, len - str.length()) + str;
}

private static String toDecString(String str62) {
long res = 0;
int len = str62.length();
for (int ii = 0; ii < len; ii++) {
long atom = (long) Math.pow(62, len - ii - 1);
res = res + atom * convert2Int(str62.charAt(ii));
}
return String.valueOf(res);
}


private static int convert2Int(char c) {
if (c >= 48 && c <= 57) {//0-9
return c - 48;
} else if (c >= 97 && c <= 122) {//a-z
return c - 87;
} else if (c >= 65 && c <= 90) {//A-Z
return c - 29;
} else {//不支持的字符
return -1;
}
}

private static String[] split(String s, int len) {
int count = s.length();
int nn = count % len;
int size = (nn > 0) ? count / len + 1 : count / len;
String[] res = new String[size];
nn = nn > 0 ? nn : len;
res[0] = s.substring(0, nn);
for (int ii = 1; ii < size; ii++) {
res[ii] = s.substring((ii - 1) * len + nn, ii * len + nn);
}
return res;
}

public static void main(String[] args) {
Test test = new Test();
//http://weibo.com/3173644855/zDl0ZAVZC
String s=test.decode("zDl0ZAVZC");
System.out.println(s);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值