summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
Unidiff
Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html478
1 files changed, 478 insertions, 0 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html b/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
new file mode 100644
index 0000000..bdb0cbc
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html
@@ -0,0 +1,478 @@
1<!--
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27-->
28
29<html>
30<head>
31 <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
32 <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script>
33 <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
34 <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
35
36 <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
37 <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
38 <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
39 <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
40
41 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
42 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
43 <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script>
44</head>
45<body>
46<pre id="test">
47<script type="text/javascript">
48try {
49 varbigInt_1;
50 varbigInt_2;
51 varresult;
52 varexpectedResult;
53
54 //
55 //Constructur and equality test
56 //
57 bigInt_1 = new Clipperz.Crypto.BigInt("110");
58 is (bigInt_1.equals(bigInt_1), true, "");
59
60 bigInt_1 = new Clipperz.Crypto.BigInt("110");
61 bigInt_2 = new Clipperz.Crypto.BigInt("110", 10);
62 is (bigInt_1.equals(bigInt_2), true, "");
63
64 bigInt_1 = new Clipperz.Crypto.BigInt("110");
65 bigInt_2 = new Clipperz.Crypto.BigInt(110);
66 is (bigInt_1.equals(bigInt_2), true, "");
67
68 bigInt_1 = new Clipperz.Crypto.BigInt(6);
69 bigInt_2 = new Clipperz.Crypto.BigInt("110", 2);
70 is (bigInt_1.equals(bigInt_2), true, "");
71
72 bigInt_1 = new Clipperz.Crypto.BigInt(6);
73 bigInt_2 = new Clipperz.Crypto.BigInt("110", 3);
74 is (bigInt_1.equals(bigInt_2), false, "");
75
76
77 //
78 //Addition test
79 //
80 bigInt_1 = new Clipperz.Crypto.BigInt(6);
81 bigInt_2 = new Clipperz.Crypto.BigInt(110);
82 result = bigInt_1.add(bigInt_2);
83 expectedResult = new Clipperz.Crypto.BigInt(116);
84 is (result.equals(expectedResult), true, "");
85 is (result.equals(Clipperz.Crypto.BigInt.add(bigInt_1, bigInt_2)), true, "instance method === static function");
86
87 bigInt_1 = new Clipperz.Crypto.BigInt(6);
88 result = bigInt_1.add(6);
89 expectedResult = new Clipperz.Crypto.BigInt(12);
90 is (result.equals(expectedResult), true, "");
91
92 bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
93 bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
94 result = bigInt_1.add(bigInt_2);
95 expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585858585858585858585858585858585");
96 is (result.equals(expectedResult), true, "");
97
98 bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161");
99 bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
100 result = bigInt_1.add(bigInt_2);
101 expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585851585858585858585858585858585");
102 is (result.equals(expectedResult), false, "");
103
104 bigInt_1 = new Clipperz.Crypto.BigInt("86161616161616161616161616161616161616161616161616161");
105 bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424");
106 result = bigInt_1.add(bigInt_2);
107 expectedResult = new Clipperz.Crypto.BigInt("128585858585858585858585858585858585858585858585858585");
108 is (result.equals(expectedResult), true, "");
109
110 bigInt_1 = new Clipperz.Crypto.BigInt("6541652165410321654063516540621063540654" +
111 "0654065106540654165416521654103216540635" +
112 "1654062106354065406540651065406541");
113 bigInt_2 = new Clipperz.Crypto.BigInt("3046540351035403510354035103510351351351" +
114 "0351350435103213540634132135401351035403" +
115 "5403540354103540");
116 result = bigInt_1.add(bigInt_2);
117 expectedResult = new Clipperz.Crypto.BigInt("6541652165410321657110056891656467051008" +
118 "1005100210054167675767872089206430081269" +
119 "2975416119864419441944191419510081");
120 is (result.equals(expectedResult), true, "");
121
122
123 //
124 //Moltiplication test
125 //
126 bigInt_1 = new Clipperz.Crypto.BigInt(6);
127 bigInt_2 = new Clipperz.Crypto.BigInt(110);
128 result = bigInt_1.multiply(bigInt_2);
129 expectedResult = new Clipperz.Crypto.BigInt(660);
130 is (result.equals(expectedResult), true, "");
131
132 bigInt_1 = new Clipperz.Crypto.BigInt(6);
133 result = bigInt_1.multiply(5);
134 expectedResult = new Clipperz.Crypto.BigInt(30);
135 is (result.equals(expectedResult), true, "");
136
137 bigInt_1 = new Clipperz.Crypto.BigInt("5465465165465465132743540354354032135463" +
138 "5435135403513516843052413543054035");
139 bigInt_2 = new Clipperz.Crypto.BigInt("3543513543543213543032135435413054365430" +
140 "5130513540351354354305435403");
141 result = bigInt_1.multiply(bigInt_2);
142 expectedResult = new Clipperz.Crypto.BigInt("1936694983559052629352223965314822970014" +
143 "6364423657014976098029153153101751605574" +
144 "5077086464435601381095664357540911830059" +
145 "9503335163757031001105");
146 is (result.equals(expectedResult), true, "");
147
148 //
149 //Module test
150 //
151 bigInt_1 = new Clipperz.Crypto.BigInt(106);
152 bigInt_2 = new Clipperz.Crypto.BigInt(10);
153 result = bigInt_1.module(bigInt_2);
154 expectedResult = new Clipperz.Crypto.BigInt(6);
155 is (result.equals(expectedResult), true, "");
156
157 bigInt_1 = new Clipperz.Crypto.BigInt(106);
158 result = bigInt_1.module(10);
159 expectedResult = new Clipperz.Crypto.BigInt(6);
160 is (result.equals(expectedResult), true, "");
161
162 bigInt_1 = new Clipperz.Crypto.BigInt("5465465465468468465468463541358438543513" +
163 "8543135435135423545624354235123512531235" +
164 "1356463543840351351305135435121354305413" +
165 "543");
166
167
168 bigInt_2 = new Clipperz.Crypto.BigInt("3543543213543213540543545463542354385768" +
169 "512584354354215");
170 result = bigInt_1.module(bigInt_2);
171 expectedResult = new Clipperz.Crypto.BigInt("52689987206612998786765715819079250963638640081836513");
172 is (result.equals(expectedResult), true, "");
173
174 //
175 //Power (Module) test
176 //
177 bigInt_1 = new Clipperz.Crypto.BigInt(6);
178 bigInt_2 = new Clipperz.Crypto.BigInt(3);
179 result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt(1000));
180 expectedResult = new Clipperz.Crypto.BigInt(216);
181 is (result.equals(expectedResult), true, "");
182
183 bigInt_1 = new Clipperz.Crypto.BigInt(6);
184 result = bigInt_1.powerModule(3, 1000);
185 expectedResult = new Clipperz.Crypto.BigInt(216);
186 is (result.equals(expectedResult), true, "");
187
188 bigInt_1 = new Clipperz.Crypto.BigInt("354354354354687638546846846846846576876468746846846846");
189 bigInt_2 = new Clipperz.Crypto.BigInt("354");
190 result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt("3543541354354354354354351354354351354354354354354354"));
191 expectedResult = new Clipperz.Crypto.BigInt("1957028940698171231089373321334263118681605242465644");
192 is (result.equals(expectedResult), true, "");
193
194 bigInt_1 = new Clipperz.Crypto.BigInt("e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", 16);
195 //is(bigInt_1.toString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "IE bug");
196 is(bigInt_1.asString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "fix for IE bug");
197
198
199 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
200 is(bigInt_1.asString(16, 64), "000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "fix to ensure the string representation has a minimum fixed length");
201
202/*
203 //
204 //Comparison
205 //
206 bigInt_1 = new Clipperz.Crypto.BigInt("0", 10);
207 bigInt_2 = new Clipperz.Crypto.BigInt("0", 10);
208 is (bigInt_1.equals(bigInt_2), true, "bigInt(0) = bigInt(0)");
209 is (bigInt_1.equals(0), true, "bigInt(0) = 0");
210
211 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
212 is (bigInt_1.equals(bigInt_2), false, "bigInt(xxxxxx) != bigInt(0)");
213 is (bigInt_1.equals(0), false, "bigInt(xxxxx) != 0");
214
215 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
216 bigInt_2 = new Clipperz.Crypto.BigInt("0", 16);
217 is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(0)");
218 is(bigInt_2.compare(bigInt_1), -1, "bigInt(0) < bigInt(xxxx)");
219
220 bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16);
221 bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
222 is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(05)");
223 is(bigInt_2.compare(bigInt_1), -1, "bigInt(05) < bigInt(xxxx)");
224
225 bigInt_1 = new Clipperz.Crypto.BigInt("-10", 10);
226 bigInt_2 = new Clipperz.Crypto.BigInt("10", 10);
227 is(bigInt_1.equals(bigInt_2), true, "bigInt(-10) - bigInt(10). No negative number are managed");
228
229 //
230 //XOR
231 //
232 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
233 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
234 result = bigInt_1.xor(bigInt_2);
235 expectedResult = new Clipperz.Crypto.BigInt(0);
236 is(result.asString(16), expectedResult.asString(16), "a xor a = 0");
237
238 //
239 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
240 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
241 result = bigInt_1.xor(bigInt_2);
242 expectedResult = new Clipperz.Crypto.BigInt('295147905179352825856');
243 is(result.asString(16), expectedResult.asString(16), "single bit difference");
244
245 //
246 bigInt_1 = new Clipperz.Crypto.BigInt("01", 16);
247 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16);
248 result = bigInt_1.xor(bigInt_2);
249 expectedResult = new Clipperz.Crypto.BigInt('102987336249554097029535212322581322789799900648198034993674544906295017912404');
250 is(result.asString(16), expectedResult.asString(16), "01 xor value");
251
252 //
253 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
254 bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
255 result = bigInt_1.xor(bigInt_2);
256 expectedResult = new Clipperz.Crypto.BigInt('7237005577332262213973186563042994240829374041602535252466099000494570602496');
257 is(result.asString(16), expectedResult.asString(16), "first bit difference xor");
258
259
260 //
261 //isBitSet
262 //
263 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
264 result = bigInt_1.isBitSet(1);
265 expectedResult = true;
266 is(result, expectedResult, "'ff'.isBitSet(1)");
267
268 bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
269 result = bigInt_1.isBitSet(1);
270 expectedResult = false;
271 is(result, expectedResult, "'f0'.isBitSet(1)");
272
273 bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
274 result = bigInt_1.isBitSet(3);
275 expectedResult = false;
276 is(result, expectedResult, "'f0'.isBitSet(3)");
277
278 bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16);
279 result = bigInt_1.isBitSet(4);
280 expectedResult = true;
281 is(result, expectedResult, "'f0'.isBitSet(4)");
282
283 bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
284 result = bigInt_1.isBitSet(7);
285 expectedResult = false;
286 is(result, expectedResult, "'ff00'.isBitSet(7)");
287
288 bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16);
289 result = bigInt_1.isBitSet(8);
290 expectedResult = true;
291 is(result, expectedResult, "'ff00'.isBitSet(8)");
292
293 //
294 bigInt_1 = new Clipperz.Crypto.BigInt("05000000000000", 16);
295 result = bigInt_1.isBitSet(47);
296 expectedResult = false;
297 is(result, expectedResult, "'05000000000000'.isBitSet(47)");
298
299 result = bigInt_1.isBitSet(48);
300 expectedResult = true;
301 is(result, expectedResult, "'05000000000000'.isBitSet(48)");
302
303 result = bigInt_1.isBitSet(49);
304 expectedResult = false;
305 is(result, expectedResult, "'05000000000000'.isBitSet(49)");
306
307 result = bigInt_1.isBitSet(50);
308 expectedResult = true;
309 is(result, expectedResult, "'05000000000000'.isBitSet(50)");
310
311 result = bigInt_1.isBitSet(51);
312 expectedResult = false;
313 is(result, expectedResult, "'05000000000000'.isBitSet(51)");
314
315 //
316 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
317
318 result = bigInt_1.isBitSet(52);
319 expectedResult = true;
320 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)");
321
322 result = bigInt_1.isBitSet(53);
323 expectedResult = false;
324 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)");
325
326 result = bigInt_1.isBitSet(54);
327 expectedResult = false;
328 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)");
329
330 result = bigInt_1.isBitSet(55);
331 expectedResult = true;
332 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)");
333
334 result = bigInt_1.isBitSet(56);
335 expectedResult = false;
336 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)");
337
338 result = bigInt_1.isBitSet(57);
339 expectedResult = false;
340 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)");
341
342 result = bigInt_1.isBitSet(58);
343 expectedResult = true;
344 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)");
345
346 result = bigInt_1.isBitSet(59);
347 expectedResult = false;
348 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)");
349
350 result = bigInt_1.isBitSet(60);
351 expectedResult = false;
352 is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)");
353
354 //
355 //shiftLeft
356 //
357 bigInt_1 = new Clipperz.Crypto.BigInt("7f", 16);
358 result = bigInt_1.shiftLeft(1);
359 expectedResult = new Clipperz.Crypto.BigInt('fe', 16);
360 is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)");
361
362 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
363 result = bigInt_1.shiftLeft(1);
364 expectedResult = new Clipperz.Crypto.BigInt('01fe', 16);
365 is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)");
366
367 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
368 result = bigInt_1.shiftLeft(2);
369 expectedResult = new Clipperz.Crypto.BigInt('411949344998216388118140849290325291159199602592792139973517588004462660346196', 10);
370 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
371
372 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
373 result = bigInt_1.shiftLeft(8);
374 expectedResult = new Clipperz.Crypto.BigInt('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16);
375 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(8)");
376
377 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
378 result = bigInt_1.shiftLeft(10);
379 expectedResult = new Clipperz.Crypto.BigInt('105459032319543395358244057418323274536755098263754787833220502529142441048626176', 10);
380 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)");
381
382 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
383 result = bigInt_1.shiftLeft(4096);
384 expectedResult = new Clipperz.Crypto.BigInt('266319164760353889206396941232739217557890883507082863997979538237408246532747151496450837043424377376926977212182012023686831226737377369852125202402098145876219029018646049576792205484267848170179157853023266287725961304046416750146445344507869587461686016719979944538177432428730245324189334334817497396705169439104855885416460935698516539852892760625369984672271807592980051379072961966267124963131928067770749329011150668180796667192392027523071601150548205543997146350727148885425131890513407882508735446345822174200042918879518190588482963417582471561436215675823872015307629566605147920139961896995509627341070659007877630760561618021922340198636222738900413041589858099507891702174848695380017286939422770656819923801325579542295611580916900945707539132241939193098989585491346846486694653352501301851631933610655701026861715541355665900384634131852357081890301147104554877895768806174478161952060916705243614916310627428392386264214492834954273769685672081818149530274447979003153864646452529328518204716201193108795473912970645455457215455929896570875795325190705652768977680951535622436287312272907838194995042100153360373621439300266297151905265332115434133380301670205335338558744799343198526203012170200626802804318535680', 10);
385 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
386
387 bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16);
388 result = bigInt_1.shiftLeft(5000);
389 expectedResult = new Clipperz.Crypto.BigInt('36017909319555363939297846508911757008556852467205798478749046189356513330989041570231272721076143922520578818149998351104871978707844731275672652360293180474918203352225676748028889909508585302690242044220987556901043359920075229167479636668489487021705618421769517884399224788393498408327257966673365451264730932480701037648195190724361287852846952667257156204462064385766889505990099642052739974651257588866645027017486311782036674195285521311468922365736517586569614071211079825802088151607502649165228246449902253708785396560087430392277977851200155957347440614508171640900912431375050142178348130480158080696562512167652410483775588091117019722112093545783277082149415339867358805673644654236371762589715111732737686904860620316822561292797144756685380676343141118415434643259498221414744450502163805872581378284735047416230112208369784803081434462030568662742790926051825877463257023387907801068796855629691810029349692983890802136654401365294584656484852908751516361546884362396124203127393434938355516740711953765305060269622960662047729516459906444429108776596594293559927265789943280929098971285454533928986078946124455350540187565506016643147748500262510780357259199808936108629893209819473029835119866186316144675107047007737043503194737001430981972314376700993832503282107582239603281145093446879837002884732470988727066207277180181469885503549870618810897831820650576980763622189213611885522245978572420535750015505830146119605502167931087454823309031494727688701857532561113118183883936890880', 10);
390 is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)");
391
392
393 //
394 //BigInt compare vs ByteArray compare
395 //
396 var bigInt_byteArray_1;
397 var bigInt_byteArray_2;
398
399 //
400 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
401 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
402 bitInt_byteArray_1 = bigInt_1.asByteArray();
403 bitInt_byteArray_2 = bigInt_2.asByteArray();
404
405 result = bigInt_1.compare(bigInt_2);
406 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
407 is(result, expectedResult, "equal compare");
408
409 //
410 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
411 bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
412 bitInt_byteArray_1 = bigInt_1.asByteArray();
413 bitInt_byteArray_2 = bigInt_2.asByteArray();
414
415 result = bigInt_1.compare(bigInt_2);
416 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
417 is(result, expectedResult, "second term with one more bit at the leftmost - compare");
418
419 //
420 bigInt_1 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
421 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
422 bitInt_byteArray_1 = bigInt_1.asByteArray();
423 bitInt_byteArray_2 = bigInt_2.asByteArray();
424
425 result = bigInt_1.compare(bigInt_2);
426 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
427 is(result, expectedResult, "first term with one more bit at the leftmost - compare");
428
429 //
430 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
431 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
432 bitInt_byteArray_1 = bigInt_1.asByteArray();
433 bitInt_byteArray_2 = bigInt_2.asByteArray();
434
435 result = bigInt_1.compare(bigInt_2);
436 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
437 is(result, expectedResult, "first term with one more bit in the middle - compare");
438
439 //
440 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427af41e4649b934ca495991b7852b855", 16);
441 bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427aeffffffffffffffffffffffffffff", 16);
442 bitInt_byteArray_1 = bigInt_1.asByteArray();
443 bitInt_byteArray_2 = bigInt_2.asByteArray();
444
445 result = bigInt_1.compare(bigInt_2);
446 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
447 is(result, expectedResult, "first term with one more bit in the middle - compare");
448
449 //
450 bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16);
451 bigInt_2 = new Clipperz.Crypto.BigInt("05", 16);
452 bitInt_byteArray_1 = bigInt_1.asByteArray();
453 bitInt_byteArray_2 = bigInt_2.asByteArray();
454
455 result = bigInt_1.compare(bigInt_2);
456 expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2);
457 is(result, expectedResult, "equal compare");
458*/
459 //-------------------------------------------------------------------------
460} catch (err) {
461
462 var s = "test suite failure!\n";
463 var o = {};
464 var k = null;
465 for (k in err) {
466 // ensure unique keys?!
467 if (!o[k]) {
468 s += k + ": " + err[k] + "\n";
469 o[k] = err[k];
470 }
471 }
472 ok ( false, s );
473}
474
475</script>
476</pre>
477</body>
478</html>