package org.stevewinfield.sunrise.util;

public class B64Encoding {
	public static String encode(int i) { 
        try 
        { 
            String s = ""; 
            for (int x = 1; x <= 2; x++) 
                s += (char)((byte)(64 + (i >> 6 * (2 - x) & 0x3f))); 
            return s; 
        } catch (Exception e) { 
            System.out.println(e.toString()); 
            return ""; 
        }         
    } 
    public static int decode(String s) { 
        try { 
            char[] val = s.toCharArray(); 
            int intTot = 0; 
            int y = 0; 
            for (int x = (val.length - 1); x >= 0; x--) 
            { 
                int intTmp = (int)(byte)((val[x] - 64)); 
                if (y > 0) 
                    intTmp = intTmp * (int)(Math.pow(64, y)); 
                intTot += intTmp; 
                y++; 
            } 
            return intTot; 
        } catch (Exception e) { 
            System.out.println(e.toString()); 
            return 0; 
        }     
    } 
}
