mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-30 04:00:50 +01:00
Fix base64 decoding on Windows 11 arm64
This commit is contained in:
parent
ba98a0689b
commit
14f6571764
@ -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--)
|
||||
{
|
||||
int x = bzData[k] - 0x40;
|
||||
if (j > 0)
|
||||
x *= (int)Math.pow(64.0, (double)j);
|
||||
public static int decode(byte[] data) {
|
||||
int res = 0;
|
||||
|
||||
i += x;
|
||||
j++;
|
||||
for (int k = data.length - 1, i = 0; k >= 0; k--, i++)
|
||||
{
|
||||
int x = data[k] - 0x40;
|
||||
if (i > 0){
|
||||
res += x << (i * 6);
|
||||
} else {
|
||||
res += x;
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
25
G-Earth/src/test/java/TestBase64Encoding.java
Normal file
25
G-Earth/src/test/java/TestBase64Encoding.java
Normal 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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user