-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_hashlib
executable file
·171 lines (155 loc) · 5.78 KB
/
test_hashlib
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
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/as3shebang --
import shell.*;
var hashlib:* = Domain.currentDomain.load( "hashlib.abc" );
trace( hashlib + " loaded" );
import flash.utils.ByteArray;
import hash.*;
function uintToHex( n:uint ):String
{
var hex:String = n.toString( 16 );
if( hex.length%2 != 0 ) { hex = "0" + hex; }
return hex;
}
trace( "different hash of \"hello world\"" );
var str:String = "hello world";
var bytes = new ByteArray();
bytes.writeUTFBytes( str );
// Non-cryptographic hash functions
trace( " ap = " + uintToHex( ap( bytes ) ) );
trace( " bkdr = " + uintToHex( bkdr( bytes ) ) );
trace( " brp = " + uintToHex( brp( bytes ) ) );
trace( " dek = " + uintToHex( dek( bytes ) ) );
trace( " djb = " + uintToHex( djb( bytes ) ) );
trace( " elf = " + uintToHex( elf( bytes ) ) );
trace( " fnv = " + uintToHex( fnv( bytes ) ) );
trace( " js = " + uintToHex( js( bytes ) ) );
trace( " pjw = " + uintToHex( pjw( bytes ) ) );
trace( " rs = " + uintToHex( rs( bytes ) ) );
trace( " sdbm = " + uintToHex( sdbm( bytes ) ) );
// Cyclic redundancy checks
// 8bits
var crc_8;
crc_8 = new crc8();
crc_8.update( bytes );
trace( " crc8 = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_atm();
crc_8.update( bytes );
trace( " crc8_atm = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_ccitt();
crc_8.update( bytes );
trace( " crc8_ccitt = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_darc();
crc_8.update( bytes );
trace( " crc8_darc = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_icode();
crc_8.update( bytes );
trace( " crc8_icode = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_itu();
crc_8.update( bytes );
trace( " crc8_itu = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_j1850();
crc_8.update( bytes );
trace( " crc8_j1850 = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_maxim();
crc_8.update( bytes );
trace( " crc8_maxim = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_rohc();
crc_8.update( bytes );
trace( " crc8_rohc = " + uintToHex( crc_8.valueOf() ) );
crc_8 = new crc8_wcdma();
crc_8.update( bytes );
trace( " crc8_wcdma = " + uintToHex( crc_8.valueOf() ) );
// 16bits
var crc_16;
crc_16 = new crc16();
crc_16.update( bytes );
trace( " crc16 = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_aug_ccitt();
crc_16.update( bytes );
trace( " crc16_aug_ccitt = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_buypass();
crc_16.update( bytes );
trace( " crc16_buypass = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_ccitt_false();
crc_16.update( bytes );
trace( " crc16_ccitt_false = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_dds10();
crc_16.update( bytes );
trace( " crc16_dds10 = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_dect_r();
crc_16.update( bytes );
trace( " crc16_dect_r = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_dect_x();
crc_16.update( bytes );
trace( " crc16_dect_x = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_dnp();
crc_16.update( bytes );
trace( " crc16_dnp = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_en13757();
crc_16.update( bytes );
trace( " crc16_en13757 = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_genibus();
crc_16.update( bytes );
trace( " crc16_genibus = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_maxim();
crc_16.update( bytes );
trace( " crc16_maxim = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_mcrf4xx();
crc_16.update( bytes );
trace( " crc16_mcrf4xx = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_riello();
crc_16.update( bytes );
trace( " crc16_riello = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_t10dif();
crc_16.update( bytes );
trace( " crc16_t10dif = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_teledisk();
crc_16.update( bytes );
trace( " crc16_teledisk = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new crc16_usb();
crc_16.update( bytes );
trace( " crc16_usb = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new kermit();
crc_16.update( bytes );
trace( " kermit = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new modbus();
crc_16.update( bytes );
trace( " modbus = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new x25();
crc_16.update( bytes );
trace( " x25 = " + uintToHex( crc_16.valueOf() ) );
crc_16 = new xmodem();
crc_16.update( bytes );
trace( " xmodem = " + uintToHex( crc_16.valueOf() ) );
// 32bits
var crc_32;
crc_32 = new crc32();
crc_32.update( bytes );
trace( " crc32 = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_bzip2();
crc_32.update( bytes );
trace( " crc32_bzip2 = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_c();
crc_32.update( bytes );
trace( " crc32_c = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_d();
crc_32.update( bytes );
trace( " crc32_d = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_k();
crc_32.update( bytes );
trace( " crc32_k = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_mpeg2();
crc_32.update( bytes );
trace( " crc32_mpeg2 = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_posix();
crc_32.update( bytes );
trace( " crc32_posix = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new crc32_q();
crc_32.update( bytes );
trace( " crc32_q = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new jamcrc();
crc_32.update( bytes );
trace( " jamcrc = " + uintToHex( crc_32.valueOf() ) );
crc_32 = new xfer();
crc_32.update( bytes );
trace( " xfer = " + uintToHex( crc_32.valueOf() ) );