// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class RadixFun2 {
    private static String DIGITS = "0123456789abcdefghijklmnpqrstuvwxyzWXYZ";
    private static int fromAny(String s, int radix) {
        int res = 0;
        char[] sa = s.toCharArray();
        int sign = 1;
        for (int i = 0; i < s.length(); i++) {
            if(sa[i] != '-') {
                res = res * radix + DIGITS.indexOf(sa[i]);
            } else {
                sign = -1;
            }
        }
        return sign * res;
    }
    private static String toAny(int i, int radix) {
        if(i >= 0) {
            String res = "";
            int tmp = i;
            while (tmp > 0) {
                res = DIGITS.toCharArray()[tmp % radix] + res;
                tmp = tmp / radix;
            }
            return res;
        } else {
            return "-" + toAny(-i, radix);
        }
    }
    public static String enc(String s) {
        return toAny(fromAny(s, 10), 36);
    }
    public static String dec(String s) {
        return toAny(fromAny(s, 36), 10);
    }
    public static void main(String[] args) {
        String s1 = "123456789";
        String s2 = enc(s1);
        String s3 = dec(s2);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
}
