| 308 | }; |
| 309 | |
| 310 | public static String enCode64(String s) { |
| 311 | int index = 0; |
| 312 | StringBuilder strBuff = new StringBuilder(); |
| 313 | StringBuilder resultBuff = new StringBuilder(); |
| 314 | while (true) { |
| 315 | |
| 316 | if (index == -1) { |
| 317 | switch (s.length() * 8 % 6) { |
| 318 | case 2: |
| 319 | resultBuff.append('=').append('='); |
| 320 | break; |
| 321 | case 4: |
| 322 | resultBuff.append('='); |
| 323 | break; |
| 324 | } |
| 325 | break; |
| 326 | } |
| 327 | |
| 328 | if (index >= s.length()) { |
| 329 | int zeroCount = 6 - strBuff.length(); |
| 330 | for (int i = 0; i < zeroCount; i++) { |
| 331 | strBuff.append('0'); |
| 332 | } |
| 333 | index = -1; |
| 334 | } |
| 335 | |
| 336 | if (strBuff.length() < 6) { |
| 337 | strBuff.append(getBitStr(s.charAt(index++))); |
| 338 | } |
| 339 | |
| 340 | String temp2 = strBuff.substring(0, 6); |
| 341 | int temp10 = Integer.parseInt(temp2, 2); |
| 342 | resultBuff.append(baseChars[temp10]); |
| 343 | strBuff.delete(0, 6); |
| 344 | } |
| 345 | return resultBuff.toString(); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | public static String getBitStr(char i) { |