Mercurial > projects > dcrypt
comparison dcrypt/crypto/ciphers/RC4.d @ 28:ad687db713a4
Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Sun, 10 May 2009 22:38:48 -0400 |
parents | 8b5eaf3c2979 |
children |
comparison
equal
deleted
inserted
replaced
27:8b5eaf3c2979 | 28:ad687db713a4 |
---|---|
45 setup(workingKey); | 45 setup(workingKey); |
46 | 46 |
47 _encrypt = _initialized = true; | 47 _encrypt = _initialized = true; |
48 } | 48 } |
49 | 49 |
50 char[] name() | 50 string name() |
51 { | 51 { |
52 return "RC4"; | 52 return "RC4"; |
53 } | 53 } |
54 | 54 |
55 ubyte returnByte(ubyte input) | 55 ubyte returnByte(ubyte input) |
114 /** Some RC4 test vectors. */ | 114 /** Some RC4 test vectors. */ |
115 debug (UnitTest) | 115 debug (UnitTest) |
116 { | 116 { |
117 unittest | 117 unittest |
118 { | 118 { |
119 static const char[][] test_keys = [ | 119 static string[] test_keys = [ |
120 "0123456789abcdef", | 120 "0123456789abcdef", |
121 "0123456789abcdef", | 121 "0123456789abcdef", |
122 "0000000000000000", | 122 "0000000000000000", |
123 "ef012345", | 123 "ef012345", |
124 "0123456789abcdef" | 124 "0123456789abcdef" |
125 ]; | 125 ]; |
126 | 126 |
127 static const char[][] test_plaintexts = [ | 127 static string[] test_plaintexts = [ |
128 "0123456789abcdef", | 128 "0123456789abcdef", |
129 "0000000000000000", | 129 "0000000000000000", |
130 "0000000000000000", | 130 "0000000000000000", |
131 "00000000000000000000", | 131 "00000000000000000000", |
132 "01010101010101010101010101010101"~ | 132 "01010101010101010101010101010101"~ |
161 "01010101010101010101010101010101"~ | 161 "01010101010101010101010101010101"~ |
162 "01010101010101010101010101010101"~ | 162 "01010101010101010101010101010101"~ |
163 "01010101010101010101010101010101" | 163 "01010101010101010101010101010101" |
164 ]; | 164 ]; |
165 | 165 |
166 static const char[][] test_ciphertexts = [ | 166 static string[] test_ciphertexts = [ |
167 "75b7878099e0c596", | 167 "75b7878099e0c596", |
168 "7494c2e7104b0879", | 168 "7494c2e7104b0879", |
169 "de188941a3375d3a", | 169 "de188941a3375d3a", |
170 "d6a141a7ec3c38dfbd61", | 170 "d6a141a7ec3c38dfbd61", |
171 "7595c3e6114a09780c4ad452338e1ffd"~ | 171 "7595c3e6114a09780c4ad452338e1ffd"~ |
201 "12129a284deacc4cdefe58be7137541c"~ | 201 "12129a284deacc4cdefe58be7137541c"~ |
202 "047126c8d49e2755ab181ab7e940b0c0" | 202 "047126c8d49e2755ab181ab7e940b0c0" |
203 ]; | 203 ]; |
204 | 204 |
205 RC4 r = new RC4(); | 205 RC4 r = new RC4(); |
206 foreach (uint i, char[] test_key; test_keys) | 206 foreach (uint i, string test_key; test_keys) |
207 { | 207 { |
208 ubyte[] buffer = new ubyte[test_plaintexts[i].length>>1]; | 208 ubyte[] buffer = new ubyte[test_plaintexts[i].length>>1]; |
209 char[] result; | 209 string result; |
210 | 210 |
211 r.init(true, new SymmetricKey(ByteConverter.hexDecode(test_key))); | 211 r.init(true, new SymmetricKey(ByteConverter.hexDecode(test_key))); |
212 | 212 |
213 // Encryption | 213 // Encryption |
214 r.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); | 214 r.update(ByteConverter.hexDecode(test_plaintexts[i]), buffer); |