File indexing completed on 2024-05-12 04:45:26
0001 /** 0002 * Copyright (C) 2004-2006 Brad Hards <bradh@frogmouth.net> 0003 * 0004 * Redistribution and use in source and binary forms, with or without 0005 * modification, are permitted provided that the following conditions 0006 * are met: 0007 * 0008 * 1. Redistributions of source code must retain the above copyright 0009 * notice, this list of conditions and the following disclaimer. 0010 * 2. Redistributions in binary form must reproduce the above copyright 0011 * notice, this list of conditions and the following disclaimer in the 0012 * documentation and/or other materials provided with the distribution. 0013 * 0014 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 0015 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 0016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 0017 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 0018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 0019 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0020 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0021 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 0023 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0024 */ 0025 0026 #include <QtCrypto> 0027 #include <QtTest/QtTest> 0028 0029 #ifdef QT_STATICPLUGIN 0030 #include "import_plugins.h" 0031 #endif 0032 0033 class BigIntUnitTest : public QObject 0034 { 0035 Q_OBJECT 0036 0037 private Q_SLOTS: 0038 void initTestCase(); 0039 void cleanupTestCase(); 0040 void allTests(); 0041 0042 private: 0043 QCA::Initializer *m_init; 0044 }; 0045 0046 void BigIntUnitTest::initTestCase() 0047 { 0048 m_init = new QCA::Initializer; 0049 } 0050 0051 void BigIntUnitTest::cleanupTestCase() 0052 { 0053 delete m_init; 0054 } 0055 0056 void BigIntUnitTest::allTests() 0057 { 0058 QCA::BigInteger result; 0059 0060 // Some string conversion tests 0061 QCOMPARE(QCA::BigInteger("255").toString(), QCA::BigInteger(255).toString()); 0062 QCOMPARE(QCA::BigInteger("-255").toString(), QCA::BigInteger(-255).toString()); 0063 QCOMPARE(QCA::BigInteger("255").toString(), QStringLiteral("255")); 0064 QCOMPARE(QCA::BigInteger("-255").toString(), QStringLiteral("-255")); 0065 QCOMPARE(QCA::BigInteger("255"), QCA::BigInteger(QCA::BigInteger(255).toArray())); 0066 QCOMPARE(QCA::BigInteger("-255"), QCA::BigInteger(QCA::BigInteger(-255).toArray())); 0067 0068 // Some operator tests 0069 QCOMPARE(QCA::BigInteger("255") == QCA::BigInteger(255), true); 0070 QCOMPARE(QCA::BigInteger("-255") == QCA::BigInteger(-255), true); 0071 QCOMPARE(QCA::BigInteger("256") != QCA::BigInteger(255), true); 0072 QCOMPARE(QCA::BigInteger("-256") != QCA::BigInteger(-255), true); 0073 0074 // Some comparison tests 0075 QCA::BigInteger a("4000000000000"); 0076 QCA::BigInteger b("-4000000000000"); 0077 QCA::BigInteger c("2000000000000"); 0078 QCOMPARE(a < b, false); 0079 QCOMPARE(a <= b, false); 0080 QCOMPARE(a.compare(b), 1); 0081 QCOMPARE(a > b, true); 0082 QCOMPARE(a >= b, true); 0083 QCOMPARE(a > c, true); 0084 QCOMPARE(c.compare(b), 1); 0085 QCOMPARE(c.compare(a), -1); 0086 0087 // Check if the stream operator is any good 0088 QString testString; 0089 QTextStream ts(&testString, QIODevice::WriteOnly); 0090 ts << a << b << c << Qt::endl; 0091 QCOMPARE(testString, QStringLiteral("4000000000000-40000000000002000000000000\n")); 0092 0093 // Botan's addition tests 0094 QCOMPARE(QCA::BigInteger(255) += QCA::BigInteger(1), QCA::BigInteger(256)); 0095 result = QCA::BigInteger(255) += QCA::BigInteger(1); 0096 QCOMPARE(result.toString(), QCA::BigInteger(256).toString()); 0097 0098 result = QCA::BigInteger("65535") += QCA::BigInteger("1"); 0099 QCOMPARE(result.toString(), QStringLiteral("65536")); 0100 QCOMPARE(result, QCA::BigInteger("65536")); 0101 0102 result = QCA::BigInteger("4294967295") += QCA::BigInteger(1); 0103 QCOMPARE(result.toString(), QStringLiteral("4294967296")); 0104 QCOMPARE(result, QCA::BigInteger("4294967296")); 0105 0106 result = QCA::BigInteger("18446744073709551615") += QCA::BigInteger(1); 0107 QCOMPARE(result.toString(), QStringLiteral("18446744073709551616")); 0108 QCOMPARE(result, QCA::BigInteger("18446744073709551616")); 0109 0110 result = QCA::BigInteger("124536363637272472") += QCA::BigInteger("124536363637272472"); 0111 QCOMPARE(result.toString(), QStringLiteral("249072727274544944")); 0112 QCOMPARE(result, QCA::BigInteger("249072727274544944")); 0113 0114 result = QCA::BigInteger("9223372036854775807") += QCA::BigInteger("281474976710655"); 0115 QCOMPARE(result.toString(), QStringLiteral("9223653511831486462")); 0116 QCOMPARE(result, QCA::BigInteger("9223653511831486462")); 0117 0118 result = QCA::BigInteger("9223372036854775807") += QCA::BigInteger("137438953471"); 0119 QCOMPARE(result.toString(), QStringLiteral("9223372174293729278")); 0120 QCOMPARE(result, QCA::BigInteger("9223372174293729278")); 0121 0122 // Botan's carry tests 0123 result = QCA::BigInteger("340282366920938463463374607431768211455") += 0124 QCA::BigInteger("340282366920938463463374607431768211455"); 0125 QCOMPARE(result.toString(), QStringLiteral("680564733841876926926749214863536422910")); 0126 QCOMPARE(result, QCA::BigInteger("680564733841876926926749214863536422910")); 0127 0128 result = QCA::BigInteger("340282366920938463463374607431768211455") += 0129 QCA::BigInteger("340282366920938463463374607431768211450"); 0130 QCOMPARE(result.toString(), QStringLiteral("680564733841876926926749214863536422905")); 0131 QCOMPARE(result, QCA::BigInteger("680564733841876926926749214863536422905")); 0132 0133 result = QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935") += 0134 QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935"); 0135 QCOMPARE(result.toString(), 0136 QStringLiteral("231584178474632390847141970017375815706539969331281128078915168015826259279870")); 0137 QCOMPARE(result, QCA::BigInteger("231584178474632390847141970017375815706539969331281128078915168015826259279870")); 0138 0139 result = QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935") += 0140 QCA::BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639919"); 0141 QCOMPARE(result.toString(), 0142 QStringLiteral("231584178474632390847141970017375815706539969331281128078915168015826259279854")); 0143 QCOMPARE(result, QCA::BigInteger("231584178474632390847141970017375815706539969331281128078915168015826259279854")); 0144 0145 result = QCA::BigInteger( 0146 "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858" 0147 "186486050853753882811946569946433649006084095") += QCA::BigInteger("18446744073709551616"); 0148 QCOMPARE(result.toString(), 0149 QStringLiteral("134078079299425970995740249982058461274793658205923933777235614437217640300735469768018742" 0150 "98166903427690031858186486050853753882811946588393177722715635711")); 0151 QCOMPARE(result, 0152 QCA::BigInteger("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874" 0153 "298166903427690031858186486050853753882811946588393177722715635711")); 0154 0155 result = QCA::BigInteger( 0156 "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858" 0157 "186486050853753882811946569946433649006084095") += QCA::BigInteger("1"); 0158 QCOMPARE(result.toString(), 0159 QStringLiteral("134078079299425970995740249982058461274793658205923933777235614437217640300735469768018742" 0160 "98166903427690031858186486050853753882811946569946433649006084096")); 0161 QCOMPARE(result, 0162 QCA::BigInteger("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874" 0163 "298166903427690031858186486050853753882811946569946433649006084096")); 0164 0165 result = QCA::BigInteger( 0166 "-3979427001391940661083482696042714676976618976483847341650296529192053560111268857919862747528477749805933030" 0167 "6128763345008528325994574657552726381901") += QCA::BigInteger("-342238655038"); 0168 QCOMPARE(result.toString(), 0169 QStringLiteral("-39794270013919406610834826960427146769766189764838473416502965291920535601112688579198627" 0170 "475284777498059330306128763345008528325994574657894965036939")); 0171 QCOMPARE(result, 0172 QCA::BigInteger("-3979427001391940661083482696042714676976618976483847341650296529192053560111268857919862" 0173 "7475284777498059330306128763345008528325994574657894965036939")); 0174 0175 result = QCA::BigInteger( 0176 "25110291853498940831251897922987678157346336093292373576945426289097725034326735312448621015537884914") += 0177 QCA::BigInteger("-36551081154398645734533965739979697527373251608055056627686956281114038842935173436543461"); 0178 QCOMPARE( 0179 result.toString(), 0180 QStringLiteral( 0181 "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453")); 0182 QCOMPARE( 0183 result, 0184 QCA::BigInteger( 0185 "25110291853462389750097499277253144191606356395765000325337371232470038078045621273605685842101341453")); 0186 0187 result = QCA::BigInteger("27802650352") += QCA::BigInteger("660736146705288303126411072388564329913778942"); 0188 QCOMPARE(result.toString(), QStringLiteral("660736146705288303126411072388564357716429294")); 0189 QCOMPARE(result, QCA::BigInteger("660736146705288303126411072388564357716429294")); 0190 0191 result = QCA::BigInteger( 0192 "-1348245899955041864800954463709881466231496038216683608715424566397833766910915722793041224478985289") += 0193 QCA::BigInteger( 0194 "1151714952286618235856515264359526625702022859705853911311473221800833298790436145729926116122727676438617" 0195 "3666571334749062651694592291882972"); 0196 QCOMPARE(result.toString(), 0197 QStringLiteral("115171495228661823585651526435952662570188803511585840712499312635446231064381299612610444" 0198 "77618561339819775832804423833339858653367812897683")); 0199 QCOMPARE(result, 0200 QCA::BigInteger("11517149522866182358565152643595266257018880351158584071249931263544623106438129961261044" 0201 "477618561339819775832804423833339858653367812897683")); 0202 0203 result = QCA::BigInteger( 0204 "-17540530441681616962868251635133601915039026254996886583618243914226325157426408929602625346567256761818") += 0205 QCA::BigInteger("865200427983527245206901810160356641402419461642082623179544681519016990"); 0206 QCOMPARE(result.toString(), 0207 QStringLiteral("-17540530441681616962868251635132736714611042727751679681808083557584922737964766846979445" 0208 "801885737744828")); 0209 QCOMPARE(result, 0210 QCA::BigInteger("-1754053044168161696286825163513273671461104272775167968180808355758492273796476684697944" 0211 "5801885737744828")); 0212 0213 result = QCA::BigInteger("128844776074298261556398714096948603458177018275051329218555498374") += QCA::BigInteger( 0214 "44381631382915087636205223513461060322054892810769796122995361187369527639191715091334647906024675972047519364" 0215 "8"); 0216 QCOMPARE(result.toString(), 0217 QStringLiteral("443816313829150876362052235134610603220548928236542737304251873430093990488865754371523497" 0218 "335298088939030692022")); 0219 QCOMPARE(result, 0220 QCA::BigInteger("44381631382915087636205223513461060322054892823654273730425187343009399048886575437152349" 0221 "7335298088939030692022")); 0222 0223 result = QCA::BigInteger("1709484189262457846620911889502097055085989595277300243221975568275935717696463") += 0224 QCA::BigInteger("-1646592344139809206374540620411514484579951199941360"); 0225 QCOMPARE(result.toString(), 0226 QStringLiteral("1709484189262457846620911887855504710946180388902759622810461083695984517755103")); 0227 QCOMPARE(result, 0228 QCA::BigInteger("1709484189262457846620911887855504710946180388902759622810461083695984517755103")); 0229 0230 result = QCA::BigInteger( 0231 "32017586542963717616570934157618710254018062780641801520492877117023353895132395250905592913967322327352806288" 0232 "3083030595199153877335714942842") += 0233 QCA::BigInteger( 0234 "-2828241696960736089879965882386687935938570856545481227619497640844399275054327390050478930503975773972"); 0235 QCOMPARE(result.toString(), 0236 QStringLiteral("320175865429637176165709341576187102537352386109457279115048805287846851015385381652510447" 0237 "912053725632683663608028703205148674946831739168870")); 0238 QCOMPARE(result, 0239 QCA::BigInteger("32017586542963717616570934157618710253735238610945727911504880528784685101538538165251044" 0240 "7912053725632683663608028703205148674946831739168870")); 0241 0242 result = QCA::BigInteger( 0243 "-4035398360542181725908295312107496142105415014744259439963377204111754181625695349185753326709217") += 0244 QCA::BigInteger("85450213703789913646546187382091037800"); 0245 QCOMPARE(result.toString(), 0246 QStringLiteral( 0247 "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417")); 0248 QCOMPARE(result, 0249 QCA::BigInteger( 0250 "-4035398360542181725908295312107496142105415014744259439963291753898050391712048802998371235671417")); 0251 0252 result = QCA::BigInteger( 0253 "-1292166446073479876801522363382357887431657639184151284775525387363973852756087726243671676713861533673009088" 0254 "319851") += 0255 QCA::BigInteger( 0256 "8045388958745181755374994252823750582362455317985903504033438417669555720706432671419456956248951093302427" 0257 "49935754739434394691714971"); 0258 QCOMPARE(result.toString(), 0259 QStringLiteral("804538895874518174245332979208895181434723168416232462971686202582804287295117879777971842" 0260 "868807383086571073221893205761385603395120")); 0261 QCOMPARE(result, 0262 QCA::BigInteger("80453889587451817424533297920889518143472316841623246297168620258280428729511787977797184" 0263 "2868807383086571073221893205761385603395120")); 0264 0265 result = QCA::BigInteger( 0266 "-4519865887009263094594517568520056973794810149560079685292342518849465226829012150220864325970243240622408355" 0267 "64200177389") += QCA::BigInteger("15762983479"); 0268 QCOMPARE(result.toString(), 0269 QStringLiteral("-45198658870092630945945175685200569737948101495600796852923425188494652268290121502208643" 0270 "2597024324062240835548437193910")); 0271 QCOMPARE(result, 0272 QCA::BigInteger("-4519865887009263094594517568520056973794810149560079685292342518849465226829012150220864" 0273 "32597024324062240835548437193910")); 0274 0275 result = QCA::BigInteger( 0276 "-3907475412115728816974567022055278374116794025624287474334038831885743634200801846649105209920908153587891040" 0277 "882946582394429615396962188674594744360388466") += 0278 QCA::BigInteger("193893611236537854694879677478106237157079207398283117392998175454362643521031390"); 0279 QCOMPARE(result.toString(), 0280 QStringLiteral("-39074754121157288169745670220552783741167940256242874743340388318857436340069082354125673" 0281 "55226028476109784803725867374996146498003964013220232100839357076")); 0282 QCOMPARE(result, 0283 QCA::BigInteger("-3907475412115728816974567022055278374116794025624287474334038831885743634006908235412567" 0284 "355226028476109784803725867374996146498003964013220232100839357076")); 0285 0286 result = QCA::BigInteger("-72603710637966201224690926289") += 0287 QCA::BigInteger("-13618442642298533261581255034923612640512507150728017106768861506299813289801666559564532"); 0288 QCOMPARE( 0289 result.toString(), 0290 QStringLiteral("-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821")); 0291 QCOMPARE( 0292 result, 0293 QCA::BigInteger("-13618442642298533261581255034923612640512507150728017106768934110010451256002891250490821")); 0294 0295 result = QCA::BigInteger( 0296 "56077960835713056831402948406790747107889446769357509759472207603483968107693997028111823994257399379783658853" 0297 "302692762256851623103019589392739") += 0298 QCA::BigInteger("-427057313888431079237360487703561848638868677065083968842"); 0299 QCOMPARE(result.toString(), 0300 QStringLiteral("560779608357130568314029484067907471078894467693575097594722076034839681076939970281113969" 0301 "36943510948704421492814989200408212754425954505423897")); 0302 QCOMPARE(result, 0303 QCA::BigInteger("56077960835713056831402948406790747107889446769357509759472207603483968107693997028111396" 0304 "936943510948704421492814989200408212754425954505423897")); 0305 0306 result = QCA::BigInteger("-2209800838508504443494783762534800337712101405156784708782197580824527899758308") += 0307 QCA::BigInteger( 0308 "4284407650303949586450021392583759850781770841835415277411207859644308960659857039623581632798746339397171" 0309 "0495985285591895096794994387176281079"); 0310 QCOMPARE(result.toString(), 0311 QStringLiteral("428440765030394958645002139258375985078177084183541527741120785942332887680900659527410325" 0312 "65452663056259609090828500883112899214169859276522771")); 0313 QCOMPARE(result, 0314 QCA::BigInteger("42844076503039495864500213925837598507817708418354152774112078594233288768090065952741032" 0315 "565452663056259609090828500883112899214169859276522771")); 0316 0317 result = QCA::BigInteger( 0318 "33887767308809826842417841176152232321272231788338404526859019370507113927387984766381329515371768224976188337" 0319 "692") += QCA::BigInteger("349484339542971517481628970179002500341"); 0320 QCOMPARE(result.toString(), 0321 QStringLiteral("338877673088098268424178411761522323212722317883384045268590193705071139277374691059243010" 0322 "32853397195155190838033")); 0323 QCOMPARE(result, 0324 QCA::BigInteger("33887767308809826842417841176152232321272231788338404526859019370507113927737469105924301" 0325 "032853397195155190838033")); 0326 0327 result = QCA::BigInteger( 0328 "85748089639858660722587321621536298082690707526412426951630101551228144063151688592419555048867068162") += 0329 QCA::BigInteger("-383634567691961960211191292397062452265352651123492760493087381707279"); 0330 QCOMPARE( 0331 result.toString(), 0332 QStringLiteral( 0333 "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883")); 0334 QCOMPARE( 0335 result, 0336 QCA::BigInteger( 0337 "85748089639858660722587321621535914448123015564452215760337704488775878710500565099659061961485360883")); 0338 0339 result = QCA::BigInteger("23889807888563742283608049816129153552608399262924421832404872043475") += 0340 QCA::BigInteger("995"); 0341 QCOMPARE(result.toString(), QStringLiteral("23889807888563742283608049816129153552608399262924421832404872044470")); 0342 QCOMPARE(result, QCA::BigInteger("23889807888563742283608049816129153552608399262924421832404872044470")); 0343 0344 result = QCA::BigInteger( 0345 "-6547869258334748646692309625826942226114726807018592624664656062396549960483067839575496977812718292577743295" 0346 "38985") += QCA::BigInteger("-276137507159648540503039013089014674747"); 0347 QCOMPARE(result.toString(), 0348 QStringLiteral("-65478692583347486466923096258269422261147268070185926246646560623965499604858292146470934" 0349 "6321774868270863344213732")); 0350 QCOMPARE(result, 0351 QCA::BigInteger("-6547869258334748646692309625826942226114726807018592624664656062396549960485829214647093" 0352 "46321774868270863344213732")); 0353 0354 result = QCA::BigInteger("50463316268089933") += QCA::BigInteger( 0355 "-1405915834634318069210003494981352875890054233189278509478942429953101385694731575213124136524392343244191305" 0356 "27702899917161307657443381774866237429"); 0357 QCOMPARE(result.toString(), 0358 QStringLiteral("-14059158346343180692100034949813528758900542331892785094789424299531013856947315752131241" 0359 "3652439234324419130527702899917161307657392918458598147496")); 0360 QCOMPARE(result, 0361 QCA::BigInteger("-1405915834634318069210003494981352875890054233189278509478942429953101385694731575213124" 0362 "13652439234324419130527702899917161307657392918458598147496")); 0363 0364 result = QCA::BigInteger( 0365 "1339015021665554488163337105187026760232395594198925052890859936\ 0366 418304234254229440059229155546157793544192") += 0367 QCA::BigInteger( 0368 "6294037420283433712414743361937677483761554699961644450461297486224793278823004487175687771163597590566132" 0369 "592591599249970281125781761944353272"); 0370 QCOMPARE(result.toString(), 0371 QStringLiteral("629403742028343371241474336193767748510056972162719893862463459141182003905540008137461282" 0372 "4054457526984436826845828690029510281327919737897464")); 0373 QCOMPARE(result, 0374 QCA::BigInteger("62940374202834337124147433619376774851005697216271989386246345914118200390554000813746128" 0375 "24054457526984436826845828690029510281327919737897464")); 0376 0377 result = QCA::BigInteger("-241446683") += QCA::BigInteger( 0378 "-282671163032866994488211995758272717472259277760825940523445628\ 0379 442206062910449311538519756165635175664610569214430918184214"); 0380 QCOMPARE(result.toString(), 0381 QStringLiteral("-28267116303286699448821199575827271747225927776082594052344562844220606291044931153851975" 0382 "6165635175664610569214431159630897")); 0383 QCOMPARE(result, 0384 QCA::BigInteger("-2826711630328669944882119957582727174722592777608259405234456284422060629104493115385197" 0385 "56165635175664610569214431159630897")); 0386 0387 result = QCA::BigInteger( 0388 "23586055033034526379960814219020565159517446117183831284424451195057397075503263789123424483550462390668969955" 0389 "63581") += 0390 QCA::BigInteger("-3830437229145325165273364525551261440648845791949681661260946956860463720730123941973615"); 0391 QCOMPARE(result.toString(), 0392 QStringLiteral("235860550330345263799608141807161928680641944644501860289118367885689391560064471765139549" 0393 "1494582518336773053589966")); 0394 QCOMPARE(result, 0395 QCA::BigInteger("23586055033034526379960814180716192868064194464450186028911836788568939156006447176513954" 0396 "91494582518336773053589966")); 0397 0398 result = QCA::BigInteger("1860794367587960058388097846258490") += 0399 QCA::BigInteger("-237344494507203983863096991896035366478949095337787603280"); 0400 QCOMPARE(result.toString(), QStringLiteral("-237344494507203983863095131101667778518890707239941344790")); 0401 QCOMPARE(result, QCA::BigInteger("-237344494507203983863095131101667778518890707239941344790")); 0402 0403 result = QCA::BigInteger("-286399096802321907543674770412181810379003627366516307780436082546") += 0404 QCA::BigInteger("6433131620680089024037442172197761714707480582555136398379812339597187475099646442833150194"); 0405 QCOMPARE( 0406 result.toString(), 0407 QStringLiteral("6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648")); 0408 QCOMPARE( 0409 result, 0410 QCA::BigInteger("6433131620680089024037441885798664912385573038880365986198001960593560108583338662397067648")); 0411 0412 result = QCA::BigInteger( 0413 "18118033907710236955953781758362789478332280418185972957475244257214680056902377349016498752054120312533829578" 0414 "5763244283224569259250011493") += 0415 QCA::BigInteger( 0416 "-119912766577350317025030707802803587547945939765717835695952624506754949712992302334818793328075301820498" 0417 "3010837846725666878521137637491"); 0418 QCOMPARE(result.toString(), 0419 QStringLiteral("179981211411328866389287510505599858907843344784202551217792916327079251071893850466816799" 0420 "587260450107133312774925397557557690738112374002")); 0421 QCOMPARE(result, 0422 QCA::BigInteger("17998121141132886638928751050559985890784334478420255121779291632707925107189385046681679" 0423 "9587260450107133312774925397557557690738112374002")); 0424 0425 result = QCA::BigInteger( 0426 "-6414020139555553381140864289162018465205127581107592617628203214491558550345077676836677565241902214951203461" 0427 "1311149858695307750874152") += QCA::BigInteger("174441039"); 0428 QCOMPARE(result.toString(), 0429 QStringLiteral("-64140201395555533811408642891620184652051275811075926176282032144915585503450776768366775" 0430 "652419022149512034611311149858695307576433113")); 0431 QCOMPARE(result, 0432 QCA::BigInteger("-6414020139555553381140864289162018465205127581107592617628203214491558550345077676836677" 0433 "5652419022149512034611311149858695307576433113")); 0434 0435 result = QCA::BigInteger( 0436 "12727579443088358572080378780185073375305574454222304955616346165037244198775127175123602392596401935136013522" 0437 "02821462208896049331599624285621") += 0438 QCA::BigInteger( 0439 "7326562354017884140300121264633612334070903165496641915889499701\ 0440 38457507491850467631029977010"); 0441 QCOMPARE(result.toString(), 0442 QStringLiteral("127275794430883585720803787801850733753055744542296315179703640491775443200397607874576732" 0443 "9576189857705190302172959919716387899799230654262631")); 0444 QCOMPARE(result, 0445 QCA::BigInteger("12727579443088358572080378780185073375305574454229631517970364049177544320039760787457673" 0446 "29576189857705190302172959919716387899799230654262631")); 0447 0448 result = QCA::BigInteger("-296171972628230") += QCA::BigInteger( 0449 "-8295766099121843219000823699362222865173820102569731517716391727126741710202086962877467940292139"); 0450 QCOMPARE(result.toString(), 0451 QStringLiteral( 0452 "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369")); 0453 QCOMPARE(result, 0454 QCA::BigInteger( 0455 "-8295766099121843219000823699362222865173820102569731517716391727126741710202086963173639912920369")); 0456 0457 result = QCA::BigInteger("746985914068199510024843682108839444828414222769191520615967632362127522466922882591") += 0458 QCA::BigInteger("-20487191102299831461877807785745372724903547246374023"); 0459 QCOMPARE(result.toString(), 0460 QStringLiteral("746985914068199510024843682108818957637311922937729642808181886989402618919676508568")); 0461 QCOMPARE(result, 0462 QCA::BigInteger("746985914068199510024843682108818957637311922937729642808181886989402618919676508568")); 0463 0464 result = QCA::BigInteger("-4") += 0465 QCA::BigInteger("-2344390090753264806043234960981151613122271366762590006930318876906455201397017135"); 0466 QCOMPARE(result.toString(), 0467 QStringLiteral("-2344390090753264806043234960981151613122271366762590006930318876906455201397017139")); 0468 QCOMPARE(result, 0469 QCA::BigInteger("-2344390090753264806043234960981151613122271366762590006930318876906455201397017139")); 0470 0471 result = QCA::BigInteger("-44876180273995737337769331875058141129678736711749946388832275767882143882764") += 0472 QCA::BigInteger("20982187786"); 0473 QCOMPARE(result.toString(), 0474 QStringLiteral("-44876180273995737337769331875058141129678736711749946388832275767861161694978")); 0475 QCOMPARE(result, QCA::BigInteger("-44876180273995737337769331875058141129678736711749946388832275767861161694978")); 0476 0477 result = QCA::BigInteger( 0478 "-601944008264824351134005823298148744369561537910415436895793990789678217920719566630222862549689727198849" 0479 "4") += 0480 QCA::BigInteger( 0481 "532566302499155416003316607801593784583652720754079760364736422291735917382015688217276924340984564880"); 0482 QCOMPARE(result.toString(), 0483 QStringLiteral("-60189075163457443559240549163736858499110317263834002891975751714744904432898136506140113" 0484 "48572556287423614")); 0485 QCOMPARE(result, 0486 QCA::BigInteger("-6018907516345744355924054916373685849911031726383400289197575171474490443289813650614011" 0487 "348572556287423614")); 0488 0489 result = QCA::BigInteger( 0490 "-7375547156361602684772634935716753083385095966292105905292822923781472871944886871927821129478599825311797681" 0491 "2683153264088230182865250970217610487") += 0492 QCA::BigInteger("-30100016097092378349958946184353117306134810372681"); 0493 QCOMPARE(result.toString(), 0494 QStringLiteral("-73755471563616026847726349357167530833850959662921059052928229237814728719448868719278211" 0495 "294786028353134073905061503223034414535982557105027983168")); 0496 QCOMPARE(result, 0497 QCA::BigInteger("-7375547156361602684772634935716753083385095966292105905292822923781472871944886871927821" 0498 "1294786028353134073905061503223034414535982557105027983168")); 0499 0500 result = QCA::BigInteger( 0501 "-2211177066689704345686852756638946306674958952044447080285364283965878599873864667094550865713828159912") += 0502 QCA::BigInteger( 0503 "-536556043937245689200756579876160678199726920153847573681478030051738396345585808165230823703346036004092" 0504 "1820049494698892905680307378540208"); 0505 QCOMPARE(result.toString(), 0506 QStringLiteral("-53655604393724568920075657987616067842084462682281800825016330571563302701308170336967553" 0507 "17318824644006800419923359365987456546021206700120")); 0508 QCOMPARE(result, 0509 QCA::BigInteger("-5365560439372456892007565798761606784208446268228180082501633057156330270130817033696755" 0510 "317318824644006800419923359365987456546021206700120")); 0511 0512 result = QCA::BigInteger( 0513 "60741225123371088419685216490350768416336915742544171041442859708190687151580370231498672521465704184848502349" 0514 "79838064249373816163440") += QCA::BigInteger("301843614094506325875637699"); 0515 QCOMPARE(result.toString(), 0516 QStringLiteral("607412251233710884196852164903507684163369157425441710414428597081906871515803702314986725" 0517 "2146570418484850536823452158755699691801139")); 0518 QCOMPARE(result, 0519 QCA::BigInteger("60741225123371088419685216490350768416336915742544171041442859708190687151580370231498672" 0520 "52146570418484850536823452158755699691801139")); 0521 0522 result = QCA::BigInteger( 0523 "-5182147769311581499087713405643489820105439851080650534792191527346598920424997741288096547136515478330872068" 0524 "93256740737426200715673766732196603988") += 0525 QCA::BigInteger( 0526 "-2983517255774769372611552588738613700467454531142255734565888403876035392822615770224917521828071895197" 0527 "9"); 0528 QCOMPARE(result.toString(), 0529 QStringLiteral("-51821477693115814990877134056434898201054401494323761122691287885018577942863677880335496" 0530 "6136208893491971245653610668963583902964848985012915555967")); 0531 QCOMPARE(result, 0532 QCA::BigInteger("-5182147769311581499087713405643489820105440149432376112269128788501857794286367788033549" 0533 "66136208893491971245653610668963583902964848985012915555967")); 0534 0535 result = QCA::BigInteger("15937412249227240968245047444122") += QCA::BigInteger( 0536 "186214680376169426108822450700978827886569053440254258585576645530381613666540347032550716844628275956253"); 0537 QCOMPARE(result.toString(), 0538 QStringLiteral("186214680376169426108822450700978827886569053440254258585576645530381613682477759281777957" 0539 "812873323400375")); 0540 QCOMPARE(result, 0541 QCA::BigInteger("18621468037616942610882245070097882788656905344025425858557664553038161368247775928177795" 0542 "7812873323400375")); 0543 0544 result = QCA::BigInteger( 0545 "-1252801011625868585504750425292810762392310545870176170791196952700385571348584614055110796749581358409708177" 0546 "7160") += 0547 QCA::BigInteger( 0548 "-539986280927242338236008809854961759996986302156061552378097160849129372827386927545686899193598721998757" 0549 "419572890"); 0550 QCOMPARE(result.toString(), 0551 QStringLiteral("-55251429104350102409105631410788986762090940761476331408600913037613322854087277368623800" 0552 "7161094535582854501350050")); 0553 QCOMPARE(result, 0554 QCA::BigInteger("-5525142910435010240910563141078898676209094076147633140860091303761332285408727736862380" 0555 "07161094535582854501350050")); 0556 0557 result = QCA::BigInteger("-2454746908") += QCA::BigInteger( 0558 "-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030211860839641756441626" 0559 "913419699098985245833920954444218"); 0560 QCOMPARE(result.toString(), 0561 QStringLiteral("-38229571278893947800552421563603701870755920786555523760506046799344150145738795138700302" 0562 "11860839641756441626913419699098985245833923409191126")); 0563 QCOMPARE(result, 0564 QCA::BigInteger("-3822957127889394780055242156360370187075592078655552376050604679934415014573879513870030" 0565 "211860839641756441626913419699098985245833923409191126")); 0566 0567 result = QCA::BigInteger("-54288706131860071583318409080596095357980447323635") += QCA::BigInteger( 0568 "-4253394105560156310989737429933273230514384568190270696062942611579402976432972405594521244327792021815897638" 0569 "74"); 0570 QCOMPARE(result.toString(), 0571 QStringLiteral("-42533941055601563109897374299332732305143845681902706960629431544664642950336882387786120" 0572 "5028874560162037087509")); 0573 QCOMPARE(result, 0574 QCA::BigInteger("-4253394105560156310989737429933273230514384568190270696062943154466464295033688238778612" 0575 "05028874560162037087509")); 0576 0577 result = QCA::BigInteger( 0578 "1418766894051319870818496026367686195459604395660119754151922014257535705077512233275240217434104") += 0579 QCA::BigInteger("-111987390206074845527"); 0580 QCOMPARE(result.toString(), 0581 QStringLiteral( 0582 "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577")); 0583 QCOMPARE(result, 0584 QCA::BigInteger( 0585 "1418766894051319870818496026367686195459604395660119754151922014257535705077400245885034142588577")); 0586 0587 result = QCA::BigInteger( 0588 "-6904101318604104774561038575945435154096774792428336186348093024529626004763532868225501682312348541164651530" 0589 "78845744722987447719420052500874721214723") += 0590 QCA::BigInteger( 0591 "-258469037743394674731135699243278836145549479106673938483740960989738710973653960062315588091814633168127" 0592 "2708396146283818299"); 0593 QCOMPARE(result.toString(), 0594 QStringLiteral("-69041013186041047745610386017923389284362422655419061106759766390845739154309267165995977" 0595 "8128621963853004753702001625641133779400692760897021005033022")); 0596 QCOMPARE(result, 0597 QCA::BigInteger("-6904101318604104774561038601792338928436242265541906110675976639084573915430926716599597" 0598 "78128621963853004753702001625641133779400692760897021005033022")); 0599 0600 result = QCA::BigInteger("-2326153002179462643778624079324592172489363679671158") += 0601 QCA::BigInteger("-109819757548464054181938329012610459679"); 0602 QCOMPARE(result.toString(), QStringLiteral("-2326153002179572463536172543378774110818376290130837")); 0603 QCOMPARE(result, QCA::BigInteger("-2326153002179572463536172543378774110818376290130837")); 0604 0605 result = QCA::BigInteger( 0606 "-4428752250566525488353857709194941742993785578807911414016959206453045495320705299466107784149485981354180907" 0607 "411034982168391") += 0608 QCA::BigInteger( 0609 "-39247778259374215325521768005388007526581235832446540589720560855741992694947322437679214611686905696"); 0610 QCOMPARE(result.toString(), 0611 QStringLiteral("-44287522505665254883538969569732011172091111005759168020244857876888779418612950200269635" 0612 "26142180928676618586625646669074087")); 0613 QCOMPARE(result, 0614 QCA::BigInteger("-4428752250566525488353896956973201117209111100575916802024485787688877941861295020026963" 0615 "526142180928676618586625646669074087")); 0616 0617 result = QCA::BigInteger("3047") += QCA::BigInteger( 0618 "-7356458785031315352377693216371961073343377689039020461804017379719600010085607082927794304834315616579528230" 0619 "7508135277641315214"); 0620 QCOMPARE(result.toString(), 0621 QStringLiteral("-73564587850313153523776932163719610733433776890390204618040173797196000100856070829277943" 0622 "048343156165795282307508135277641312167")); 0623 QCOMPARE(result, 0624 QCA::BigInteger("-7356458785031315352377693216371961073343377689039020461804017379719600010085607082927794" 0625 "3048343156165795282307508135277641312167")); 0626 0627 result = QCA::BigInteger( 0628 "71397189765381049110362731262243394989390499523719445987286843598407339615555456955143712741779487184644001767" 0629 "776382991377987516772847242986") += 0630 QCA::BigInteger("-5821969555717973232123574849275726788359152255219972775831"); 0631 QCOMPARE(result.toString(), 0632 QStringLiteral("713971897653810491103627312622433949893904995237194459872868435984073396155554569493217431" 0633 "86061513952520426918500656203018835261552874467155")); 0634 QCOMPARE(result, 0635 QCA::BigInteger("71397189765381049110362731262243394989390499523719445987286843598407339615555456949321743" 0636 "186061513952520426918500656203018835261552874467155")); 0637 0638 result = QCA::BigInteger( 0639 "-1814097526566131387779640926359093790218263603909606471867269911652274001767668314665411600499352055079190702" 0640 "33410228328274") += 0641 QCA::BigInteger( 0642 "-523301382154855044703947051892202646490840761177533623732372519689918420769842424772676407501350528096714" 0643 "904915297347684247802773107355881667545916901"); 0644 QCOMPARE(result.toString(), 0645 QStringLiteral("-52330138215485504470394705207361239914745389995549771636828189871174478116080307195940339" 0646 "8666577928273481736381838507734183008281026426115077774245175")); 0647 QCOMPARE(result, 0648 QCA::BigInteger("-5233013821548550447039470520736123991474538999554977163682818987117447811608030719594033" 0649 "98666577928273481736381838507734183008281026426115077774245175")); 0650 0651 result = QCA::BigInteger("6858961373707073067") += QCA::BigInteger( 0652 "-3340515089338930614338442797642711071819749062833649913099030776499716064369180713270728698264719460945945941" 0653 "15614990907"); 0654 QCOMPARE(result.toString(), 0655 QStringLiteral("-33405150893389306143384427976427110718197490628336499130990307764997160643691807132707286" 0656 "9826471946087735632741907917840")); 0657 QCOMPARE(result, 0658 QCA::BigInteger("-3340515089338930614338442797642711071819749062833649913099030776499716064369180713270728" 0659 "69826471946087735632741907917840")); 0660 0661 result = QCA::BigInteger( 0662 "-23635098930374569407171906960429616870908424281519944658490940109956689534874971218650241680916564611") += 0663 QCA::BigInteger( 0664 "-189589178757795228335995891331428279524485393011427187469792714438466702359827437934396866267364281985416" 0665 "47202983677887505430060922528525205"); 0666 QCOMPARE(result.toString(), 0667 QStringLiteral("-18958917875779522833599589133142827952472174400073093316386443350807099852853652217721206" 0668 "571394919138651603892518552858724080302603445089816")); 0669 QCOMPARE(result, 0670 QCA::BigInteger("-1895891787577952283359958913314282795247217440007309331638644335080709985285365221772120" 0671 "6571394919138651603892518552858724080302603445089816")); 0672 0673 // Botan's subtraction tests 0674 result = QCA::BigInteger("0") -= QCA::BigInteger("0"); 0675 QCOMPARE(result.toString(), QStringLiteral("0")); 0676 QCOMPARE(result, QCA::BigInteger("0")); 0677 0678 result = QCA::BigInteger("0") -= QCA::BigInteger("1"); 0679 QCOMPARE(result.toString(), QStringLiteral("-1")); 0680 QCOMPARE(result, QCA::BigInteger("-1")); 0681 0682 result = QCA::BigInteger("0") -= QCA::BigInteger("4294967296"); 0683 QCOMPARE(result.toString(), QStringLiteral("-4294967296")); 0684 QCOMPARE(result, QCA::BigInteger("-4294967296")); 0685 0686 // Next test is labelled # 2^512 - 1 0687 result = QCA::BigInteger( 0688 "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858" 0689 "186486050853753882811946569946433649006084095") -= QCA::BigInteger("1"); 0690 QCOMPARE(result.toString(), 0691 QStringLiteral("134078079299425970995740249982058461274793658205923933777235614437217640300735469768018742" 0692 "98166903427690031858186486050853753882811946569946433649006084094")); 0693 QCOMPARE(result, 0694 QCA::BigInteger("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874" 0695 "298166903427690031858186486050853753882811946569946433649006084094")); 0696 0697 result = QCA::BigInteger("89094716573076464980713547115099137014719483620102078148320806773871083148864") -= 0698 QCA::BigInteger("49505213825110728957828173754776257356620450607893971553289366249708672306581"); 0699 QCOMPARE(result.toString(), 0700 QStringLiteral("39589502747965736022885373360322879658099033012208106595031440524162410842283")); 0701 QCOMPARE(result, QCA::BigInteger("39589502747965736022885373360322879658099033012208106595031440524162410842283")); 0702 0703 result = QCA::BigInteger("65894747009896006767807716946835412110318548717263922395390971078905789585431") -= 0704 QCA::BigInteger("3884269741925508225990715416862047284194603799902650748631039608684367281358"); 0705 QCOMPARE(result.toString(), 0706 QStringLiteral("62010477267970498541817001529973364826123944917361271646759931470221422304073")); 0707 QCOMPARE(result, QCA::BigInteger("62010477267970498541817001529973364826123944917361271646759931470221422304073")); 0708 0709 result = QCA::BigInteger( 0710 "59501963964519775669021213017070542183647171968931013600114917777619522537369647091659626133477106071641786829" 0711 "87783755894811024288429224592316636383") -= 0712 QCA::BigInteger( 0713 "8750653273562160761286422180115618621879821429145276197424652349306577311499807887070429373153777028581165" 0714 "316131683348567"); 0715 QCOMPARE(result.toString(), 0716 QStringLiteral("595019639645197756690212129295640094480255643560667917989587315588213082459168851174131026" 0717 "4041133295664370795917354382741033995707263908460633287816")); 0718 QCOMPARE(result, 0719 QCA::BigInteger("59501963964519775669021212929564009448025564356066791798958731558821308245916885117413102" 0720 "64041133295664370795917354382741033995707263908460633287816")); 0721 0722 result = QCA::BigInteger("9815262808265519920770782360080149146267723690") -= QCA::BigInteger( 0723 "14067005768891609281364919358115291341352189918255780397560060748765650205261663193732434161580120817"); 0724 QCOMPARE( 0725 result.toString(), 0726 QStringLiteral( 0727 "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127")); 0728 QCOMPARE( 0729 result, 0730 QCA::BigInteger( 0731 "-14067005768891609281364919358115291341352189918255780387744797940500130284490880833652285015312397127")); 0732 0733 result = QCA::BigInteger( 0734 "-3901491029419486215684797223469406667043760137344853438401542216058534125031549938788864908670209347775308945" 0735 "93416337175399865065870417717658815158195790") -= 0736 QCA::BigInteger("1456031684988128870809574635750149625240648487837308"); 0737 QCOMPARE(result.toString(), 0738 QStringLiteral("-39014910294194862156847972234694066670437601373448534384015422160585341250315499387888649" 0739 "0867020934778986926278404466046209439701620567342899463646033098")); 0740 QCOMPARE(result, 0741 QCA::BigInteger("-3901491029419486215684797223469406667043760137344853438401542216058534125031549938788864" 0742 "90867020934778986926278404466046209439701620567342899463646033098")); 0743 0744 result = QCA::BigInteger("7473774301764883450943") -= 0745 QCA::BigInteger("-26256369859367890755157372820052387483402723790185562908491933812453"); 0746 QCOMPARE(result.toString(), QStringLiteral("26256369859367890755157372820052387483402723797659337210256817263396")); 0747 QCOMPARE(result, QCA::BigInteger("26256369859367890755157372820052387483402723797659337210256817263396")); 0748 0749 result = QCA::BigInteger( 0750 "36246343251214922024139186757009148849295485593397952003237349660142296147421019916619944353877490544706223768" 0751 "684758263065399016597969") -= 0752 QCA::BigInteger( 0753 "2574427901445527995149185461475228850098549655325125750771680756403104624569522792792597223218143154924988" 0754 "199562355517064962665954307425375180"); 0755 QCOMPARE(result.toString(), 0756 QStringLiteral("-25744278651991847439342634373360420930894008060296401573737287531657549644272266453715773" 0757 "06598198801047497654856131748380204402888908408777211")); 0758 QCOMPARE(result, 0759 QCA::BigInteger("-2574427865199184743934263437336042093089400806029640157373728753165754964427226645371577" 0760 "306598198801047497654856131748380204402888908408777211")); 0761 0762 result = QCA::BigInteger("30129746266682790628283889040897642317014108334116727") -= 0763 QCA::BigInteger("-1580480523895398762563721715474380903630073871362143915864398724834897608423"); 0764 QCOMPARE(result.toString(), 0765 QStringLiteral("1580480523895398762563751845220647586420702155251184813506715738943231725150")); 0766 QCOMPARE(result, QCA::BigInteger("1580480523895398762563751845220647586420702155251184813506715738943231725150")); 0767 0768 result = QCA::BigInteger("-4614735863800137951667138933166372061") -= 0769 QCA::BigInteger("87175694379075561307234146162193190462135078700346746992273"); 0770 QCOMPARE(result.toString(), QStringLiteral("-87175694379075561307238760898056990600086745839279913364334")); 0771 QCOMPARE(result, QCA::BigInteger("-87175694379075561307238760898056990600086745839279913364334")); 0772 0773 result = QCA::BigInteger("-3753904") -= QCA::BigInteger("-11269137783745339515071988205310702154422777729974"); 0774 QCOMPARE(result.toString(), QStringLiteral("11269137783745339515071988205310702154422773976070")); 0775 QCOMPARE(result, QCA::BigInteger("11269137783745339515071988205310702154422773976070")); 0776 0777 result = QCA::BigInteger( 0778 "59252394849537944008202127973817008840291885845547005014065278717183005886493293990079450595543785692690297587" 0779 "0288") -= QCA::BigInteger("-205854658295495452479104108497931263758143158076949293929661651111"); 0780 QCOMPARE(result.toString(), 0781 QStringLiteral("592523948495379440082021279738170088402918858455675904798948282624309162973430871164552649" 0782 "113514806220832637521399")); 0783 QCOMPARE(result, 0784 QCA::BigInteger("59252394849537944008202127973817008840291885845567590479894828262430916297343087116455264" 0785 "9113514806220832637521399")); 0786 0787 result = QCA::BigInteger("-33993701617495591491176844355") -= QCA::BigInteger( 0788 "3438065097398894672826284379125235190693300918673662774192379185002391232383325160416036963599856704698280"); 0789 QCOMPARE(result.toString(), 0790 QStringLiteral("-34380650973988946728262843791252351906933009186736627741923791850023912323833591541176544" 0791 "59191347881542635")); 0792 QCOMPARE(result, 0793 QCA::BigInteger("-3438065097398894672826284379125235190693300918673662774192379185002391232383359154117654" 0794 "459191347881542635")); 0795 0796 result = QCA::BigInteger("26876428790838270949718735111909136008255051776703") -= QCA::BigInteger( 0797 "-1781128112966810373286192008831149275546995635268767241859967609117529616872536681035700534316457543887601645" 0798 "022"); 0799 QCOMPARE(result.toString(), 0800 QStringLiteral("178112811296681037328619200883114927554699563526876724185996763599395840771080763075443564" 0801 "6225593552142653421725")); 0802 QCOMPARE(result, 0803 QCA::BigInteger("17811281129668103732861920088311492755469956352687672418599676359939584077108076307544356" 0804 "46225593552142653421725")); 0805 0806 result = QCA::BigInteger( 0807 "2059771092932179758019770618974659367350250375647433386639519387\ 0808 69317693429941871882153770641334267205446421916220398066553188") -= 0809 QCA::BigInteger("3342500267594994347156312297990633112620923791590960237694328174171473763026"); 0810 QCOMPARE(result.toString(), 0811 QStringLiteral("205977109293217975801977061897465936735025037564739996163684343774970537117643881249041149" 0812 "717542676245208727588046226592790162")); 0813 QCOMPARE(result, 0814 QCA::BigInteger("20597710929321797580197706189746593673502503756473999616368434377497053711764388124904114" 0815 "9717542676245208727588046226592790162")); 0816 0817 result = QCA::BigInteger("5545520403000578843599072515870982842927227412121917598877293331575380404618111609") -= 0818 QCA::BigInteger("5991287327241003718821424770352575362437680738923552868139860461945460339860477495902"); 0819 QCOMPARE(result.toString(), 0820 QStringLiteral("-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293")); 0821 QCOMPARE(result, 0822 QCA::BigInteger("-5985741806838003139977825697836704379594753511511430950540983168613884959455859384293")); 0823 0824 result = QCA::BigInteger("248039029608125071340") -= QCA::BigInteger("3664608673"); 0825 QCOMPARE(result.toString(), QStringLiteral("248039029604460462667")); 0826 QCOMPARE(result, QCA::BigInteger("248039029604460462667")); 0827 0828 result = QCA::BigInteger("15425705711415937103627") -= QCA::BigInteger( 0829 "-1435504065517745703440045276868982910754081405474123003767554211132837427846963435621523810229738262235546179" 0830 "779885824"); 0831 QCOMPARE(result.toString(), 0832 QStringLiteral("143550406551774570344004527686898291075408140547412300376755421113283742784696343562152381" 0833 "0229753687941257595716989451")); 0834 QCOMPARE(result, 0835 QCA::BigInteger("14355040655177457034400452768689829107540814054741230037675542111328374278469634356215238" 0836 "10229753687941257595716989451")); 0837 0838 result = QCA::BigInteger("50882847205108645607281568922683652688671738236030732914347600821086") -= 0839 QCA::BigInteger("12176160963158"); 0840 QCOMPARE(result.toString(), QStringLiteral("50882847205108645607281568922683652688671738236030732902171439857928")); 0841 QCOMPARE(result, QCA::BigInteger("50882847205108645607281568922683652688671738236030732902171439857928")); 0842 0843 result = QCA::BigInteger( 0844 "-3542651856598581894767004787703302288554217246197356622850977105341631254320181588119095376220762923216041205" 0845 "8300173038824256783171761132") -= 0846 QCA::BigInteger("-4864862607366468843184694353123830534588538011093812418208808135799"); 0847 QCOMPARE(result.toString(), 0848 QStringLiteral("-35426518565985818947670047877033022885542172461973566228509771053416307678339208514722110" 0849 "577513276108329877469762161945011838574363625333")); 0850 QCOMPARE(result, 0851 QCA::BigInteger("-3542651856598581894767004787703302288554217246197356622850977105341630767833920851472211" 0852 "0577513276108329877469762161945011838574363625333")); 0853 0854 result = QCA::BigInteger( 0855 "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599921571184") -= 0856 QCA::BigInteger("-4054101"); 0857 QCOMPARE(result.toString(), 0858 QStringLiteral( 0859 "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083")); 0860 QCOMPARE(result, 0861 QCA::BigInteger( 0862 "-1428596214712268310382144828171384812520179141608121870013556402879770424002218157546599917517083")); 0863 0864 result = QCA::BigInteger("-200931") -= QCA::BigInteger( 0865 "-4455880246013049575948283291316071779115178672557051947544960765970517168228311149083493083504573514296684748" 0866 "3009157514950177565952218520297258834187372"); 0867 QCOMPARE(result.toString(), 0868 QStringLiteral("445588024601304957594828329131607177911517867255705194754496076597051716822831114908349308" 0869 "35045735142966847483009157514950177565952218520297258833986441")); 0870 QCOMPARE(result, 0871 QCA::BigInteger("44558802460130495759482832913160717791151786725570519475449607659705171682283111490834930" 0872 "835045735142966847483009157514950177565952218520297258833986441")); 0873 0874 result = QCA::BigInteger("105704314890799915321259") -= QCA::BigInteger( 0875 "82792354594507641557491243849916981441456306687749410083165776119049069747385436947778487411878749535140554980" 0876 "3329615347120938123226038208"); 0877 QCOMPARE(result.toString(), 0878 QStringLiteral("-82792354594507641557491243849916981441456306687749410083165776119049069747385436947778487" 0879 "4118787495351405549803329509642806047323310716949")); 0880 QCOMPARE(result, 0881 QCA::BigInteger("-8279235459450764155749124384991698144145630668774941008316577611904906974738543694777848" 0882 "74118787495351405549803329509642806047323310716949")); 0883 0884 result = QCA::BigInteger("1448979433940064018828919290452280235308901982649341") -= 0885 QCA::BigInteger("303926827425887072291878308433008512899006711759770318009"); 0886 QCOMPARE(result.toString(), QStringLiteral("-303925378446453132227859479513718060618771402857787668668")); 0887 QCOMPARE(result, QCA::BigInteger("-303925378446453132227859479513718060618771402857787668668")); 0888 0889 result = QCA::BigInteger("-243237595290235750457450892290434789864") -= QCA::BigInteger( 0890 "19817702076334276402981273067417321098467533300947463865383702005126562800253466403934608765512316565811954342" 0891 "319565128573969"); 0892 QCOMPARE(result.toString(), 0893 QStringLiteral("-19817702076334276402981273067417321098467533300947463865383702005126562800253466403934852" 0894 "003107606801562411793211855563363833")); 0895 QCOMPARE(result, 0896 QCA::BigInteger("-1981770207633427640298127306741732109846753330094746386538370200512656280025346640393485" 0897 "2003107606801562411793211855563363833")); 0898 0899 result = QCA::BigInteger("294037338365659932242802023634") -= 0900 QCA::BigInteger("4401245995535867764294876849802142926077599828776505639975554254356763769548465"); 0901 QCOMPARE(result.toString(), 0902 QStringLiteral("-4401245995535867764294876849802142926077599828776211602637188594424520967524831")); 0903 QCOMPARE(result, 0904 QCA::BigInteger("-4401245995535867764294876849802142926077599828776211602637188594424520967524831")); 0905 0906 result = QCA::BigInteger("7303853946195223307036710881687367004566538357189824031021831088365362") -= 0907 QCA::BigInteger("119286025999378935715794641163321741"); 0908 QCOMPARE(result.toString(), 0909 QStringLiteral("7303853946195223307036710881687366885280512357810888315227189925043621")); 0910 QCOMPARE(result, QCA::BigInteger("7303853946195223307036710881687366885280512357810888315227189925043621")); 0911 0912 result = 0913 QCA::BigInteger("571167355343287235687602610714110416067426289363505412908804940696550592413192300554016875") -= 0914 QCA::BigInteger("15872188842802631759540597"); 0915 QCOMPARE( 0916 result.toString(), 0917 QStringLiteral("571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278")); 0918 QCOMPARE( 0919 result, 0920 QCA::BigInteger("571167355343287235687602610714110416067426289363505412908804940680678403570389668794476278")); 0921 0922 result = QCA::BigInteger("1002240129784524388754179399598974973256811336031329881209395070412702275169416754240") -= 0923 QCA::BigInteger( 0924 "5942948247886059134314539354042003351647830595287234900671578947794647475365720680007051520796770907993342" 0925 "0746952"); 0926 QCOMPARE(result.toString(), 0927 QStringLiteral("-59429482478860591343145393539417793386693781564118169607116814504689663417625876918861120" 0928 "137555006804764003992712")); 0929 QCOMPARE(result, 0930 QCA::BigInteger("-5942948247886059134314539353941779338669378156411816960711681450468966341762587691886112" 0931 "0137555006804764003992712")); 0932 0933 result = QCA::BigInteger( 0934 "1370431648825444838359719050380239722263203134555431526491525074601463042144798545817957389") -= 0935 QCA::BigInteger("3473869878"); 0936 QCOMPARE( 0937 result.toString(), 0938 QStringLiteral("1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511")); 0939 QCOMPARE( 0940 result, 0941 QCA::BigInteger("1370431648825444838359719050380239722263203134555431526491525074601463042144798542344087511")); 0942 0943 result = QCA::BigInteger("8548280229254726209") -= 0944 QCA::BigInteger("33066125035269904981849320434016892734943145935582141989968280846973981913056248918"); 0945 QCOMPARE(result.toString(), 0946 QStringLiteral("-33066125035269904981849320434016892734943145935582141989968280838425701683801522709")); 0947 QCOMPARE(result, 0948 QCA::BigInteger("-33066125035269904981849320434016892734943145935582141989968280838425701683801522709")); 0949 0950 result = QCA::BigInteger( 0951 "-1902355883268750648950815079596633217599012996302992895858417011175963029327693964733408210016910253836443785" 0952 "9846398095065171936899503") -= 0953 QCA::BigInteger( 0954 "2489927112752354534228346876280965340763863196622012469575197689419310377944305084304077119122752284308807" 0955 "9031762445684377195650493065096847292797"); 0956 QCOMPARE(result.toString(), 0957 QStringLiteral("-24899271127542568901116156269299161558434598298396114825715006823151687949554810473334048" 0958 "130874856925188248134300810122237042048588130268784192300")); 0959 QCOMPARE(result, 0960 QCA::BigInteger("-2489927112754256890111615626929916155843459829839611482571500682315168794955481047333404" 0961 "8130874856925188248134300810122237042048588130268784192300")); 0962 0963 result = QCA::BigInteger( 0964 "-1800353575522706389288305623797196690530870204356722928042061228497437075035917720399302198953687023") -= 0965 QCA::BigInteger( 0966 "-118756682615304660537085387309407764121711064830726245327571774713841280164583325446427884047654699244961" 0967 "27460164"); 0968 QCOMPARE(result.toString(), 0969 QStringLiteral("118756682615286657001330160245514881065473092863820936625528207484560859552298351075677524" 0970 "87045070622297173773141")); 0971 QCOMPARE(result, 0972 QCA::BigInteger("11875668261528665700133016024551488106547309286382093662552820748456085955229835107567752" 0973 "487045070622297173773141")); 0974 0975 result = QCA::BigInteger("-29861551039945217879") -= QCA::BigInteger( 0976 "11134730259168556423534561466475429305816690823484096396972829608778892265003199963808382325823762328728689476" 0977 "24793789212829885934"); 0978 QCOMPARE(result.toString(), 0979 QStringLiteral("-11134730259168556423534561466475429305816690823484096396972829608778892265003199963808382" 0980 "32582376232872868947654655340252775103813")); 0981 QCOMPARE(result, 0982 QCA::BigInteger("-1113473025916855642353456146647542930581669082348409639697282960877889226500319996380838" 0983 "232582376232872868947654655340252775103813")); 0984 0985 result = QCA::BigInteger( 0986 "56553296365676115383821827756495791765870729764975792067630330165532810366551228779710851013983764350649164198" 0987 "7188791892506290") -= QCA::BigInteger("-2188105671531473889939411772533707"); 0988 QCOMPARE(result.toString(), 0989 QStringLiteral("565532963656761153838218277564957917658707297649757920676303301655328103665512287797108510" 0990 "142025749178023115877128203665039997")); 0991 QCOMPARE(result, 0992 QCA::BigInteger("56553296365676115383821827756495791765870729764975792067630330165532810366551228779710851" 0993 "0142025749178023115877128203665039997")); 0994 0995 result = QCA::BigInteger("-349535960680522202843083381184496349093812380954435872337802226") -= 0996 QCA::BigInteger("-1829600726218222026679938"); 0997 QCOMPARE(result.toString(), QStringLiteral("-349535960680522202843083381184496349091982780228217650311122288")); 0998 QCOMPARE(result, QCA::BigInteger("-349535960680522202843083381184496349091982780228217650311122288")); 0999 1000 result = QCA::BigInteger("-1") -= QCA::BigInteger("-6726974989587128275"); 1001 QCOMPARE(result.toString(), QStringLiteral("6726974989587128274")); 1002 QCOMPARE(result, QCA::BigInteger("6726974989587128274")); 1003 1004 result = QCA::BigInteger("-107142709838121196902389095205618516687047338619382145236348309762148611647954748824") -= 1005 QCA::BigInteger("42484103615491"); 1006 QCOMPARE(result.toString(), 1007 QStringLiteral("-107142709838121196902389095205618516687047338619382145236348309762148654132058364315")); 1008 QCOMPARE(result, 1009 QCA::BigInteger("-107142709838121196902389095205618516687047338619382145236348309762148654132058364315")); 1010 1011 result = 1012 QCA::BigInteger("-90546630430085769764839607528116121381848878494574360812027599640018921358040178215575723") -= 1013 QCA::BigInteger( 1014 "-118922408531468986902800063237122125617455464103913195171141030774109638861272017660698580914239435114280" 1015 "434761425243"); 1016 QCOMPARE(result.toString(), 1017 QStringLiteral("118922408531468986902800063146575495187369694339073587643024909392260760366697656848670981" 1018 "274220513756240256545849520")); 1019 QCOMPARE(result, 1020 QCA::BigInteger("11892240853146898690280006314657549518736969433907358764302490939226076036669765684867098" 1021 "1274220513756240256545849520")); 1022 1023 result = QCA::BigInteger( 1024 "-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086267287272360432363387" 1025 "213743735507218270373633222520429") -= QCA::BigInteger("-151423255459028627628896755237194376177115"); 1026 QCOMPARE(result.toString(), 1027 QStringLiteral("-55450446670824271288017264167276573600015884301135781828506575730632419398825703245730862" 1028 "67287272360280940131754715107878321515136438846343314")); 1029 QCOMPARE(result, 1030 QCA::BigInteger("-5545044667082427128801726416727657360001588430113578182850657573063241939882570324573086" 1031 "267287272360280940131754715107878321515136438846343314")); 1032 1033 result = QCA::BigInteger("-5247636471953421659649611318164848102069") -= 1034 QCA::BigInteger("-4024324110573096565232590473170599175885004"); 1035 QCOMPARE(result.toString(), QStringLiteral("4019076474101143143572940861852434327782935")); 1036 QCOMPARE(result, QCA::BigInteger("4019076474101143143572940861852434327782935")); 1037 1038 result = QCA::BigInteger("39412892606015043322484854253879371723186457838590224795040178472832") -= 1039 QCA::BigInteger("-5038321321957452145034687815432890684825466579123474921848465393400312"); 1040 QCOMPARE(result.toString(), 1041 QStringLiteral("5077734214563467188357172669686770056548653036962065146643505571873144")); 1042 QCOMPARE(result, QCA::BigInteger("5077734214563467188357172669686770056548653036962065146643505571873144")); 1043 1044 result = QCA::BigInteger( 1045 "-5597941458800922703568362450520876675318746972779964027720427420784331758329273633391278382952827027264258300" 1046 "4969175230274821") -= 1047 QCA::BigInteger( 1048 "-109633110576212669339535976775635762395927171313557427036242111476016398579345366908401334025571265714128" 1049 "108308032073779442181369365924213118258269679"); 1050 QCOMPARE(result.toString(), 1051 QStringLiteral("109633110576212669339535920796221174386700135629932921827475358288546670779705089704127126" 1052 "182253682421391774395248244251171908726782919243943027994858")); 1053 QCOMPARE(result, 1054 QCA::BigInteger("10963311057621266933953592079622117438670013562993292182747535828854667077970508970412712" 1055 "6182253682421391774395248244251171908726782919243943027994858")); 1056 1057 result = 1058 QCA::BigInteger("-38752353898173389347479216285772999906325286421302866854350737050533204094183249691110") -= 1059 QCA::BigInteger( 1060 "2428819407377764342156426895396654728835493564788997075896393065230009911546390816091652653701035085361"); 1061 QCOMPARE(result.toString(), 1062 QStringLiteral("-24288194073777643809087807935700440763147098505619969822216794865328767658971278666248567" 1063 "47884284776471")); 1064 QCOMPARE(result, 1065 QCA::BigInteger("-2428819407377764380908780793570044076314709850561996982221679486532876765897127866624856" 1066 "747884284776471")); 1067 1068 result = QCA::BigInteger("-2784579005241382005249492720344") -= 1069 QCA::BigInteger("-164204542616919252351131740123094674"); 1070 QCOMPARE(result.toString(), QStringLiteral("164201758037914010969126490630374330")); 1071 QCOMPARE(result, QCA::BigInteger("164201758037914010969126490630374330")); 1072 1073 result = QCA::BigInteger("200948857420871544747808060972375039052401280822505804851732868100") -= 1074 QCA::BigInteger("-795957177479360455258269298038670876462147576765875895105714"); 1075 QCOMPARE(result.toString(), QStringLiteral("200949653378049024108263319241673077723277742970082570727627973814")); 1076 QCOMPARE(result, QCA::BigInteger("200949653378049024108263319241673077723277742970082570727627973814")); 1077 1078 result = QCA::BigInteger("217570540819") -= QCA::BigInteger( 1079 "121955083597720420983384282166693307394185530431368476834980748302158718406063500763434561937200696970170700"); 1080 QCOMPARE(result.toString(), 1081 QStringLiteral("-12195508359772042098338428216669330739418553043136847683498074830215871840606350076343456" 1082 "1937200479399629881")); 1083 QCOMPARE(result, 1084 QCA::BigInteger(QStringLiteral("-1219550835977204209833842821666933073941855304313684768349807483021587184" 1085 "06063500763434561937200479399629881"))); 1086 1087 result = QCA::BigInteger(QStringLiteral("2335319252198456765380587281374076367944")) -= 1088 QCA::BigInteger(QStringLiteral("-4500271")); 1089 QCOMPARE(result, QCA::BigInteger(QStringLiteral("2335319252198456765380587281374080868215"))); 1090 1091 result = QCA::BigInteger( 1092 QStringLiteral("-393694614027544181700073367147249369966344727230221941008713805434207925307052598")) -= 1093 QCA::BigInteger(QStringLiteral("-153972676737062409261153899615588515236137907791841623991260363840680295565313" 1094 "157972489168132345521780658007459602823125797806770")); 1095 QCOMPARE(result.toString(), 1096 QStringLiteral("153972676737062409261153899615588515236137907791447929377232819658980222198165908602522823" 1097 "405115299839649293654168615200490754172")); 1098 QCOMPARE(result, 1099 QCA::BigInteger(QStringLiteral("15397267673706240926115389961558851523613790779144792937723281965898022219" 1100 "8165908602522823405115299839649293654168615200490754172"))); 1101 1102 result = QCA::BigInteger(QStringLiteral("114832549702862263167")) -= 1103 QCA::BigInteger(QStringLiteral("1292186490722995955874527641883028787538667360089228102228659716577356947303995" 1104 "3984775959232814911435097412913078625")); 1105 QCOMPARE(result.toString(), 1106 QStringLiteral("-12921864907229959558745276418830287875386673600892281022286597165773569473039953984775959" 1107 "232814796602547710050815458")); 1108 QCOMPARE(result, 1109 QCA::BigInteger(QStringLiteral("-1292186490722995955874527641883028787538667360089228102228659716577356947" 1110 "3039953984775959232814796602547710050815458"))); 1111 1112 result = 1113 QCA::BigInteger(QStringLiteral("6489502346837936889305337487724547956628371915228387374094443896266362105931065" 1114 "153072983425911767580294076594078932835008494777866083")) -= 1115 QCA::BigInteger(QStringLiteral("1099205476533612407829257935144627350486541654788267826664706620630745291371323" 1116 "154513322608446957760026881954001581")); 1117 QCOMPARE(result.toString(), 1118 QStringLiteral("648950234683793688820613201119093554879911398008376002360790224147809427926635853244223813" 1119 "4540444425780753985631975074981612823864502")); 1120 QCOMPARE(result, 1121 QCA::BigInteger(QStringLiteral("64895023468379368882061320111909355487991139800837600236079022414780942792" 1122 "66358532442238134540444425780753985631975074981612823864502"))); 1123 1124 result = 1125 QCA::BigInteger(QStringLiteral("1699911441239587542538013131736629773378508702733583789516405216010771529944743" 1126 "40806917796870911557233689087716056557")) -= 1127 QCA::BigInteger(QStringLiteral("-15409167")); 1128 QCOMPARE(result.toString(), 1129 QStringLiteral("169991144123958754253801313173662977337850870273358378951640521601077152994474340806917796" 1130 "870911557233689087731465724")); 1131 QCOMPARE(result, 1132 QCA::BigInteger(QStringLiteral("16999114412395875425380131317366297733785087027335837895164052160107715299" 1133 "4474340806917796870911557233689087731465724"))); 1134 } 1135 1136 QTEST_MAIN(BigIntUnitTest) 1137 1138 #include "bigintunittest.moc"