So my code is: But if I run this.I got java.lang.ArrayIndexOutOfBoundsException Even if i try to encode some Chinese characters or Janpanese characters like "测试一下" Don't ask me to add a try catch or OutOfBounds check
(Because it will change the result to which is unable to verify)
(If encode "TestThissjkdajld9999kdjalyyy".It works without exception.)
Thanks.
public class Main {
public static final String l = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
public String encode (String fucyo) {
char[] av = l.toCharArray();
char[] testssdvx = fucyo.toCharArray();
int length = testssdvx.length;
int now = 1;
String result = "";
while(now < length-1) {
synchronized(this) {
System.out.println(testssdvx[now]);
System.out.println(testssdvx[now+1]);
result += av[(testssdvx[now]>>2)];
result += av[((testssdvx[now]&3)<<4) + (testssdvx[now+1]>>4 )];
result += av[((testssdvx[now+1]&15)<<2)+ (testssdvx[now+2]>>6)];
result += av[(testssdvx[now+2] & 63)];
now +=3;
}
}
System.out.println("Pre:"+result);
char[] charArray = result.toCharArray();
result = "";
for (int i=charArray.length-1; i>=0; i--){
result += charArray[i];
}
return result;
}
public static void main(String[] args) {
System.out.println(new Main().encode("TestThissjkdajldjalksdjalkdjalksdjskladjciiiiiiii78787875ytyyyyyyyyyyyyy"));
}
}