ruby-aes-table2 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,740 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Class: AesAlg</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td><strong>Class</strong></td>
53
- <td class="class-name-in-header">AesAlg</td>
54
- </tr>
55
- <tr class="top-aligned-row">
56
- <td><strong>In:</strong></td>
57
- <td>
58
- <a href="../files/lib/ruby-aes/aes_alg_rb.html">
59
- lib/ruby-aes/aes_alg.rb
60
- </a>
61
- <br />
62
- </td>
63
- </tr>
64
-
65
- <tr class="top-aligned-row">
66
- <td><strong>Parent:</strong></td>
67
- <td>
68
- Object
69
- </td>
70
- </tr>
71
- </table>
72
- </div>
73
- <!-- banner header -->
74
-
75
- <div id="bodyContent">
76
-
77
-
78
-
79
- <div id="contextContent">
80
-
81
-
82
-
83
- </div>
84
-
85
- <div id="method-list">
86
- <h3 class="section-bar">Methods</h3>
87
-
88
- <div class="name-list">
89
- <a href="#M000004">_decrypt_block</a>&nbsp;&nbsp;
90
- <a href="#M000003">_encrypt_block</a>&nbsp;&nbsp;
91
- <a href="#M000007">decrypt_block</a>&nbsp;&nbsp;
92
- <a href="#M000009">decrypt_blocks</a>&nbsp;&nbsp;
93
- <a href="#M000011">decrypt_buffer</a>&nbsp;&nbsp;
94
- <a href="#M000002">decryption_key_schedule</a>&nbsp;&nbsp;
95
- <a href="#M000006">encrypt_block</a>&nbsp;&nbsp;
96
- <a href="#M000008">encrypt_blocks</a>&nbsp;&nbsp;
97
- <a href="#M000010">encrypt_buffer</a>&nbsp;&nbsp;
98
- <a href="#M000001">encryption_key_schedule</a>&nbsp;&nbsp;
99
- <a href="#M000012">init</a>&nbsp;&nbsp;
100
- <a href="#M000013">new</a>&nbsp;&nbsp;
101
- <a href="#M000005">xor</a>&nbsp;&nbsp;
102
- </div>
103
- </div>
104
-
105
- </div>
106
-
107
-
108
- <!-- if includes -->
109
- <div id="includes">
110
- <h3 class="section-bar">Included Modules</h3>
111
-
112
- <div id="includes-list">
113
- <span class="include-name"><a href="AesCons.html">AesCons</a></span>
114
- </div>
115
- </div>
116
-
117
- <div id="section">
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
- <!-- if method_list -->
127
- <div id="methods">
128
- <h3 class="section-bar">Public Class methods</h3>
129
-
130
- <div id="method-M000013" class="method-detail">
131
- <a name="M000013"></a>
132
-
133
- <div class="method-heading">
134
- <a href="#M000013" class="method-signature">
135
- <span class="method-name">new</span><span class="method-args">(key_length, mode, key, iv = nil)</span>
136
- </a>
137
- </div>
138
-
139
- <div class="method-description">
140
- <p><a class="source-toggle" href="#"
141
- onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
142
- <div class="method-source-code" id="M000013-source">
143
- <pre>
144
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 368</span>
145
- 368: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">key_length</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span> = <span class="ruby-keyword kw">nil</span>)
146
- 369: <span class="ruby-identifier">init</span>(<span class="ruby-identifier">key_length</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span>)
147
- 370: <span class="ruby-keyword kw">end</span>
148
- </pre>
149
- </div>
150
- </div>
151
- </div>
152
-
153
- <h3 class="section-bar">Public Instance methods</h3>
154
-
155
- <div id="method-M000007" class="method-detail">
156
- <a name="M000007"></a>
157
-
158
- <div class="method-heading">
159
- <a href="#M000007" class="method-signature">
160
- <span class="method-name">decrypt_block</span><span class="method-args">(block)</span>
161
- </a>
162
- </div>
163
-
164
- <div class="method-description">
165
- <p><a class="source-toggle" href="#"
166
- onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
167
- <div class="method-source-code" id="M000007-source">
168
- <pre>
169
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 262</span>
170
- 262: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
171
- 263: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@mode</span>
172
- 264: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>
173
- 265: <span class="ruby-identifier">_decrypt_block</span>(<span class="ruby-identifier">block</span>)
174
- 266: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CBC'</span>
175
- 267: <span class="ruby-identifier">o</span> = <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">_decrypt_block</span>(<span class="ruby-identifier">block</span>), <span class="ruby-ivar">@iv</span>)
176
- 268: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">block</span>
177
- 269: <span class="ruby-identifier">o</span>
178
- 270: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'OFB'</span>
179
- 271: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>)
180
- 272: <span class="ruby-identifier">xor</span>(<span class="ruby-ivar">@iv</span>, <span class="ruby-identifier">block</span>)
181
- 273: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CFB'</span>
182
- 274: <span class="ruby-identifier">o</span> = <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>), <span class="ruby-identifier">block</span>)
183
- 275: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">block</span>
184
- 276: <span class="ruby-identifier">o</span>
185
- 277: <span class="ruby-keyword kw">end</span>
186
- 278: <span class="ruby-keyword kw">end</span>
187
- </pre>
188
- </div>
189
- </div>
190
- </div>
191
-
192
- <div id="method-M000009" class="method-detail">
193
- <a name="M000009"></a>
194
-
195
- <div class="method-heading">
196
- <a href="#M000009" class="method-signature">
197
- <span class="method-name">decrypt_blocks</span><span class="method-args">(buffer)</span>
198
- </a>
199
- </div>
200
-
201
- <div class="method-description">
202
- <p><a class="source-toggle" href="#"
203
- onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
204
- <div class="method-source-code" id="M000009-source">
205
- <pre>
206
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 293</span>
207
- 293: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_blocks</span>(<span class="ruby-identifier">buffer</span>)
208
- 294: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad block length&quot;</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">%</span> <span class="ruby-value">16</span>).<span class="ruby-identifier">zero?</span>
209
- 295: <span class="ruby-identifier">pt</span> = <span class="ruby-value str">&quot;&quot;</span>
210
- 296: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
211
- 297: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
212
- 298: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
213
- 299: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
214
- 300: <span class="ruby-identifier">pt</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
215
- 301: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
216
- 302: <span class="ruby-keyword kw">end</span>
217
- 303: <span class="ruby-keyword kw">end</span>
218
- 304: <span class="ruby-keyword kw">end</span>
219
- </pre>
220
- </div>
221
- </div>
222
- </div>
223
-
224
- <div id="method-M000011" class="method-detail">
225
- <a name="M000011"></a>
226
-
227
- <div class="method-heading">
228
- <a href="#M000011" class="method-signature">
229
- <span class="method-name">decrypt_buffer</span><span class="method-args">(buffer)</span>
230
- </a>
231
- </div>
232
-
233
- <div class="method-description">
234
- <p><a class="source-toggle" href="#"
235
- onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
236
- <div class="method-source-code" id="M000011-source">
237
- <pre>
238
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 320</span>
239
- 320: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
240
- 321: <span class="ruby-identifier">pt</span> = <span class="ruby-value str">&quot;&quot;</span>
241
- 322: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
242
- 323: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
243
- 324: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
244
- 325: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
245
- 326: <span class="ruby-identifier">pt</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">decrypt_block</span>(<span class="ruby-identifier">block</span>)
246
- 327: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
247
- 328: <span class="ruby-keyword kw">end</span>
248
- 329: <span class="ruby-keyword kw">end</span>
249
- 330: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
250
- 331: <span class="ruby-identifier">c</span> = <span class="ruby-identifier">pt</span>[<span class="ruby-value">-1</span>]
251
- 332: <span class="ruby-identifier">c</span>.<span class="ruby-identifier">chr</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">c</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">pt</span>[<span class="ruby-operator">-</span><span class="ruby-identifier">c</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-operator">-</span>(<span class="ruby-identifier">c</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>)] <span class="ruby-operator">:</span> (<span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad Block Padding&quot;</span>)
252
- 333: <span class="ruby-keyword kw">else</span>
253
- 334: <span class="ruby-identifier">pt</span>
254
- 335: <span class="ruby-keyword kw">end</span>
255
- 336: <span class="ruby-keyword kw">end</span>
256
- </pre>
257
- </div>
258
- </div>
259
- </div>
260
-
261
- <div id="method-M000006" class="method-detail">
262
- <a name="M000006"></a>
263
-
264
- <div class="method-heading">
265
- <a href="#M000006" class="method-signature">
266
- <span class="method-name">encrypt_block</span><span class="method-args">(block)</span>
267
- </a>
268
- </div>
269
-
270
- <div class="method-description">
271
- <p><a class="source-toggle" href="#"
272
- onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
273
- <div class="method-source-code" id="M000006-source">
274
- <pre>
275
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 248</span>
276
- 248: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
277
- 249: <span class="ruby-keyword kw">case</span> <span class="ruby-ivar">@mode</span>
278
- 250: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>
279
- 251: <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-identifier">block</span>)
280
- 252: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CBC'</span>
281
- 253: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-identifier">xor</span>(<span class="ruby-identifier">block</span>, <span class="ruby-ivar">@iv</span>))
282
- 254: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'OFB'</span>
283
- 255: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>)
284
- 256: <span class="ruby-identifier">xor</span>(<span class="ruby-ivar">@iv</span>, <span class="ruby-identifier">block</span>)
285
- 257: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'CFB'</span>
286
- 258: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-ivar">@iv</span>), <span class="ruby-identifier">block</span>)
287
- 259: <span class="ruby-keyword kw">end</span>
288
- 260: <span class="ruby-keyword kw">end</span>
289
- </pre>
290
- </div>
291
- </div>
292
- </div>
293
-
294
- <div id="method-M000008" class="method-detail">
295
- <a name="M000008"></a>
296
-
297
- <div class="method-heading">
298
- <a href="#M000008" class="method-signature">
299
- <span class="method-name">encrypt_blocks</span><span class="method-args">(buffer)</span>
300
- </a>
301
- </div>
302
-
303
- <div class="method-description">
304
- <p><a class="source-toggle" href="#"
305
- onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
306
- <div class="method-source-code" id="M000008-source">
307
- <pre>
308
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 280</span>
309
- 280: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_blocks</span>(<span class="ruby-identifier">buffer</span>)
310
- 281: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Bad block length&quot;</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">%</span> <span class="ruby-value">16</span>).<span class="ruby-identifier">zero?</span>
311
- 282: <span class="ruby-identifier">ct</span> = <span class="ruby-value str">&quot;&quot;</span>
312
- 283: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
313
- 284: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
314
- 285: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
315
- 286: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
316
- 287: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
317
- 288: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
318
- 289: <span class="ruby-keyword kw">end</span>
319
- 290: <span class="ruby-keyword kw">end</span>
320
- 291: <span class="ruby-keyword kw">end</span>
321
- </pre>
322
- </div>
323
- </div>
324
- </div>
325
-
326
- <div id="method-M000010" class="method-detail">
327
- <a name="M000010"></a>
328
-
329
- <div class="method-heading">
330
- <a href="#M000010" class="method-signature">
331
- <span class="method-name">encrypt_buffer</span><span class="method-args">(buffer)</span>
332
- </a>
333
- </div>
334
-
335
- <div class="method-description">
336
- <p><a class="source-toggle" href="#"
337
- onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
338
- <div class="method-source-code" id="M000010-source">
339
- <pre>
340
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 306</span>
341
- 306: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt_buffer</span>(<span class="ruby-identifier">buffer</span>)
342
- 307: <span class="ruby-identifier">ct</span> = <span class="ruby-value str">&quot;&quot;</span>
343
- 308: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
344
- 309: <span class="ruby-identifier">buffer</span>.<span class="ruby-identifier">each_byte</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">char</span><span class="ruby-operator">|</span>
345
- 310: <span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">char</span>
346
- 311: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span>
347
- 312: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span>)
348
- 313: <span class="ruby-identifier">block</span> = <span class="ruby-value str">&quot;&quot;</span>
349
- 314: <span class="ruby-keyword kw">end</span>
350
- 315: <span class="ruby-keyword kw">end</span>
351
- 316: <span class="ruby-identifier">m</span> = <span class="ruby-value">16</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">%</span> <span class="ruby-value">16</span>
352
- 317: <span class="ruby-identifier">ct</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">m</span> <span class="ruby-operator">==</span> <span class="ruby-value">16</span> <span class="ruby-operator">?</span> <span class="ruby-value">0</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">encrypt_block</span>(<span class="ruby-identifier">block</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">m</span>.<span class="ruby-identifier">chr</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">m</span>))
353
- 318: <span class="ruby-keyword kw">end</span>
354
- </pre>
355
- </div>
356
- </div>
357
- </div>
358
-
359
- <div id="method-M000012" class="method-detail">
360
- <a name="M000012"></a>
361
-
362
- <div class="method-heading">
363
- <a href="#M000012" class="method-signature">
364
- <span class="method-name">init</span><span class="method-args">(key_length, mode, key, iv = nil)</span>
365
- </a>
366
- </div>
367
-
368
- <div class="method-description">
369
- <p><a class="source-toggle" href="#"
370
- onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
371
- <div class="method-source-code" id="M000012-source">
372
- <pre>
373
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 338</span>
374
- 338: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">init</span>(<span class="ruby-identifier">key_length</span>, <span class="ruby-identifier">mode</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">iv</span> = <span class="ruby-keyword kw">nil</span>)
375
- 339: <span class="ruby-ivar">@nb</span> = <span class="ruby-value">4</span>
376
- 340: <span class="ruby-ivar">@ek</span> = []
377
- 341: <span class="ruby-ivar">@dk</span> = []
378
- 342: <span class="ruby-ivar">@state</span> = <span class="ruby-keyword kw">nil</span>
379
- 343: <span class="ruby-ivar">@iv</span> = <span class="ruby-value str">&quot;\000&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">16</span>
380
- 344: <span class="ruby-ivar">@iv</span> = <span class="ruby-identifier">iv</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">iv</span>
381
- 345: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">key_length</span>
382
- 346: <span class="ruby-keyword kw">when</span> <span class="ruby-value">128</span>
383
- 347: <span class="ruby-ivar">@nk</span> = <span class="ruby-value">4</span>
384
- 348: <span class="ruby-ivar">@nr</span> = <span class="ruby-value">10</span>
385
- 349: <span class="ruby-keyword kw">when</span> <span class="ruby-value">192</span>
386
- 350: <span class="ruby-ivar">@nk</span> = <span class="ruby-value">6</span>
387
- 351: <span class="ruby-ivar">@nr</span> = <span class="ruby-value">12</span>
388
- 352: <span class="ruby-keyword kw">when</span> <span class="ruby-value">256</span>
389
- 353: <span class="ruby-ivar">@nk</span> = <span class="ruby-value">8</span>
390
- 354: <span class="ruby-ivar">@nr</span> = <span class="ruby-value">14</span>
391
- 355: <span class="ruby-keyword kw">else</span>
392
- 356: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'Bad Key length'</span>
393
- 357: <span class="ruby-keyword kw">end</span>
394
- 358: <span class="ruby-ivar">@kl</span> = <span class="ruby-identifier">key_length</span>
395
- 359: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">mode</span>
396
- 360: <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'ECB'</span>, <span class="ruby-value str">'CBC'</span>, <span class="ruby-value str">'OFB'</span>, <span class="ruby-value str">'CFB'</span>
397
- 361: <span class="ruby-ivar">@mode</span> = <span class="ruby-identifier">mode</span>
398
- 362: <span class="ruby-keyword kw">else</span>
399
- 363: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'Bad AES mode'</span>
400
- 364: <span class="ruby-keyword kw">end</span>
401
- 365: <span class="ruby-identifier">decryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
402
- 366: <span class="ruby-keyword kw">end</span>
403
- </pre>
404
- </div>
405
- </div>
406
- </div>
407
-
408
- <h3 class="section-bar">Protected Instance methods</h3>
409
-
410
- <div id="method-M000004" class="method-detail">
411
- <a name="M000004"></a>
412
-
413
- <div class="method-heading">
414
- <a href="#M000004" class="method-signature">
415
- <span class="method-name">_decrypt_block</span><span class="method-args">(ct)</span>
416
- </a>
417
- </div>
418
-
419
- <div class="method-description">
420
- <p><a class="source-toggle" href="#"
421
- onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
422
- <div class="method-source-code" id="M000004-source">
423
- <pre>
424
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 196</span>
425
- 196: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">_decrypt_block</span>(<span class="ruby-identifier">ct</span>)
426
- 197: <span class="ruby-identifier">t0</span> = <span class="ruby-identifier">t1</span> = <span class="ruby-identifier">t2</span> = <span class="ruby-identifier">t3</span> = <span class="ruby-keyword kw">nil</span>
427
- 198: <span class="ruby-comment cmt"># map byte array block to cipher state and add initial round key:</span>
428
- 199: <span class="ruby-identifier">s0</span> = (<span class="ruby-identifier">ct</span>[ <span class="ruby-value">0</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">1</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">2</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">3</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">0</span>]
429
- 200: <span class="ruby-identifier">s1</span> = (<span class="ruby-identifier">ct</span>[ <span class="ruby-value">4</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">5</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">6</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">7</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">1</span>]
430
- 201: <span class="ruby-identifier">s2</span> = (<span class="ruby-identifier">ct</span>[ <span class="ruby-value">8</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[ <span class="ruby-value">9</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">10</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">11</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">2</span>]
431
- 202: <span class="ruby-identifier">s3</span> = (<span class="ruby-identifier">ct</span>[<span class="ruby-value">12</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">13</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">14</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">ct</span>[<span class="ruby-value">15</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">3</span>]
432
- 203: <span class="ruby-identifier">r</span> = <span class="ruby-ivar">@nr</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">1</span>
433
- 204: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
434
- 205: <span class="ruby-identifier">loop</span> {
435
- 206: <span class="ruby-identifier">t0</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
436
- 207: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s1</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
437
- 208: <span class="ruby-identifier">t1</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
438
- 209: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s2</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
439
- 210: <span class="ruby-identifier">t2</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
440
- 211: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s3</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
441
- 212: <span class="ruby-identifier">t3</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
442
- 213: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">s0</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
443
- 214: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">8</span>
444
- 215: <span class="ruby-identifier">r</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
445
- 216: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
446
- 217: <span class="ruby-identifier">s0</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
447
- 218: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t1</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
448
- 219: <span class="ruby-identifier">s1</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
449
- 220: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t2</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
450
- 221: <span class="ruby-identifier">s2</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
451
- 222: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t3</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
452
- 223: <span class="ruby-identifier">s3</span> = <span class="ruby-constant">Td0</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Td1</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
453
- 224: <span class="ruby-constant">Td2</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Td3</span>[(<span class="ruby-identifier">t0</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
454
- 225: }
455
- 226: <span class="ruby-comment cmt"># apply last round and map cipher state to byte array block:</span>
456
- 227: <span class="ruby-identifier">s0</span> = (<span class="ruby-constant">Si3</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si2</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
457
- 228: (<span class="ruby-constant">Si1</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si0</span>[(<span class="ruby-identifier">t1</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
458
- 229: <span class="ruby-identifier">s1</span> = (<span class="ruby-constant">Si3</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si2</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
459
- 230: (<span class="ruby-constant">Si1</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si0</span>[(<span class="ruby-identifier">t2</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
460
- 231: <span class="ruby-identifier">s2</span> = (<span class="ruby-constant">Si3</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si2</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
461
- 232: (<span class="ruby-constant">Si1</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si0</span>[(<span class="ruby-identifier">t3</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
462
- 233: <span class="ruby-identifier">s3</span> = (<span class="ruby-constant">Si3</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si2</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
463
- 234: (<span class="ruby-constant">Si1</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">Si0</span>[(<span class="ruby-identifier">t0</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@dk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
464
- 235: [(<span class="ruby-value str">&quot;%08x%08x%08x%08x&quot;</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">s0</span>, <span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span>, <span class="ruby-identifier">s3</span>])].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;H*&quot;</span>)
465
- 236: <span class="ruby-keyword kw">end</span>
466
- </pre>
467
- </div>
468
- </div>
469
- </div>
470
-
471
- <div id="method-M000003" class="method-detail">
472
- <a name="M000003"></a>
473
-
474
- <div class="method-heading">
475
- <a href="#M000003" class="method-signature">
476
- <span class="method-name">_encrypt_block</span><span class="method-args">(pt)</span>
477
- </a>
478
- </div>
479
-
480
- <div class="method-description">
481
- <p><a class="source-toggle" href="#"
482
- onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
483
- <div class="method-source-code" id="M000003-source">
484
- <pre>
485
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 153</span>
486
- 153: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">_encrypt_block</span>(<span class="ruby-identifier">pt</span>)
487
- 154: <span class="ruby-identifier">t0</span> = <span class="ruby-identifier">t1</span> = <span class="ruby-identifier">t2</span> = <span class="ruby-identifier">t3</span> = <span class="ruby-keyword kw">nil</span>
488
- 155: <span class="ruby-comment cmt"># map byte array block to cipher state and add initial round key:</span>
489
- 156: <span class="ruby-identifier">s0</span> = (<span class="ruby-identifier">pt</span>[ <span class="ruby-value">0</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">1</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">2</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">3</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span>]
490
- 157: <span class="ruby-identifier">s1</span> = (<span class="ruby-identifier">pt</span>[ <span class="ruby-value">4</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">5</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">6</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">7</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span>]
491
- 158: <span class="ruby-identifier">s2</span> = (<span class="ruby-identifier">pt</span>[ <span class="ruby-value">8</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[ <span class="ruby-value">9</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">10</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">11</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span>]
492
- 159: <span class="ruby-identifier">s3</span> = (<span class="ruby-identifier">pt</span>[<span class="ruby-value">12</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">13</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">14</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">pt</span>[<span class="ruby-value">15</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span>]
493
- 160: <span class="ruby-identifier">r</span> = <span class="ruby-ivar">@nr</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">1</span>
494
- 161: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
495
- 162: <span class="ruby-identifier">loop</span> {
496
- 163: <span class="ruby-identifier">t0</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
497
- 164: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s3</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
498
- 165: <span class="ruby-identifier">t1</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
499
- 166: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s0</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
500
- 167: <span class="ruby-identifier">t2</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
501
- 168: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s1</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
502
- 169: <span class="ruby-identifier">t3</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">s3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">s0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
503
- 170: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">s1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">s2</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
504
- 171: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">8</span>
505
- 172: <span class="ruby-identifier">r</span> <span class="ruby-operator">-=</span> <span class="ruby-value">1</span>
506
- 173: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
507
- 174: <span class="ruby-identifier">s0</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
508
- 175: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t3</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
509
- 176: <span class="ruby-identifier">s1</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
510
- 177: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t0</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
511
- 178: <span class="ruby-identifier">s2</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
512
- 179: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t1</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
513
- 180: <span class="ruby-identifier">s3</span> = <span class="ruby-constant">Te0</span>[(<span class="ruby-identifier">t3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>) ] <span class="ruby-operator">^</span> <span class="ruby-constant">Te1</span>[(<span class="ruby-identifier">t0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span>
514
- 181: <span class="ruby-constant">Te2</span>[(<span class="ruby-identifier">t1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-constant">Te3</span>[(<span class="ruby-identifier">t2</span> ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
515
- 182: }
516
- 183: <span class="ruby-comment cmt"># apply last round and map cipher state to byte array block:</span>
517
- 184: <span class="ruby-identifier">s0</span> = (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
518
- 185: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">t3</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
519
- 186: <span class="ruby-identifier">s1</span> = (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
520
- 187: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">t0</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
521
- 188: <span class="ruby-identifier">s2</span> = (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">t2</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
522
- 189: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">t1</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
523
- 190: <span class="ruby-identifier">s3</span> = (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">t3</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">t0</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">16</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
524
- 191: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">t1</span><span class="ruby-operator">&gt;&gt;</span><span class="ruby-value">8</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">t2</span>)<span class="ruby-operator">&amp;</span><span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
525
- 192: [(<span class="ruby-value str">&quot;%08x%08x%08x%08x&quot;</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">s0</span>, <span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span>, <span class="ruby-identifier">s3</span>])].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;H*&quot;</span>)
526
- 193: <span class="ruby-keyword kw">end</span>
527
- </pre>
528
- </div>
529
- </div>
530
- </div>
531
-
532
- <div id="method-M000002" class="method-detail">
533
- <a name="M000002"></a>
534
-
535
- <div class="method-heading">
536
- <a href="#M000002" class="method-signature">
537
- <span class="method-name">decryption_key_schedule</span><span class="method-args">(key)</span>
538
- </a>
539
- </div>
540
-
541
- <div class="method-description">
542
- <p><a class="source-toggle" href="#"
543
- onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
544
- <div class="method-source-code" id="M000002-source">
545
- <pre>
546
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 96</span>
547
- 96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
548
- 97: <span class="ruby-comment cmt"># expand the cipher key:</span>
549
- 98: <span class="ruby-identifier">encryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
550
- 99: <span class="ruby-ivar">@dk</span> = <span class="ruby-ivar">@ek</span>.<span class="ruby-identifier">dup</span>
551
- 100: <span class="ruby-comment cmt"># invert the order of the round keys:</span>
552
- 101: <span class="ruby-identifier">j</span> = <span class="ruby-value">4</span> <span class="ruby-operator">*</span> <span class="ruby-ivar">@nr</span>
553
- 102: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
554
- 103: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
555
- 104: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-identifier">j</span>
556
- 105: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span>]
557
- 106: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span>] = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span>]
558
- 107: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span>] = <span class="ruby-identifier">temp</span>
559
- 108: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>]
560
- 109: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>] = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>]
561
- 110: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>] = <span class="ruby-identifier">temp</span>
562
- 111: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>]
563
- 112: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>] = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>]
564
- 113: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">2</span>] = <span class="ruby-identifier">temp</span>
565
- 114: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>]
566
- 115: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">i</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>] = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>]
567
- 116: <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span> <span class="ruby-operator">+</span> <span class="ruby-value">3</span>] = <span class="ruby-identifier">temp</span>
568
- 117: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
569
- 118: <span class="ruby-identifier">j</span> <span class="ruby-operator">-=</span> <span class="ruby-value">4</span>
570
- 119: <span class="ruby-keyword kw">end</span>
571
- 120: <span class="ruby-comment cmt"># apply the inverse MixColumn transform</span>
572
- 121: <span class="ruby-comment cmt"># to all round keys but the first and the last:</span>
573
- 122: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
574
- 123: <span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-ivar">@nr</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
575
- 124: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
576
- 125: <span class="ruby-identifier">w0</span>= <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span>]
577
- 126: <span class="ruby-identifier">w1</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>]
578
- 127: <span class="ruby-identifier">w2</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span><span class="ruby-operator">+</span><span class="ruby-value">2</span>]
579
- 128: <span class="ruby-identifier">w3</span> = <span class="ruby-ivar">@dk</span>[<span class="ruby-identifier">j</span><span class="ruby-operator">+</span><span class="ruby-value">3</span>]
580
- 129: <span class="ruby-ivar">@dk</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
581
- 130: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)] ]<span class="ruby-operator">^</span>
582
- 131: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
583
- 132: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w0</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
584
- 133: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w0</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ]
585
- 134: <span class="ruby-ivar">@dk</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
586
- 135: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)] ] <span class="ruby-operator">^</span>
587
- 136: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
588
- 137: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w1</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
589
- 138: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w1</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ]
590
- 139: <span class="ruby-ivar">@dk</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
591
- 140: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)] ] <span class="ruby-operator">^</span>
592
- 141: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
593
- 142: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w2</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
594
- 143: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w2</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ]
595
- 144: <span class="ruby-ivar">@dk</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] =
596
- 145: <span class="ruby-constant">Td0</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)] ] <span class="ruby-operator">^</span>
597
- 146: <span class="ruby-constant">Td1</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
598
- 147: <span class="ruby-constant">Td2</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w3</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ] <span class="ruby-operator">^</span>
599
- 148: <span class="ruby-constant">Td3</span>[<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">w3</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>] ]
600
- 149: <span class="ruby-keyword kw">end</span>
601
- 150: <span class="ruby-keyword kw">end</span>
602
- </pre>
603
- </div>
604
- </div>
605
- </div>
606
-
607
- <div id="method-M000001" class="method-detail">
608
- <a name="M000001"></a>
609
-
610
- <div class="method-heading">
611
- <a href="#M000001" class="method-signature">
612
- <span class="method-name">encryption_key_schedule</span><span class="method-args">(key)</span>
613
- </a>
614
- </div>
615
-
616
- <div class="method-description">
617
- <p><a class="source-toggle" href="#"
618
- onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
619
- <div class="method-source-code" id="M000001-source">
620
- <pre>
621
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 20</span>
622
- 20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encryption_key_schedule</span>(<span class="ruby-identifier">key</span>)
623
- 21: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
624
- 22: <span class="ruby-ivar">@ek</span> = []
625
- 23: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">2</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">3</span>]
626
- 24: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">4</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">5</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">6</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">7</span>]
627
- 25: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">8</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">9</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">10</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">11</span>]
628
- 26: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">12</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">13</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">14</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">15</span>]
629
- 27: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@kl</span> <span class="ruby-operator">==</span> <span class="ruby-value">128</span>
630
- 28: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
631
- 29: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
632
- 30: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
633
- 31: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[<span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
634
- 32: (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
635
- 33: (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
636
- 34: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">temp</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
637
- 35: (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> <span class="ruby-constant">RCON</span>[<span class="ruby-identifier">i</span>]
638
- 36: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[<span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
639
- 37: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[<span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
640
- 38: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[<span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
641
- 39: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
642
- 40: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">10</span>)
643
- 41: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">4</span>
644
- 42: <span class="ruby-keyword kw">end</span>
645
- 43: <span class="ruby-keyword kw">end</span>
646
- 44: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">4</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">16</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">17</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">18</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">19</span>]
647
- 45: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">5</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">20</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">21</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">22</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">23</span>]
648
- 46: <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@kl</span> <span class="ruby-operator">==</span> <span class="ruby-value">192</span>)
649
- 47: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
650
- 48: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
651
- 49: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
652
- 50: <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
653
- 51: (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
654
- 52: (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
655
- 53: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">temp</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
656
- 54: (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> <span class="ruby-constant">RCON</span>[<span class="ruby-identifier">i</span>]
657
- 55: <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
658
- 56: <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
659
- 57: <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
660
- 58: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
661
- 59: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">8</span>)
662
- 60: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
663
- 61: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">11</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
664
- 62: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">6</span>
665
- 63: <span class="ruby-keyword kw">end</span>
666
- 64: <span class="ruby-keyword kw">end</span>
667
- 65: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">6</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">24</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">25</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">26</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">27</span>]
668
- 66: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">7</span>] = <span class="ruby-identifier">key</span>[<span class="ruby-value">28</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">24</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">29</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">16</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">30</span>] <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value">8</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>[<span class="ruby-value">31</span>]
669
- 67: <span class="ruby-keyword kw">if</span> (<span class="ruby-ivar">@kl</span> <span class="ruby-operator">==</span> <span class="ruby-value">256</span>)
670
- 68: <span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
671
- 69: <span class="ruby-identifier">loop</span> <span class="ruby-keyword kw">do</span>
672
- 70: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
673
- 71: <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">0</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
674
- 72: (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
675
- 73: (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
676
- 74: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">temp</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
677
- 75: (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span> <span class="ruby-constant">RCON</span>[<span class="ruby-identifier">i</span>]
678
- 76: <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">1</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">8</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
679
- 77: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">2</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">9</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
680
- 78: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">11</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">3</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">10</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
681
- 79: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
682
- 80: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">i</span> <span class="ruby-operator">==</span> <span class="ruby-value">7</span>)
683
- 81: <span class="ruby-identifier">temp</span> = <span class="ruby-ivar">@ek</span>[<span class="ruby-value">11</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
684
- 82: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">12</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">4</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span>
685
- 83: (<span class="ruby-constant">S3</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">24</span>)]) <span class="ruby-operator">^</span>
686
- 84: (<span class="ruby-constant">S2</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
687
- 85: (<span class="ruby-constant">S1</span>[(<span class="ruby-identifier">temp</span> <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">8</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>]) <span class="ruby-operator">^</span>
688
- 86: (<span class="ruby-constant">S0</span>[(<span class="ruby-identifier">temp</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0xff</span>])
689
- 87: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">13</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">5</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">12</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
690
- 88: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">14</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">6</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">13</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
691
- 89: <span class="ruby-ivar">@ek</span>[<span class="ruby-value">15</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] = <span class="ruby-ivar">@ek</span>[ <span class="ruby-value">7</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>] <span class="ruby-operator">^</span> <span class="ruby-ivar">@ek</span>[<span class="ruby-value">14</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>]
692
- 90: <span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">8</span>
693
- 91: <span class="ruby-keyword kw">end</span>
694
- 92: <span class="ruby-keyword kw">end</span>
695
- 93: <span class="ruby-keyword kw">end</span>
696
- </pre>
697
- </div>
698
- </div>
699
- </div>
700
-
701
- <div id="method-M000005" class="method-detail">
702
- <a name="M000005"></a>
703
-
704
- <div class="method-heading">
705
- <a href="#M000005" class="method-signature">
706
- <span class="method-name">xor</span><span class="method-args">(a,b)</span>
707
- </a>
708
- </div>
709
-
710
- <div class="method-description">
711
- <p><a class="source-toggle" href="#"
712
- onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
713
- <div class="method-source-code" id="M000005-source">
714
- <pre>
715
- <span class="ruby-comment cmt"># File lib/ruby-aes/aes_alg.rb, line 239</span>
716
- 239: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">xor</span>(<span class="ruby-identifier">a</span>,<span class="ruby-identifier">b</span>)
717
- 240: <span class="ruby-identifier">c</span> = <span class="ruby-value str">&quot;&quot;</span>
718
- 241: <span class="ruby-value">16</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
719
- 242: <span class="ruby-identifier">c</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">a</span>[<span class="ruby-identifier">i</span>] <span class="ruby-operator">^</span> <span class="ruby-identifier">b</span>[<span class="ruby-identifier">i</span>]).<span class="ruby-identifier">chr</span>
720
- 243: <span class="ruby-keyword kw">end</span>
721
- 244: <span class="ruby-identifier">c</span>
722
- 245: <span class="ruby-keyword kw">end</span>
723
- </pre>
724
- </div>
725
- </div>
726
- </div>
727
-
728
-
729
- </div>
730
-
731
-
732
- </div>
733
-
734
-
735
- <div id="validator-badges">
736
- <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
737
- </div>
738
-
739
- </body>
740
- </html>