Fix base64 decoding on Windows 11 arm64

This commit is contained in:
UnfamiliarLegacy 2024-06-28 17:33:02 +02:00
parent ba98a0689b
commit 14f6571764
2 changed files with 36 additions and 14 deletions

View File

@ -5,8 +5,6 @@ package gearth.encoding;
* <a href="https://github.com/Quackster/Kepler">Kepler</a>
*/
public class Base64Encoding {
public byte NEGATIVE = 64;
public byte POSITIVE = 65;
public static byte[] encode(int i, int numBytes) {
byte[] bzRes = new byte[numBytes];
@ -19,20 +17,19 @@ public class Base64Encoding {
return bzRes;
}
public static int decode(byte[] bzData) {
int i = 0;
int j = 0;
for (int k = bzData.length - 1; k >= 0; k--)
public static int decode(byte[] data) {
int res = 0;
for (int k = data.length - 1, i = 0; k >= 0; k--, i++)
{
int x = bzData[k] - 0x40;
if (j > 0)
x *= (int)Math.pow(64.0, (double)j);
i += x;
j++;
}
return i;
int x = data[k] - 0x40;
if (i > 0){
res += x << (i * 6);
} else {
res += x;
}
}
return res;
}
}

View File

@ -0,0 +1,25 @@
import gearth.encoding.Base64Encoding;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestBase64Encoding {
@Test
public void testBase64Encoding() {
testDecode(0, "@@");
testDecode(202, "CJ");
testDecode(206, "CN");
testDecode(277, "DU");
testDecode(1337, "@Ty");
}
private void testDecode(int expected, String input) {
final byte[] header = input.getBytes(StandardCharsets.ISO_8859_1);
assertEquals(expected, Base64Encoding.decode(header));
}
}