import java.util.List;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
/**
* @author Victor
*/
public class Main {
public static void main
(String[] args
) { // Passa o alfabeto como parâmetro. Tem 62 caracteres aqui, então são 62 símbolos.
BaseN bn = new BaseN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
String x
= "The quick brown fox jumps over a lazy dog"; System.
out.
println(a
); // Escreve "1u9WLfG65OMtVkQWPtWDcC6o8IjI5td5l9DzpilIK4Nyx81tKLRrStPj" System.
out.
println(b
); // Escreve "The quick brown fox jumps over a lazy dog" }
}
class BaseN {
this.base = base;
}
byte[] bytes = text.getBytes();
for (byte b : bytes) {
big
= big.
multiply(BI_256
).
add(BigInteger.
valueOf(b
)); }
StringBuilder sb = new StringBuilder(bytes.length * 4 / 3 + 2);
BigInteger[] parts
= big.
divideAndRemainder(radix
); int small = parts[1].intValue();
big = parts[0];
sb.append(base.charAt(small));
}
return sb.reverse().toString();
}
for (char c : text.toCharArray()) {
int i = base.indexOf(c);
big
= big.
multiply(radix
).
add(BigInteger.
valueOf(i
)); }
List<Byte> byteList = new ArrayList<>(text.length());
BigInteger[] parts
= big.
divideAndRemainder(BI_256
); int small = parts[1].intValue();
big = parts[0];
byteList.add((byte) small);
}
byte[] r = new byte[byteList.size() - 1];
int i = 0;
for (Byte b
: byteList
) { if (i > 0) r[i - 1] = b;
i++;
}
}
}
aW1wb3J0IGphdmEudXRpbC5MaXN0OwppbXBvcnQgamF2YS5tYXRoLkJpZ0ludGVnZXI7CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwppbXBvcnQgamF2YS51dGlsLkNvbGxlY3Rpb25zOwoKLyoqCiAqIEBhdXRob3IgVmljdG9yCiAqLwpwdWJsaWMgY2xhc3MgTWFpbiB7CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIC8vIFBhc3NhIG8gYWxmYWJldG8gY29tbyBwYXL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