-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdu_decode.java
More file actions
160 lines (143 loc) · 3.72 KB
/
pdu_decode.java
File metadata and controls
160 lines (143 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import java.io.*;
import java.util.*;
class convert1
{
public String ByteSwapStr(String v)
{
String out="";
for(int i=0;i<v.length();i+=2)
{
String temp=v.substring(i,i+2);
out=out+temp.charAt(1)+temp.charAt(0);
}
return out;
}
public String TimeStampConverter(String v)
{
String out="";
String date=v.substring(0,6);
String rev_date= new StringBuffer(date).reverse().toString();
out+=rev_date.substring(4,6)+"/"+rev_date.substring(2,4)+"/"+rev_date.substring(0,2)+" ";
String time=v.substring(6,12);
time=this.ByteSwapStr(time);
out+=time.substring(0,2)+":"+time.substring(2,4)+":"+time.substring(4,6);
return out;
}
public String Decode(String v,int length)
{
String bit_string="";
String []oct_array=new String[length];
String []rest_array=new String[length];
String []sept_array=new String[length];
int count=0,s=1;
String text_msg="";
int length_count=0;
for(int i=0;i<v.length();i+=2)
{
String var=v.substring(i,i+2);
try
{
String temp=Integer.toBinaryString(Integer.parseInt(var,16));
int len=temp.length();
if(len!=8)
{
for(int j=0;j<8-len;j++)
temp="0"+temp;
//System.out.println(var+":"+temp);
bit_string+=temp;
}
else
{
//System.out.println(var+":"+temp);
bit_string+=temp;
}
}
catch( java.lang.NumberFormatException e)
{}
}
for(int i=0;i<bit_string.length();i+=8)
{
oct_array[count]=bit_string.substring(i,i+8);
rest_array[count]=oct_array[count].substring(0,s%8);
sept_array[count]=oct_array[count].substring((s%8),8);
s++;
count++;
if(s==8)
{
s=1;
}
}
for(int i=0;i<rest_array.length;i++)
{
try
{
if(i%7==0)
{
if(i!=0)
{
text_msg+=(char) Integer.parseInt( (Integer.toHexString(Integer.parseInt(rest_array[i-1],2))),16);
length_count++;
}
text_msg+=(char) Integer.parseInt( (Integer.toHexString(Integer.parseInt(sept_array[i],2))),16);
length_count++;
}
else
{
text_msg+=(char) Integer.parseInt( (Integer.toHexString(Integer.parseInt((sept_array[i]+rest_array[i-1]),2))) ,16);
length_count++;
}
}
catch ( java.lang.NumberFormatException e)
{ }
}
try
{
if(length_count!=length)
{
text_msg+=(char)Integer.parseInt( (Integer.toHexString(Integer.parseInt(rest_array[rest_array.length]))),16 );
}
}
catch( java.lang.ArrayIndexOutOfBoundsException ee)
{ }
return text_msg.substring(0,length);
}
}
public class pdu_decode
{
String decodable_str;
String smsc_no="";
String secured_text_msg="";
String text_msg="";
String sender_no="";
String time_stamp="";
int msg_length;
int start=4;
public return_format decode(String decodable_str) throws Exception
{
convert1 con = new convert1();
//System.out.println("decodable string:"+decodable_str);
String temp=decodable_str.substring(start,start+12);
start=start+12+6;
smsc_no=con.ByteSwapStr(temp);
//System.out.println("smsc num:"+smsc_no);
temp=decodable_str.substring(start,start+12);
sender_no=con.ByteSwapStr(temp);
//System.out.println("sender num:"+sender_no);
start+=12+4;
temp=decodable_str.substring(start,start+12);
time_stamp=con.TimeStampConverter(temp);
//System.out.println(time_stamp);
start+=12+2;
String hex=decodable_str.substring(start,start+2);
msg_length=Integer.parseInt(hex,16);
//System.out.println("length of text msg:"+msg_length);
start+=2;
temp=decodable_str.substring(start);
secured_text_msg=con.Decode(temp,msg_length);
//System.out.println("pdu msg:"+temp);
//System.out.println("secured string: "+secured_text_msg);
//System.out.println("text message:"+text_msg);
return_format obj = new return_format(time_stamp,sender_no,secured_text_msg);
return obj;
}
}