Created
January 8, 2020 15:57
NAs decoding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.oss.nas1570.Nas1570 | |
import com.oss.nas1570.NASCoder; | |
import com.oss.nas1570.Nas1570; | |
import java.nio.ByteBuffer; | |
public class Test { | |
public static void main(String[] args) throws Throwable { | |
// NAS 2.0.0 - nasjava-r15.7.0 | |
Nas1570.initialize(); | |
NASCoder coder = Nas1570.getNASCoder(); | |
System.out.println( | |
coder.decodeToJSON( | |
ByteBuffer.wrap( | |
decodeHexString("2741f768d52a720ec101081a06767a77617070066d6e63343830066d636333313104677072730d030000002672674a010a901b095d013030101b931f7196fefe7603ffff00fa00fa003205833401095e06fefee8e80505274d800003102607f1600010c00800ce000d000000030003102607f1600010c0020000000000000003000d04c6e22494000d04ac10c164802110030000108106c6e224948306ac10c1640010020594") | |
) | |
) | |
); | |
} | |
public static byte[] decodeHexString(String hexString) { | |
if (hexString.length() % 2 == 1) { | |
throw new IllegalArgumentException( | |
"Invalid hexadecimal String supplied."); | |
} | |
byte[] bytes = new byte[hexString.length() / 2]; | |
for (int i = 0; i < hexString.length(); i += 2) { | |
bytes[i / 2] = hexToByte(hexString.substring(i, i + 2)); | |
} | |
return bytes; | |
} | |
public static byte hexToByte(String hexString) { | |
int firstDigit = toDigit(hexString.charAt(0)); | |
int secondDigit = toDigit(hexString.charAt(1)); | |
return (byte) ((firstDigit << 4) + secondDigit); | |
} | |
private static int toDigit(char hexChar) { | |
int digit = Character.digit(hexChar, 16); | |
if (digit == -1) { | |
throw new IllegalArgumentException( | |
"Invalid Hexadecimal Character: " + hexChar); | |
} | |
return digit; | |
} | |
} | |
/* | |
{ | |
"emmMessage":{ | |
"protected":{ | |
"protocolDiscriminator":7, | |
"securityHeaderType":2, | |
"mac":1106733269, | |
"sequenceNumber":42, | |
"message":"720EC101081A06767A77617070066D6E63343830066D636333313104677072730D030000002672674A010A901B095D013030101B931F7196FEFE7603FFFF00FA00FA003205833401095E06FEFEE8E80505274D800003102607F1600010C00800CE000D000000030003102607F1600010C0020000000000000003000D04C6E22494000D04AC10C164802110030000108106C6E224948306AC10C1640010020594" | |
} | |
} | |
} | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment