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.html | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html b/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html index bdb0cbc..b970a9a 100644 --- a/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html +++ b/frontend/gamma/tests/tests/Clipperz/Crypto/BigInt.html @@ -1,408 +1,405 @@ <!-- Copyright 2008-2011 Clipperz Srl -This file is part of Clipperz's Javascript Crypto Library. -Javascript Crypto Library provides web developers with an extensive -and efficient set of cryptographic functions. The library aims to -obtain maximum execution speed while preserving modularity and -reusability. +This file is part of Clipperz Community Edition. +Clipperz Community Edition is an online password manager. For further information about its features and functionalities please -refer to http://www.clipperz.com +refer to http://www.clipperz.com. -* Javascript Crypto Library is free software: you can redistribute +* Clipperz Community Edition is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -* Javascript Crypto Library is distributed in the hope that it will +* Clipperz Community Edition is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. * You should have received a copy of the GNU Affero General Public - License along with Javascript Crypto Library. If not, see + License along with Clipperz Community Edition. If not, see <http://www.gnu.org/licenses/>. --> <html> <head> <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> <script type="text/javascript" src="../../../../js/JSLog/jslog.js"></script> <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script> <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script> <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Functions.js'></script> </head> <body> <pre id="test"> <script type="text/javascript"> try { var bigInt_1; var bigInt_2; var result; var expectedResult; // // Constructur and equality test // bigInt_1 = new Clipperz.Crypto.BigInt("110"); is (bigInt_1.equals(bigInt_1), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt("110"); bigInt_2 = new Clipperz.Crypto.BigInt("110", 10); is (bigInt_1.equals(bigInt_2), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt("110"); bigInt_2 = new Clipperz.Crypto.BigInt(110); is (bigInt_1.equals(bigInt_2), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt(6); bigInt_2 = new Clipperz.Crypto.BigInt("110", 2); is (bigInt_1.equals(bigInt_2), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt(6); bigInt_2 = new Clipperz.Crypto.BigInt("110", 3); is (bigInt_1.equals(bigInt_2), false, ""); // // Addition test // bigInt_1 = new Clipperz.Crypto.BigInt(6); bigInt_2 = new Clipperz.Crypto.BigInt(110); result = bigInt_1.add(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt(116); is (result.equals(expectedResult), true, ""); is (result.equals(Clipperz.Crypto.BigInt.add(bigInt_1, bigInt_2)), true, "instance method === static function"); bigInt_1 = new Clipperz.Crypto.BigInt(6); result = bigInt_1.add(6); expectedResult = new Clipperz.Crypto.BigInt(12); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161"); bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424"); result = bigInt_1.add(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585858585858585858585858585858585"); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt("16161616161616161616161616161616161616161616161616161"); bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424"); result = bigInt_1.add(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt("58585858585858585858585851585858585858585858585858585"); is (result.equals(expectedResult), false, ""); bigInt_1 = new Clipperz.Crypto.BigInt("86161616161616161616161616161616161616161616161616161"); bigInt_2 = new Clipperz.Crypto.BigInt("42424242424242424242424242424242424242424242424242424"); result = bigInt_1.add(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt("128585858585858585858585858585858585858585858585858585"); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt( "6541652165410321654063516540621063540654" + "0654065106540654165416521654103216540635" + "1654062106354065406540651065406541"); bigInt_2 = new Clipperz.Crypto.BigInt( "3046540351035403510354035103510351351351" + "0351350435103213540634132135401351035403" + "5403540354103540"); result = bigInt_1.add(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt( "6541652165410321657110056891656467051008" + "1005100210054167675767872089206430081269" + "2975416119864419441944191419510081"); is (result.equals(expectedResult), true, ""); // // Moltiplication test // bigInt_1 = new Clipperz.Crypto.BigInt(6); bigInt_2 = new Clipperz.Crypto.BigInt(110); result = bigInt_1.multiply(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt(660); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt(6); result = bigInt_1.multiply(5); expectedResult = new Clipperz.Crypto.BigInt(30); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt( "5465465165465465132743540354354032135463" + "5435135403513516843052413543054035"); bigInt_2 = new Clipperz.Crypto.BigInt( "3543513543543213543032135435413054365430" + "5130513540351354354305435403"); result = bigInt_1.multiply(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt( "1936694983559052629352223965314822970014" + "6364423657014976098029153153101751605574" + "5077086464435601381095664357540911830059" + "9503335163757031001105"); is (result.equals(expectedResult), true, ""); // // Module test // bigInt_1 = new Clipperz.Crypto.BigInt(106); bigInt_2 = new Clipperz.Crypto.BigInt(10); result = bigInt_1.module(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt(6); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt(106); result = bigInt_1.module(10); expectedResult = new Clipperz.Crypto.BigInt(6); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt( "5465465465468468465468463541358438543513" + "8543135435135423545624354235123512531235" + "1356463543840351351305135435121354305413" + "543"); bigInt_2 = new Clipperz.Crypto.BigInt( "3543543213543213540543545463542354385768" + "512584354354215"); result = bigInt_1.module(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt("52689987206612998786765715819079250963638640081836513"); is (result.equals(expectedResult), true, ""); // // Power (Module) test // bigInt_1 = new Clipperz.Crypto.BigInt(6); bigInt_2 = new Clipperz.Crypto.BigInt(3); result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt(1000)); expectedResult = new Clipperz.Crypto.BigInt(216); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt(6); result = bigInt_1.powerModule(3, 1000); expectedResult = new Clipperz.Crypto.BigInt(216); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt("354354354354687638546846846846846576876468746846846846"); bigInt_2 = new Clipperz.Crypto.BigInt("354"); result = bigInt_1.powerModule(bigInt_2, new Clipperz.Crypto.BigInt("3543541354354354354354351354354351354354354354354354")); expectedResult = new Clipperz.Crypto.BigInt("1957028940698171231089373321334263118681605242465644"); is (result.equals(expectedResult), true, ""); bigInt_1 = new Clipperz.Crypto.BigInt("e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", 16); // is(bigInt_1.toString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "IE bug"); is(bigInt_1.asString(16), "e0f6c73cf1d3715a0d77dc3a4eb9c66c01d913c91bc22d9672d83958445424a1", "fix for IE bug"); bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16); is(bigInt_1.asString(16, 64), "000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", "fix to ensure the string representation has a minimum fixed length"); /* // // Comparison // bigInt_1 = new Clipperz.Crypto.BigInt("0", 10); bigInt_2 = new Clipperz.Crypto.BigInt("0", 10); is (bigInt_1.equals(bigInt_2), true, "bigInt(0) = bigInt(0)"); is (bigInt_1.equals(0), true, "bigInt(0) = 0"); bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16); is (bigInt_1.equals(bigInt_2), false, "bigInt(xxxxxx) != bigInt(0)"); is (bigInt_1.equals(0), false, "bigInt(xxxxx) != 0"); bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16); bigInt_2 = new Clipperz.Crypto.BigInt("0", 16); is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(0)"); is(bigInt_2.compare(bigInt_1), -1, "bigInt(0) < bigInt(xxxx)"); bigInt_1 = new Clipperz.Crypto.BigInt("000108cbbacda1f03ea9360301045434ec7d82ba150936df08a229cbb4832ce1", 16); bigInt_2 = new Clipperz.Crypto.BigInt("05", 16); is(bigInt_1.compare(bigInt_2), 1, "bigInt(xxxxxx) > bigInt(05)"); is(bigInt_2.compare(bigInt_1), -1, "bigInt(05) < bigInt(xxxx)"); bigInt_1 = new Clipperz.Crypto.BigInt("-10", 10); bigInt_2 = new Clipperz.Crypto.BigInt("10", 10); is(bigInt_1.equals(bigInt_2), true, "bigInt(-10) - bigInt(10). No negative number are managed"); // // XOR // bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); result = bigInt_1.xor(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt(0); is(result.asString(16), expectedResult.asString(16), "a xor a = 0"); // bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16); result = bigInt_1.xor(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt('295147905179352825856'); is(result.asString(16), expectedResult.asString(16), "single bit difference"); // bigInt_1 = new Clipperz.Crypto.BigInt("01", 16); bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b935ca495991b7852b855", 16); result = bigInt_1.xor(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt('102987336249554097029535212322581322789799900648198034993674544906295017912404'); is(result.asString(16), expectedResult.asString(16), "01 xor value"); // bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); bigInt_2 = new Clipperz.Crypto.BigInt("f3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); result = bigInt_1.xor(bigInt_2); expectedResult = new Clipperz.Crypto.BigInt('7237005577332262213973186563042994240829374041602535252466099000494570602496'); is(result.asString(16), expectedResult.asString(16), "first bit difference xor"); // // isBitSet // bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16); result = bigInt_1.isBitSet(1); expectedResult = true; is(result, expectedResult, "'ff'.isBitSet(1)"); bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16); result = bigInt_1.isBitSet(1); expectedResult = false; is(result, expectedResult, "'f0'.isBitSet(1)"); bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16); result = bigInt_1.isBitSet(3); expectedResult = false; is(result, expectedResult, "'f0'.isBitSet(3)"); bigInt_1 = new Clipperz.Crypto.BigInt("f0", 16); result = bigInt_1.isBitSet(4); expectedResult = true; is(result, expectedResult, "'f0'.isBitSet(4)"); bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16); result = bigInt_1.isBitSet(7); expectedResult = false; is(result, expectedResult, "'ff00'.isBitSet(7)"); bigInt_1 = new Clipperz.Crypto.BigInt("ff00", 16); result = bigInt_1.isBitSet(8); expectedResult = true; is(result, expectedResult, "'ff00'.isBitSet(8)"); // bigInt_1 = new Clipperz.Crypto.BigInt("05000000000000", 16); result = bigInt_1.isBitSet(47); expectedResult = false; is(result, expectedResult, "'05000000000000'.isBitSet(47)"); result = bigInt_1.isBitSet(48); expectedResult = true; is(result, expectedResult, "'05000000000000'.isBitSet(48)"); result = bigInt_1.isBitSet(49); expectedResult = false; is(result, expectedResult, "'05000000000000'.isBitSet(49)"); result = bigInt_1.isBitSet(50); expectedResult = true; is(result, expectedResult, "'05000000000000'.isBitSet(50)"); result = bigInt_1.isBitSet(51); expectedResult = false; is(result, expectedResult, "'05000000000000'.isBitSet(51)"); // bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); result = bigInt_1.isBitSet(52); expectedResult = true; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(52)"); result = bigInt_1.isBitSet(53); expectedResult = false; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(53)"); result = bigInt_1.isBitSet(54); expectedResult = false; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(54)"); result = bigInt_1.isBitSet(55); expectedResult = true; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(55)"); result = bigInt_1.isBitSet(56); expectedResult = false; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(56)"); result = bigInt_1.isBitSet(57); expectedResult = false; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(57)"); result = bigInt_1.isBitSet(58); expectedResult = true; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(58)"); result = bigInt_1.isBitSet(59); expectedResult = false; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(59)"); result = bigInt_1.isBitSet(60); expectedResult = false; is(result, expectedResult, "'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'.isBitSet(60)"); // // shiftLeft // bigInt_1 = new Clipperz.Crypto.BigInt("7f", 16); result = bigInt_1.shiftLeft(1); expectedResult = new Clipperz.Crypto.BigInt('fe', 16); is(result.asString(16), expectedResult.asString(16), "'7f'.shiftLeft(1)"); bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16); result = bigInt_1.shiftLeft(1); expectedResult = new Clipperz.Crypto.BigInt('01fe', 16); is(result.asString(16), expectedResult.asString(16), "'ff'.shiftLeft(1)"); bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); result = bigInt_1.shiftLeft(2); expectedResult = new Clipperz.Crypto.BigInt('411949344998216388118140849290325291159199602592792139973517588004462660346196', 10); is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)"); bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); result = bigInt_1.shiftLeft(8); expectedResult = new Clipperz.Crypto.BigInt('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500', 16); is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(8)"); bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); result = bigInt_1.shiftLeft(10); expectedResult = new Clipperz.Crypto.BigInt('105459032319543395358244057418323274536755098263754787833220502529142441048626176', 10); is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(10)"); bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16); result = bigInt_1.shiftLeft(4096); expectedResult = new Clipperz.Crypto.BigInt('266319164760353889206396941232739217557890883507082863997979538237408246532747151496450837043424377376926977212182012023686831226737377369852125202402098145876219029018646049576792205484267848170179157853023266287725961304046416750146445344507869587461686016719979944538177432428730245324189334334817497396705169439104855885416460935698516539852892760625369984672271807592980051379072961966267124963131928067770749329011150668180796667192392027523071601150548205543997146350727148885425131890513407882508735446345822174200042918879518190588482963417582471561436215675823872015307629566605147920139961896995509627341070659007877630760561618021922340198636222738900413041589858099507891702174848695380017286939422770656819923801325579542295611580916900945707539132241939193098989585491346846486694653352501301851631933610655701026861715541355665900384634131852357081890301147104554877895768806174478161952060916705243614916310627428392386264214492834954273769685672081818149530274447979003153864646452529328518204716201193108795473912970645455457215455929896570875795325190705652768977680951535622436287312272907838194995042100153360373621439300266297151905265332115434133380301670205335338558744799343198526203012170200626802804318535680', 10); is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)"); bigInt_1 = new Clipperz.Crypto.BigInt("ff", 16); result = bigInt_1.shiftLeft(5000); expectedResult = new Clipperz.Crypto.BigInt('36017909319555363939297846508911757008556852467205798478749046189356513330989041570231272721076143922520578818149998351104871978707844731275672652360293180474918203352225676748028889909508585302690242044220987556901043359920075229167479636668489487021705618421769517884399224788393498408327257966673365451264730932480701037648195190724361287852846952667257156204462064385766889505990099642052739974651257588866645027017486311782036674195285521311468922365736517586569614071211079825802088151607502649165228246449902253708785396560087430392277977851200155957347440614508171640900912431375050142178348130480158080696562512167652410483775588091117019722112093545783277082149415339867358805673644654236371762589715111732737686904860620316822561292797144756685380676343141118415434643259498221414744450502163805872581378284735047416230112208369784803081434462030568662742790926051825877463257023387907801068796855629691810029349692983890802136654401365294584656484852908751516361546884362396124203127393434938355516740711953765305060269622960662047729516459906444429108776596594293559927265789943280929098971285454533928986078946124455350540187565506016643147748500262510780357259199808936108629893209819473029835119866186316144675107047007737043503194737001430981972314376700993832503282107582239603281145093446879837002884732470988727066207277180181469885503549870618810897831820650576980763622189213611885522245978572420535750015505830146119605502167931087454823309031494727688701857532561113118183883936890880', 10); is(result.asString(16), expectedResult.asString(16), "bigInt.shiftLeft(4096)"); // // BigInt compare vs ByteArray compare // var bigInt_byteArray_1; var bigInt_byteArray_2; // bigInt_1 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); bigInt_2 = new Clipperz.Crypto.BigInt("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); bitInt_byteArray_1 = bigInt_1.asByteArray(); bitInt_byteArray_2 = bigInt_2.asByteArray(); result = bigInt_1.compare(bigInt_2); expectedResult = bitInt_byteArray_1.compare(bitInt_byteArray_2); is(result, expectedResult, "equal compare"); |