1 |
d20f93a2
|
Neels Hofmeyr
|
/* 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 |
|
|
|
31 |
483f5a4f
|
Neels Hofmeyr
|
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 |
|
|
|
60 |
b5ca3124
|
Neels Hofmeyr
|
private static void test_toStr()
|
61 |
|
|
{
|
62 |
|
|
byte nr = -128;
|
63 |
|
|
while (true) {
|
64 |
|
|
System.out.println("" + nr + " = '" + new String(Bytes.toStr(nr)) + "'");
|
65 |
|
|
if (nr == 127)
|
66 |
|
|
break;
|
67 |
|
|
nr++;
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
|
71 |
d20f93a2
|
Neels Hofmeyr
|
public static void main(String args[]){
|
72 |
483f5a4f
|
Neels Hofmeyr
|
test_str2mi2str();
|
73 |
b5ca3124
|
Neels Hofmeyr
|
test_toStr();
|
74 |
d20f93a2
|
Neels Hofmeyr
|
}
|
75 |
|
|
}
|