package org.egret.java.MahjongAndroid.utils;
import java.io.*;
public class Base64
{
private static final char legalChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
public Base64()
{
}
private static int decode(char c)
{
if (c >= 'A' && c <= 'Z')
return c - 65;
if (c < 'a' || c > 'z') goto _L2; else goto _L1
_L1:
int i = c - 97;
_L4:
return i + 26;
_L2:
if (c < '0' || c > '9')
break; /* Loop/switch isn't completed */
i = (c - 48) + 26;
if (true) goto _L4; else goto _L3
_L3:
if (c != '+')
{
if (c != '/')
{
if (c == '=')
{
return 0;
} else
{
StringBuilder stringbuilder = new StringBuilder();
stringbuilder.append("unexpected code: ");
stringbuilder.append(c);
throw new RuntimeException(stringbuilder.toString());
}
} else
{
return 63;
}
} else
{
return 62;
}
}
private static void decode(String s, OutputStream outputstream)
throws IOException
{
int j = s.length();
do
{
int i;
for (i = 0; i < j && s.charAt(i) <= ' '; i++);
if (i == j)
return;
int i1 = decode(s.charAt(i));
int j1 = decode(s.charAt(i + 1));
int k = i + 2;
int k1 = decode(s.charAt(k));
int l = i + 3;
i1 = (i1 << 18) + (j1 << 12) + (k1 << 6) + decode(s.charAt(l));
outputstream.write(i1 >> 16 & 0xff);
if (s.charAt(k) == '=')
return;
outputstream.write(i1 >> 8 & 0xff);
if (s.charAt(l) == '=')
return;
outputstream.write(i1 & 0xff);
i += 4;
} while (true);
}
public static byte[] decode(String s)
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
try
{
decode(s, ((OutputStream) (bytearrayoutputstream)));
}
// Misplaced declaration of an exception variable
catch (String s)
{
throw new RuntimeException();
}
s = bytearrayoutputstream.toByteArray();
try
{
bytearrayoutputstream.close();
}
catch (Exception exception)
{
exception.printStackTrace();
return s;
}
return s;
}
public static String encode(byte abyte0[])
{
int k = abyte0.length;
StringBuffer stringbuffer = new StringBuffer((abyte0.length * 3) / 2);
int i = 0;
label0:
do
{
int j = 0;
do
{
if (i > k - 3)
break;
int l = (abyte0[i] & 0xff) << 16 | (abyte0[i + 1] & 0xff) << 8 | abyte0[i + 2] & 0xff;
stringbuffer.append(legalChars[l >> 18 & 0x3f]);
stringbuffer.append(legalChars[l >> 12 & 0x3f]);
stringbuffer.append(legalChars[l >> 6 & 0x3f]);
stringbuffer.append(legalChars[l & 0x3f]);
i += 3;
if (j >= 14)
{
stringbuffer.append("");
continue label0;
}
j++;
} while (true);
j = 0 + k;
if (i == j - 2)
{
j = abyte0[i];
i = (abyte0[i + 1] & 0xff) << 8 | (j & 0xff) << 16;
stringbuffer.append(legalChars[i >> 18 & 0x3f]);
stringbuffer.append(legalChars[i >> 12 & 0x3f]);
stringbuffer.append(legalChars[i >> 6 & 0x3f]);
stringbuffer.append("=");
} else
if (i == j - 1)
{
i = (abyte0[i] & 0xff) << 16;
stringbuffer.append(legalChars[i >> 18 & 0x3f]);
stringbuffer.append(legalChars[i >> 12 & 0x3f]);
stringbuffer.append("==");
}
return stringbuffer.toString();
} while (true);
}
}