Neels Hofmeyr | d20f93a | 2020-02-24 22:42:22 +0100 | [diff] [blame] | 1 | /* Copyright 2020 sysmocom s.f.m.c. GmbH |
| 2 | * SPDX-License-Identifier: Apache-2.0 */ |
| 3 | package org.osmocom.IMSIPseudo; |
| 4 | import org.osmocom.IMSIPseudo.*; |
| 5 | |
| 6 | public class Test { |
| 7 | private static byte nibble2hex(byte nibble) |
| 8 | { |
| 9 | nibble = (byte)(nibble & 0xf); |
| 10 | if (nibble < 0xa) |
| 11 | return (byte)('0' + nibble); |
| 12 | else |
| 13 | return (byte)('a' + nibble - 0xa); |
| 14 | } |
| 15 | |
| 16 | private static byte[] hexdump(byte data[]) |
| 17 | { |
| 18 | byte res[] = new byte[(byte)(data.length*2)]; |
| 19 | for (byte i = 0; i < data.length; i++) { |
| 20 | res[(byte)(i*2)] = nibble2hex((byte)(data[i] >> 4)); |
| 21 | res[(byte)(i*2 + 1)] = nibble2hex(data[i]); |
| 22 | } |
| 23 | return res; |
| 24 | } |
| 25 | |
| 26 | private static String hexdumpStr(byte data[]) |
| 27 | { |
| 28 | return new String(hexdump(data)); |
| 29 | } |
| 30 | |
Neels Hofmeyr | 483f5a4 | 2020-02-25 03:06:12 +0100 | [diff] [blame^] | 31 | private static final String[] imsis = { |
| 32 | "123456", |
| 33 | "1234567", |
| 34 | "12345678", |
| 35 | "123456789", |
| 36 | "1234567890", |
| 37 | "12345678901", |
| 38 | "123456789012", |
| 39 | "1234567890123", |
| 40 | "12345678901234", |
| 41 | "123456789012345", |
| 42 | "1234567890123456", |
| 43 | }; |
| 44 | |
| 45 | private static void test_str2mi2str() |
| 46 | { |
| 47 | for (int i = 0; i < imsis.length; i++) { |
| 48 | byte str[] = imsis[i].getBytes(); |
| 49 | byte mi[] = MobileIdentity.str2mi(str, MobileIdentity.MI_IMSI, (byte)9); |
| 50 | byte str_from_mi[] = MobileIdentity.mi2str(mi); |
| 51 | System.out.print("IMSI " + new String(str) + " --> MI " + hexdumpStr(mi) + " --> IMSI " |
| 52 | + new String(str_from_mi)); |
| 53 | if (Bytes.equals(str, str_from_mi)) |
| 54 | System.out.println(" (ok)"); |
| 55 | else |
| 56 | System.out.println(" ERROR!"); |
| 57 | } |
| 58 | } |
| 59 | |
Neels Hofmeyr | d20f93a | 2020-02-24 22:42:22 +0100 | [diff] [blame] | 60 | public static void main(String args[]){ |
Neels Hofmeyr | 483f5a4 | 2020-02-25 03:06:12 +0100 | [diff] [blame^] | 61 | test_str2mi2str(); |
Neels Hofmeyr | d20f93a | 2020-02-24 22:42:22 +0100 | [diff] [blame] | 62 | } |
| 63 | } |