-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMain.sh
More file actions
executable file
·103 lines (78 loc) · 2.47 KB
/
Copy pathMain.sh
File metadata and controls
executable file
·103 lines (78 loc) · 2.47 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
#!/bin/bash
#init argument stuff
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "raw-transaction required, not provided"
#Warning, using bc as a hex/dec converter. After 10000 lines a \ will appear. this is buggy, workaround:
hex2dec() {
BC_LINE_LENGTH=10000 bc <<< "ibase=16;$1"
}
dec2hex() {
BC_LINE_LENGTH=10000 bc <<< "obase=16;$1"
}
#Convert to uppercase
hex=$1
hex="${hex^^}"
#Show decimal version of hex
echo "###################### DECIMAL VERSION OF HEX #######################"
dec=$(hex2dec "$hex")
echo "$dec"
#Generate pseudo-checksum by doing a sum of all digits
echo "###################### CHECKSUM #######################"
checksum=$(expr `echo $dec | sed 's/[0-9]/ + &/g' | sed 's/^ +//g'`)
echo "$checksum"
bittone="###$dec###$checksum***"
#
#Syntax of the bittone is ### digits ### checksum ***
# ^three tones ^dtmf tones ^three tones ^checksum ^footer
#Generate wav file - using Phrack code
./gen "$bittone"
#Convert old Unsigned 8bit to normal PCM Wave audio by using sox - swiss army knife
#8000Hz, 1 Channel, 8 Bit, Unsigned.
#works, but wav is ugly to hear......... oh well
sox -t raw -r 8000 -c 1 -b 8 -U devdsp.raw dtmf.wav
#Sleep 1 second and take a drink
sleep 1
echo "* Now detecting..."
#detect
detect=$(./detect dtmf.wav)
#Header is first 3 chars (###)
HEADER=${detect:0:3}
#Footer is last 3 chars (***)
FOOTER=${detect: -3}
#Transaction
TRANS=${detect:3:-10}
#Checksum
CHECKSUM=${detect: -7}
#Buggy :( - hack
CHECKSUM=${CHECKSUM:0:-3}
if [ "$HEADER" = "###" ];
then
echo "* Header [OK]: $HEADER"
else
echo "* Header [CORRUPT]: $HEADER - Should be ###"
fi
if [ "$FOOTER" = "***" ];
then
echo "* Footer [OK]: $FOOTER"
else
echo "* Header [CORRUPT]: $FOOTER - Should be ***"
fi
#Uncomment to show transaction as debug
#echo "!!! Transaction: $TRANS !!!"
#Checksum
SANE=$(expr `echo $TRANS | sed 's/[0-9]/ + &/g' | sed 's/^ +//g'`)
echo "* Checksum in DTMF is: $CHECKSUM"
echo "* Checksum of transaction is $SANE"
if [ "$CHECKSUM" = "$SANE" ];
then
echo "* Checksum [PASSED]: $SANE"
txid=$(dec2hex "$TRANS")
echo "* TXID: "
#include a trailing 0 - stripped off by dec2hex function by "bc" but needed for hex/pushing it onto the network
echo "0$txid"
else
echo "* Checksum [FAILED]: should be $SANE but is $CHECKSUM. Check Wav/Sox/Sound quality/etc. Don't forget 10 to 50ms of silence between tones (or else 1223 wil be read as 123)!"
fi