@Test public void shouldDecodeBase90UnsignedCorrectly() { assertEquals(90, decodeBase90("#!", false)); assertEquals(89, decodeBase90("~", false)); assertEquals(0, decodeBase90("!", false)); assertEquals(1, decodeBase90("#", false)); assertEquals(8100, decodeBase90("#!!", false)); assertEquals(8099, decodeBase90("~~", false)); assertEquals(12345, decodeBase90("#S2", false)); }
public static long decodeBase90(CharSequence charSequence, boolean signed) { long sum = 0; long sign = 1; int len = charSequence.length(); for (int i = 0; i < len; i++) { final int c = (int) charSequence.charAt(i); int add = decodeChar(c); if (signed && (i == 0) && (c >= MIDDLE_CHAR)) { add -= BASE45; sign = -1; } sum = (sum * (long) BASE90) + (long) add; } return sum * sign; }
CookieSafeBase90 { public static long decodeBase90(CharSequence charSequence, boolean signed) { long sum = 0; long sign = 1; int len = charSequence.length(); for (int i = 0; i < len; i++) { final int c = (int) charSequence.charAt(i); int add = decodeChar(c); if (signed && (i == 0) && (c >= MIDDLE_CHAR)) { add -= BASE45; sign = -1; } sum = (sum * (long) BASE90) + (long) add; } return sum * sign; } }
CookieSafeBase90 { public static long decodeBase90(CharSequence charSequence, boolean signed) { long sum = 0; long sign = 1; int len = charSequence.length(); for (int i = 0; i < len; i++) { final int c = (int) charSequence.charAt(i); int add = decodeChar(c); if (signed && (i == 0) && (c >= MIDDLE_CHAR)) { add -= BASE45; sign = -1; } sum = (sum * (long) BASE90) + (long) add; } return sum * sign; }  }
CookieSafeBase90 { public static long decodeBase90(CharSequence charSequence, boolean signed) { long sum = 0; long sign = 1; int len = charSequence.length(); for (int i = 0; i < len; i++) { final int c = (int) charSequence.charAt(i); int add = decodeChar(c); if (signed && (i == 0) && (c >= MIDDLE_CHAR)) { add -= BASE45; sign = -1; } sum = (sum * (long) BASE90) + (long) add; } return sum * sign; }  static String encodeBase45(long value, boolean highRange, boolean flipLastByte); static String encodeBase90Unsigned(long value); static String encodeBase90Signed(long value); static String encodeBytesBase90(byte[] bytes); static byte[] decodeBytesBase90(CharSequence charSequence); static long decodeBase90(CharSequence charSequence, boolean signed); static long decodeBase45(CharSequence charSequence); }
CookieSafeBase90 { public static long decodeBase90(CharSequence charSequence, boolean signed) { long sum = 0; long sign = 1; int len = charSequence.length(); for (int i = 0; i < len; i++) { final int c = (int) charSequence.charAt(i); int add = decodeChar(c); if (signed && (i == 0) && (c >= MIDDLE_CHAR)) { add -= BASE45; sign = -1; } sum = (sum * (long) BASE90) + (long) add; } return sum * sign; }  static String encodeBase45(long value, boolean highRange, boolean flipLastByte); static String encodeBase90Unsigned(long value); static String encodeBase90Signed(long value); static String encodeBytesBase90(byte[] bytes); static byte[] decodeBytesBase90(CharSequence charSequence); static long decodeBase90(CharSequence charSequence, boolean signed); static long decodeBase45(CharSequence charSequence); static final int MIDDLE_CHAR; }