📄 base32.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: Base32.java
package org.gudy.azureus2.core3.util;
public class Base32
{
private static final String base32Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
private static final int base32Lookup[] = {
255, 255, 26, 27, 28, 29, 30, 31, 255, 255,
255, 255, 255, 255, 255, 255, 255, 0, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 255, 255, 255, 255, 255, 255, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 255, 255, 255, 255, 255
};
public Base32()
{
}
public static String encode(byte bytes[])
{
int i = 0;
int index = 0;
int digit = 0;
StringBuffer base32 = new StringBuffer(((bytes.length + 7) * 8) / 5);
for (; i < bytes.length; base32.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567".charAt(digit)))
{
int currByte = bytes[i] < 0 ? bytes[i] + 256 : ((int) (bytes[i]));
if (index > 3)
{
int nextByte;
if (i + 1 < bytes.length)
nextByte = bytes[i + 1] < 0 ? bytes[i + 1] + 256 : ((int) (bytes[i + 1]));
else
nextByte = 0;
digit = currByte & 255 >> index;
index = (index + 5) % 8;
digit <<= index;
digit |= nextByte >> 8 - index;
i++;
continue;
}
digit = currByte >> 8 - (index + 5) & 0x1f;
index = (index + 5) % 8;
if (index == 0)
i++;
}
return base32.toString();
}
public static byte[] decode(String base32)
{
byte bytes[] = new byte[(base32.length() * 5) / 8];
if (bytes.length == 0)
return bytes;
int i = 0;
int index = 0;
int offset = 0;
for (; i < base32.length(); i++)
{
int lookup = base32.charAt(i) - 48;
if (lookup < 0 || lookup >= base32Lookup.length)
continue;
int digit = base32Lookup[lookup];
if (digit == 255)
continue;
if (index <= 3)
{
index = (index + 5) % 8;
if (index == 0)
{
bytes[offset] |= digit;
if (++offset >= bytes.length)
break;
} else
{
bytes[offset] |= digit << 8 - index;
}
continue;
}
index = (index + 5) % 8;
bytes[offset] |= digit >>> index;
if (++offset >= bytes.length)
break;
bytes[offset] |= digit << 8 - index;
}
return bytes;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -