Anonim / 2 years, 6 months ago | Download | Plaintext | Odpowiedz |

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
using System;

public class BigInteger
{
    private uint[] data;
    public int dataLength;
    private const int maxLength = 70;
    public static readonly int[] primesBelow2000 = new int[] { 
        2, 3, 5, 7, 11, 13, 0x11, 0x13, 0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35, 
        0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59, 0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83, 
        0x89, 0x8b, 0x95, 0x97, 0x9d, 0xa3, 0xa7, 0xad, 0xb3, 0xb5, 0xbf, 0xc1, 0xc5, 0xc7, 0xd3, 0xdf, 
        0xe3, 0xe5, 0xe9, 0xef, 0xf1, 0xfb, 0x101, 0x107, 0x10d, 0x10f, 0x115, 0x119, 0x11b, 0x125, 0x133, 0x137, 
        0x139, 0x13d, 0x14b, 0x151, 0x15b, 0x15d, 0x161, 0x167, 0x16f, 0x175, 0x17b, 0x17f, 0x185, 0x18d, 0x191, 0x199, 
        0x1a3, 0x1a5, 0x1af, 0x1b1, 0x1b7, 0x1bb, 0x1c1, 0x1c9, 0x1cd, 0x1cf, 0x1d3, 0x1df, 0x1e7, 0x1eb, 0x1f3, 0x1f7, 
        0x1fd, 0x209, 0x20b, 0x21d, 0x223, 0x22d, 0x233, 0x239, 0x23b, 0x241, 0x24b, 0x251, 0x257, 0x259, 0x25f, 0x265, 
        0x269, 0x26b, 0x277, 0x281, 0x283, 0x287, 0x28d, 0x293, 0x295, 0x2a1, 0x2a5, 0x2ab, 0x2b3, 0x2bd, 0x2c5, 0x2cf, 
        0x2d7, 0x2dd, 0x2e3, 0x2e7, 0x2ef, 0x2f5, 0x2f9, 0x301, 0x305, 0x313, 0x31d, 0x329, 0x32b, 0x335, 0x337, 0x33b, 
        0x33d, 0x347, 0x355, 0x359, 0x35b, 0x35f, 0x36d, 0x371, 0x373, 0x377, 0x38b, 0x38f, 0x397, 0x3a1, 0x3a9, 0x3ad, 
        0x3b3, 0x3b9, 0x3c7, 0x3cb, 0x3d1, 0x3d7, 0x3df, 0x3e5, 0x3f1, 0x3f5, 0x3fb, 0x3fd, 0x407, 0x409, 0x40f, 0x419, 
        0x41b, 0x425, 0x427, 0x42d, 0x43f, 0x443, 0x445, 0x449, 0x44f, 0x455, 0x45d, 0x463, 0x469, 0x47f, 0x481, 0x48b, 
        0x493, 0x49d, 0x4a3, 0x4a9, 0x4b1, 0x4bd, 0x4c1, 0x4c7, 0x4cd, 0x4cf, 0x4d5, 0x4e1, 0x4eb, 0x4fd, 0x4ff, 0x503, 
        0x509, 0x50b, 0x511, 0x515, 0x517, 0x51b, 0x527, 0x529, 0x52f, 0x551, 0x557, 0x55d, 0x565, 0x577, 0x581, 0x58f, 
        0x593, 0x595, 0x599, 0x59f, 0x5a7, 0x5ab, 0x5ad, 0x5b3, 0x5bf, 0x5c9, 0x5cb, 0x5cf, 0x5d1, 0x5d5, 0x5db, 0x5e7, 
        0x5f3, 0x5fb, 0x607, 0x60d, 0x611, 0x617, 0x61f, 0x623, 0x62b, 0x62f, 0x63d, 0x641, 0x647, 0x649, 0x64d, 0x653, 
        0x655, 0x65b, 0x665, 0x679, 0x67f, 0x683, 0x685, 0x69d, 0x6a1, 0x6a3, 0x6ad, 0x6b9, 0x6bb, 0x6c5, 0x6cd, 0x6d3, 
        0x6d9, 0x6df, 0x6f1, 0x6f7, 0x6fb, 0x6fd, 0x709, 0x713, 0x71f, 0x727, 0x737, 0x745, 0x74b, 0x74f, 0x751, 0x755, 
        0x757, 0x761, 0x76d, 0x773, 0x779, 0x78b, 0x78d, 0x79d, 0x79f, 0x7b5, 0x7bb, 0x7c3, 0x7c9, 0x7cd, 0x7cf
     };

    public BigInteger()
    {
        this.data = new uint[70];
        this.dataLength = 1;
    }

    public BigInteger(BigInteger bi)
    {
        this.data = new uint[70];
        this.dataLength = bi.dataLength;
        for (int i = 0; i < this.dataLength; i++)
        {
            this.data[i] = bi.data[i];
        }
    }

    public BigInteger(long value)
    {
        this.data = new uint[70];
        long num = value;
        this.dataLength = 0;
        while ((value != 0L) && (this.dataLength < 70))
        {
            this.data[this.dataLength] = (uint) (((ulong) value) & 0xffffffffL);
            value = value >> 0x20;
            this.dataLength++;
        }
        if (num > 0L)
        {
            if ((value != 0L) || ((this.data[0x45] & 0x80000000) != 0))
            {
                throw new ArithmeticException("Positive overflow in constructor.");
            }
        }
        else if ((num < 0L) && ((value != -1L) || ((this.data[this.dataLength - 1] & 0x80000000) == 0)))
        {
            throw new ArithmeticException("Negative underflow in constructor.");
        }
        if (this.dataLength == 0)
        {
            this.dataLength = 1;
        }
    }

    public BigInteger(ulong value)
    {
        this.data = new uint[70];
        this.dataLength = 0;
        while ((value != 0L) && (this.dataLength < 70))
        {
            this.data[this.dataLength] = (uint) (value & 0xffffffffL);
            value = value >> 0x20;
            this.dataLength++;
        }
        if ((value != 0L) || ((this.data[0x45] & 0x80000000) != 0))
        {
            throw new ArithmeticException("Positive overflow in constructor.");
        }
        if (this.dataLength == 0)
        {
            this.dataLength = 1;
        }
    }

    public BigInteger(byte[] inData)
    {
        this.dataLength = inData.Length >> 2;
        int num = inData.Length & 3;
        if (num != 0)
        {
            this.dataLength++;
        }
        if (this.dataLength > 70)
        {
            throw new ArithmeticException("Byte overflow in constructor.");
        }
        this.data = new uint[70];
        int index = inData.Length - 1;
        for (int i = 0; index >= 3; i++)
        {
            this.data[i] = (uint) ((((inData[index - 3] << 0x18) + (inData[index - 2] << 0x10)) + (inData[index - 1] << 8)) + inData[index]);
            index -= 4;
        }
        switch (num)
        {
            case 1:
                this.data[this.dataLength - 1] = inData[0];
                break;

            case 2:
                this.data[this.dataLength - 1] = (uint) ((inData[0] << 8) + inData[1]);
                break;

            case 3:
                this.data[this.dataLength - 1] = (uint) (((inData[0] << 0x10) + (inData[1] << 8)) + inData[2]);
                break;
        }
        while ((this.dataLength > 1) && (this.data[this.dataLength - 1] == 0))
        {
            this.dataLength--;
        }
    }

    public BigInteger(uint[] inData)
    {
        this.dataLength = inData.Length;
        if (this.dataLength > 70)
        {
            throw new ArithmeticException("Byte overflow in constructor.");
        }
        this.data = new uint[70];
        int index = this.dataLength - 1;
        for (int i = 0; index >= 0; i++)
        {
            this.data[i] = inData[index];
            index--;
        }
        while ((this.dataLength > 1) && (this.data[this.dataLength - 1] == 0))
        {
            this.dataLength--;
        }
    }

    public BigInteger(byte[] inData, int inLen)
    {
        this.dataLength = inLen >> 2;
        int num = inLen & 3;
        if (num != 0)
        {
            this.dataLength++;
        }
        if ((this.dataLength > 70) || (inLen > inData.Length))
        {
            throw new ArithmeticException("Byte overflow in constructor.");
        }
        this.data = new uint[70];
        int index = inLen - 1;
        for (int i = 0; index >= 3; i++)
        {
            this.data[i] = (uint) ((((inData[index - 3] << 0x18) + (inData[index - 2] << 0x10)) + (inData[index - 1] << 8)) + inData[index]);
            index -= 4;
        }
        switch (num)
        {
            case 1:
                this.data[this.dataLength - 1] = inData[0];
                break;

            case 2:
                this.data[this.dataLength - 1] = (uint) ((inData[0] << 8) + inData[1]);
                break;

            case 3:
                this.data[this.dataLength - 1] = (uint) (((inData[0] << 0x10) + (inData[1] << 8)) + inData[2]);
                break;
        }
        if (this.dataLength == 0)
        {
            this.dataLength = 1;
        }
        while ((this.dataLength > 1) && (this.data[this.dataLength - 1] == 0))
        {
            this.dataLength--;
        }
    }

    public BigInteger(string value, int radix)
    {
        BigInteger integer = new BigInteger(1L);
        BigInteger integer2 = new BigInteger();
        value = value.ToUpper().Trim();
        int num = 0;
        if (value[0] == '-')
        {
            num = 1;
        }
        for (int i = value.Length - 1; i >= num; i--)
        {
            int num3 = value[i];
            if ((num3 >= 0x30) && (num3 <= 0x39))
            {
                num3 -= 0x30;
            }
            else if ((num3 >= 0x41) && (num3 <= 90))
            {
                num3 = (num3 - 0x41) + 10;
            }
            else
            {
                num3 = 0x98967f;
            }
            if (num3 >= radix)
            {
                throw new ArithmeticException("Invalid string in constructor.");
            }
            if (value[0] == '-')
            {
                num3 = -num3;
            }
            integer2 += integer * num3;
            if ((i - 1) >= num)
            {
                integer *= radix;
            }
        }
        if (value[0] == '-')
        {
            if ((integer2.data[0x45] & 0x80000000) == 0)
            {
                throw new ArithmeticException("Negative underflow in constructor.");
            }
        }
        else if ((integer2.data[0x45] & 0x80000000) != 0)
        {
            throw new ArithmeticException("Positive overflow in constructor.");
        }
        this.data = new uint[70];
        for (int j = 0; j < integer2.dataLength; j++)
        {
            this.data[j] = integer2.data[j];
        }
        this.dataLength = integer2.dataLength;
    }

    public BigInteger abs()
    {
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            return -this;
        }
        return new BigInteger(this);
    }

    private BigInteger BarrettReduction(BigInteger x, BigInteger n, BigInteger constant)
    {
        int dataLength = n.dataLength;
        int index = dataLength + 1;
        int num3 = dataLength - 1;
        BigInteger integer = new BigInteger();
        int num4 = num3;
        for (int i = 0; num4 < x.dataLength; i++)
        {
            integer.data[i] = x.data[num4];
            num4++;
        }
        integer.dataLength = x.dataLength - num3;
        if (integer.dataLength <= 0)
        {
            integer.dataLength = 1;
        }
        BigInteger integer2 = integer * constant;
        BigInteger integer3 = new BigInteger();
        int num6 = index;
        for (int j = 0; num6 < integer2.dataLength; j++)
        {
            integer3.data[j] = integer2.data[num6];
            num6++;
        }
        integer3.dataLength = integer2.dataLength - index;
        if (integer3.dataLength <= 0)
        {
            integer3.dataLength = 1;
        }
        BigInteger integer4 = new BigInteger();
        int num8 = (x.dataLength > index) ? index : x.dataLength;
        for (int k = 0; k < num8; k++)
        {
            integer4.data[k] = x.data[k];
        }
        integer4.dataLength = num8;
        BigInteger integer5 = new BigInteger();
        for (int m = 0; m < integer3.dataLength; m++)
        {
            if (integer3.data[m] != 0)
            {
                ulong num11 = 0L;
                int num12 = m;
                int num13 = 0;
                while ((num13 < n.dataLength) && (num12 < index))
                {
                    ulong num14 = ((integer3.data[m] * n.data[num13]) + integer5.data[num12]) + num11;
                    integer5.data[num12] = (uint) (num14 & 0xffffffffL);
                    num11 = num14 >> 0x20;
                    num13++;
                    num12++;
                }
                if (num12 < index)
                {
                    integer5.data[num12] = (uint) num11;
                }
            }
        }
        integer5.dataLength = index;
        while ((integer5.dataLength > 1) && (integer5.data[integer5.dataLength - 1] == 0))
        {
            integer5.dataLength--;
        }
        integer4 -= integer5;
        if ((integer4.data[0x45] & 0x80000000) != 0)
        {
            BigInteger integer6 = new BigInteger();
            integer6.data[index] = 1;
            integer6.dataLength = index + 1;
            integer4 += integer6;
        }
        while (integer4 >= n)
        {
            integer4 -= n;
        }
        return integer4;
    }

    public int bitCount()
    {
        while ((this.dataLength > 1) && (this.data[this.dataLength - 1] == 0))
        {
            this.dataLength--;
        }
        uint num = this.data[this.dataLength - 1];
        uint num2 = 0x80000000;
        int num3 = 0x20;
        while ((num3 > 0) && ((num & num2) == 0))
        {
            num3--;
            num2 = num2 >> 1;
        }
        return (num3 + ((this.dataLength - 1) << 5));
    }

    public override bool Equals(object o)
    {
        BigInteger integer = (BigInteger) o;
        if (this.dataLength != integer.dataLength)
        {
            return false;
        }
        for (int i = 0; i < this.dataLength; i++)
        {
            if (this.data[i] != integer.data[i])
            {
                return false;
            }
        }
        return true;
    }

    public bool FermatLittleTest(int confidence)
    {
        BigInteger integer;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        if (integer.dataLength == 1)
        {
            if ((integer.data[0] == 0) || (integer.data[0] == 1))
            {
                return false;
            }
            if ((integer.data[0] == 2) || (integer.data[0] == 3))
            {
                return true;
            }
        }
        if ((integer.data[0] & 1) == 0)
        {
            return false;
        }
        int num = integer.bitCount();
        BigInteger integer2 = new BigInteger();
        BigInteger exp = integer - new BigInteger(1L);
        Random rand = new Random();
        for (int i = 0; i < confidence; i++)
        {
            bool flag = false;
            while (!flag)
            {
                int bits = 0;
                while (bits < 2)
                {
                    bits = (int) (rand.NextDouble() * num);
                }
                integer2.genRandomBits(bits, rand);
                int num4 = integer2.dataLength;
                if ((num4 > 1) || ((num4 == 1) && (integer2.data[0] != 1)))
                {
                    flag = true;
                }
            }
            BigInteger integer4 = integer2.gcd(integer);
            if ((integer4.dataLength == 1) && (integer4.data[0] != 1))
            {
                return false;
            }
            BigInteger integer5 = integer2.modPow(exp, integer);
            int dataLength = integer5.dataLength;
            if ((dataLength > 1) || ((dataLength == 1) && (integer5.data[0] != 1)))
            {
                return false;
            }
        }
        return true;
    }

    public BigInteger gcd(BigInteger bi)
    {
        BigInteger integer;
        BigInteger integer2;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        if ((bi.data[0x45] & 0x80000000) != 0)
        {
            integer2 = -bi;
        }
        else
        {
            integer2 = bi;
        }
        BigInteger integer3 = integer2;
        while ((integer.dataLength > 1) || ((integer.dataLength == 1) && (integer.data[0] != 0)))
        {
            integer3 = integer;
            integer = integer2 % integer;
            integer2 = integer3;
        }
        return integer3;
    }

    public BigInteger genCoPrime(int bits, Random rand)
    {
        bool flag = false;
        BigInteger integer = new BigInteger();
        while (!flag)
        {
            integer.genRandomBits(bits, rand);
            BigInteger integer2 = integer.gcd(this);
            if ((integer2.dataLength == 1) && (integer2.data[0] == 1))
            {
                flag = true;
            }
        }
        return integer;
    }

    public static BigInteger genPseudoPrime(int bits, int confidence, Random rand)
    {
        BigInteger integer = new BigInteger();
        for (bool flag = false; !flag; flag = integer.isProbablePrime(confidence))
        {
            integer.genRandomBits(bits, rand);
            integer.data[0] |= 1;
        }
        return integer;
    }

    public void genRandomBits(int bits, Random rand)
    {
        int num = bits >> 5;
        int num2 = bits & 0x1f;
        if (num2 != 0)
        {
            num++;
        }
        if (num > 70)
        {
            throw new ArithmeticException("Number of required bits > maxLength.");
        }
        for (int i = 0; i < num; i++)
        {
            this.data[i] = (uint) (rand.NextDouble() * 4294967296);
        }
        for (int j = num; j < 70; j++)
        {
            this.data[j] = 0;
        }
        if (num2 != 0)
        {
            uint num5 = ((uint) 1) << (num2 - 1);
            this.data[num - 1] |= num5;
            num5 = ((uint) (-1)) >> (0x20 - num2);
            this.data[num - 1] &= num5;
        }
        else
        {
            this.data[num - 1] |= 0x80000000;
        }
        this.dataLength = num;
        if (this.dataLength == 0)
        {
            this.dataLength = 1;
        }
    }

    public byte[] getBytes()
    {
        int num = this.bitCount();
        int num2 = num >> 3;
        if ((num & 7) != 0)
        {
            num2++;
        }
        byte[] buffer = new byte[num2];
        int index = 0;
        uint num5 = this.data[this.dataLength - 1];
        uint num4 = (num5 >> 0x18) & 0xff;
        if (num4 != 0)
        {
            buffer[index++] = (byte) num4;
        }
        num4 = (num5 >> 0x10) & 0xff;
        if (num4 != 0)
        {
            buffer[index++] = (byte) num4;
        }
        num4 = (num5 >> 8) & 0xff;
        if (num4 != 0)
        {
            buffer[index++] = (byte) num4;
        }
        num4 = num5 & 0xff;
        if (num4 != 0)
        {
            buffer[index++] = (byte) num4;
        }
        int num6 = this.dataLength - 2;
        while (num6 >= 0)
        {
            num5 = this.data[num6];
            buffer[index + 3] = (byte) (num5 & 0xff);
            num5 = num5 >> 8;
            buffer[index + 2] = (byte) (num5 & 0xff);
            num5 = num5 >> 8;
            buffer[index + 1] = (byte) (num5 & 0xff);
            num5 = num5 >> 8;
            buffer[index] = (byte) (num5 & 0xff);
            num6--;
            index += 4;
        }
        return buffer;
    }

    public override int GetHashCode()
    {
        return this.ToString().GetHashCode();
    }

    public int IntValue()
    {
        return (int) this.data[0];
    }

    public bool isProbablePrime()
    {
        BigInteger integer;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        if (integer.dataLength == 1)
        {
            if ((integer.data[0] == 0) || (integer.data[0] == 1))
            {
                return false;
            }
            if ((integer.data[0] == 2) || (integer.data[0] == 3))
            {
                return true;
            }
        }
        if ((integer.data[0] & 1) == 0)
        {
            return false;
        }
        for (int i = 0; i < primesBelow2000.Length; i++)
        {
            BigInteger integer2 = primesBelow2000[i];
            if (integer2 >= integer)
            {
                break;
            }
            BigInteger integer3 = integer % integer2;
            if (integer3.IntValue() == 0)
            {
                return false;
            }
        }
        BigInteger integer4 = integer - new BigInteger(1L);
        int num2 = 0;
        for (int j = 0; j < integer4.dataLength; j++)
        {
            uint num4 = 1;
            for (int m = 0; m < 0x20; m++)
            {
                if ((integer4.data[j] & num4) != 0)
                {
                    j = integer4.dataLength;
                    break;
                }
                num4 = num4 << 1;
                num2++;
            }
        }
        BigInteger exp = integer4 >> num2;
        integer.bitCount();
        BigInteger integer7 = 2.modPow(exp, integer);
        bool flag = false;
        if ((integer7.dataLength == 1) && (integer7.data[0] == 1))
        {
            flag = true;
        }
        for (int k = 0; !flag && (k < num2); k++)
        {
            if (integer7 == integer4)
            {
                flag = true;
                break;
            }
            integer7 = (integer7 * integer7) % integer;
        }
        if (flag)
        {
            flag = this.LucasStrongTestHelper(integer);
        }
        return flag;
    }

    public bool isProbablePrime(int confidence)
    {
        BigInteger integer;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        for (int i = 0; i < primesBelow2000.Length; i++)
        {
            BigInteger integer2 = primesBelow2000[i];
            if (integer2 >= integer)
            {
                break;
            }
            BigInteger integer3 = integer % integer2;
            if (integer3.IntValue() == 0)
            {
                return false;
            }
        }
        return integer.RabinMillerTest(confidence);
    }

    public static int Jacobi(BigInteger a, BigInteger b)
    {
        if ((b.data[0] & 1) == 0)
        {
            throw new ArgumentException("Jacobi defined only for odd integers.");
        }
        if (a >= b)
        {
            a = a % b;
        }
        if ((a.dataLength == 1) && (a.data[0] == 0))
        {
            return 0;
        }
        if ((a.dataLength == 1) && (a.data[0] == 1))
        {
            return 1;
        }
        if (a < 0)
        {
            if (((b - 1).data[0] & 2) == 0)
            {
                return Jacobi(-a, b);
            }
            return -Jacobi(-a, b);
        }
        int num = 0;
        for (int i = 0; i < a.dataLength; i++)
        {
            uint num3 = 1;
            for (int j = 0; j < 0x20; j++)
            {
                if ((a.data[i] & num3) != 0)
                {
                    i = a.dataLength;
                    break;
                }
                num3 = num3 << 1;
                num++;
            }
        }
        BigInteger integer = a >> num;
        int num5 = 1;
        if (((num & 1) != 0) && (((b.data[0] & 7) == 3) || ((b.data[0] & 7) == 5)))
        {
            num5 = -1;
        }
        if (((b.data[0] & 3) == 3) && ((integer.data[0] & 3) == 3))
        {
            num5 = -num5;
        }
        if ((integer.dataLength == 1) && (integer.data[0] == 1))
        {
            return num5;
        }
        return (num5 * Jacobi(b % integer, integer));
    }

    public long LongValue()
    {
        long num = 0L;
        num = this.data[0];
        try
        {
            num |= this.data[1] << 0x20;
        }
        catch (Exception)
        {
            if ((this.data[0] & 0x80000000) != 0)
            {
                num = this.data[0];
            }
        }
        return num;
    }

    public static BigInteger[] LucasSequence(BigInteger P, BigInteger Q, BigInteger k, BigInteger n)
    {
        if ((k.dataLength == 1) && (k.data[0] == 0))
        {
            return new BigInteger[] { 0, (2 % n), (1 % n) };
        }
        BigInteger constant = new BigInteger();
        int index = n.dataLength << 1;
        constant.data[index] = 1;
        constant.dataLength = index + 1;
        constant /= n;
        int s = 0;
        for (int i = 0; i < k.dataLength; i++)
        {
            uint num4 = 1;
            for (int j = 0; j < 0x20; j++)
            {
                if ((k.data[i] & num4) != 0)
                {
                    i = k.dataLength;
                    break;
                }
                num4 = num4 << 1;
                s++;
            }
        }
        BigInteger integer2 = k >> s;
        return LucasSequenceHelper(P, Q, integer2, n, constant, s);
    }

    private static BigInteger[] LucasSequenceHelper(BigInteger P, BigInteger Q, BigInteger k, BigInteger n, BigInteger constant, int s)
    {
        BigInteger[] integerArray = new BigInteger[3];
        if ((k.data[0] & 1) == 0)
        {
            throw new ArgumentException("Argument k must be odd.");
        }
        int num = k.bitCount();
        uint num2 = ((uint) 1) << ((num & 0x1f) - 1);
        BigInteger integer = 2 % n;
        BigInteger integer2 = 1 % n;
        BigInteger integer3 = P % n;
        BigInteger integer4 = integer2;
        bool flag = true;
        for (int i = k.dataLength - 1; i >= 0; i--)
        {
            while (num2 != 0)
            {
                if ((i == 0) && (num2 == 1))
                {
                    break;
                }
                if ((k.data[i] & num2) != 0)
                {
                    integer4 = (integer4 * integer3) % n;
                    integer = ((integer * integer3) - (P * integer2)) % n;
                    integer3 = (n.BarrettReduction(integer3 * integer3, n, constant) - ((integer2 * Q) << 1)) % n;
                    if (flag)
                    {
                        flag = false;
                    }
                    else
                    {
                        integer2 = n.BarrettReduction(integer2 * integer2, n, constant);
                    }
                    integer2 = (integer2 * Q) % n;
                }
                else
                {
                    integer4 = ((integer4 * integer) - integer2) % n;
                    integer3 = ((integer * integer3) - (P * integer2)) % n;
                    integer = (n.BarrettReduction(integer * integer, n, constant) - (integer2 << 1)) % n;
                    if (flag)
                    {
                        integer2 = Q % n;
                        flag = false;
                    }
                    else
                    {
                        integer2 = n.BarrettReduction(integer2 * integer2, n, constant);
                    }
                }
                num2 = num2 >> 1;
            }
            num2 = 0x80000000;
        }
        integer4 = ((integer4 * integer) - integer2) % n;
        integer = ((integer * integer3) - (P * integer2)) % n;
        if (flag)
        {
            flag = false;
        }
        else
        {
            integer2 = n.BarrettReduction(integer2 * integer2, n, constant);
        }
        integer2 = (integer2 * Q) % n;
        for (int j = 0; j < s; j++)
        {
            integer4 = (integer4 * integer) % n;
            integer = ((integer * integer) - (integer2 << 1)) % n;
            if (flag)
            {
                integer2 = Q % n;
                flag = false;
            }
            else
            {
                integer2 = n.BarrettReduction(integer2 * integer2, n, constant);
            }
        }
        integerArray[0] = integer4;
        integerArray[1] = integer;
        integerArray[2] = integer2;
        return integerArray;
    }

    public bool LucasStrongTest()
    {
        BigInteger integer;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        if (integer.dataLength == 1)
        {
            if ((integer.data[0] == 0) || (integer.data[0] == 1))
            {
                return false;
            }
            if ((integer.data[0] == 2) || (integer.data[0] == 3))
            {
                return true;
            }
        }
        if ((integer.data[0] & 1) == 0)
        {
            return false;
        }
        return this.LucasStrongTestHelper(integer);
    }

    private bool LucasStrongTestHelper(BigInteger thisVal)
    {
        long a = 5L;
        long num2 = -1L;
        long num3 = 0L;
        bool flag = false;
        while (!flag)
        {
            int num4 = Jacobi(a, thisVal);
            if (num4 == -1)
            {
                flag = true;
            }
            else
            {
                if ((num4 == 0) && (Math.Abs(a) < thisVal))
                {
                    return false;
                }
                if (num3 == 20L)
                {
                    BigInteger integer = thisVal.sqrt();
                    if ((integer * integer) == thisVal)
                    {
                        return false;
                    }
                }
                a = (Math.Abs(a) + 2L) * num2;
                num2 = -num2;
            }
            num3 += 1L;
        }
        long q = (1L - a) >> 2;
        BigInteger integer2 = thisVal + 1;
        int num6 = 0;
        for (int i = 0; i < integer2.dataLength; i++)
        {
            uint num8 = 1;
            for (int m = 0; m < 0x20; m++)
            {
                if ((integer2.data[i] & num8) != 0)
                {
                    i = integer2.dataLength;
                    break;
                }
                num8 = num8 << 1;
                num6++;
            }
        }
        BigInteger k = integer2 >> num6;
        BigInteger constant = new BigInteger();
        int index = thisVal.dataLength << 1;
        constant.data[index] = 1;
        constant.dataLength = index + 1;
        constant /= thisVal;
        BigInteger[] integerArray = LucasSequenceHelper(1, q, k, thisVal, constant, 0);
        bool flag2 = false;
        if (((integerArray[0].dataLength == 1) && (integerArray[0].data[0] == 0)) || ((integerArray[1].dataLength == 1) && (integerArray[1].data[0] == 0)))
        {
            flag2 = true;
        }
        for (int j = 1; j < num6; j++)
        {
            if (!flag2)
            {
                integerArray[1] = thisVal.BarrettReduction(integerArray[1] * integerArray[1], thisVal, constant);
                integerArray[1] = (integerArray[1] - (integerArray[2] << 1)) % thisVal;
                if ((integerArray[1].dataLength == 1) && (integerArray[1].data[0] == 0))
                {
                    flag2 = true;
                }
            }
            integerArray[2] = thisVal.BarrettReduction(integerArray[2] * integerArray[2], thisVal, constant);
        }
        if (flag2)
        {
            BigInteger integer5 = thisVal.gcd(q);
            if ((integer5.dataLength != 1) || (integer5.data[0] != 1))
            {
                return flag2;
            }
            if ((integerArray[2].data[0x45] & 0x80000000) != 0)
            {
                integerArray[2] += thisVal;
            }
            BigInteger integer6 = (q * Jacobi(q, thisVal)) % thisVal;
            if ((integer6.data[0x45] & 0x80000000) != 0)
            {
                integer6 += thisVal;
            }
            if (integerArray[2] != integer6)
            {
                flag2 = false;
            }
        }
        return flag2;
    }

    public BigInteger max(BigInteger bi)
    {
        if (this > bi)
        {
            return new BigInteger(this);
        }
        return new BigInteger(bi);
    }

    public BigInteger min(BigInteger bi)
    {
        if (this < bi)
        {
            return new BigInteger(this);
        }
        return new BigInteger(bi);
    }

    public BigInteger modInverse(BigInteger modulus)
    {
        BigInteger[] integerArray = new BigInteger[] { 0, 1 };
        BigInteger[] integerArray2 = new BigInteger[2];
        BigInteger[] integerArray3 = new BigInteger[] { 0, 0 };
        int num = 0;
        BigInteger integer = modulus;
        BigInteger integer2 = this;
        while ((integer2.dataLength > 1) || ((integer2.dataLength == 1) && (integer2.data[0] != 0)))
        {
            BigInteger outQuotient = new BigInteger();
            BigInteger outRemainder = new BigInteger();
            if (num > 1)
            {
                BigInteger integer5 = (integerArray[0] - (integerArray[1] * integerArray2[0])) % modulus;
                integerArray[0] = integerArray[1];
                integerArray[1] = integer5;
            }
            if (integer2.dataLength == 1)
            {
                singleByteDivide(integer, integer2, outQuotient, outRemainder);
            }
            else
            {
                multiByteDivide(integer, integer2, outQuotient, outRemainder);
            }
            integerArray2[0] = integerArray2[1];
            integerArray3[0] = integerArray3[1];
            integerArray2[1] = outQuotient;
            integerArray3[1] = outRemainder;
            integer = integer2;
            integer2 = outRemainder;
            num++;
        }
        if ((integerArray3[0].dataLength > 1) || ((integerArray3[0].dataLength == 1) && (integerArray3[0].data[0] != 1)))
        {
            throw new ArithmeticException("No inverse!");
        }
        BigInteger integer6 = (integerArray[0] - (integerArray[1] * integerArray2[0])) % modulus;
        if ((integer6.data[0x45] & 0x80000000) != 0)
        {
            integer6 += modulus;
        }
        return integer6;
    }

    public BigInteger modPow(BigInteger exp, BigInteger n)
    {
        BigInteger integer2;
        if ((exp.data[0x45] & 0x80000000) != 0)
        {
            throw new ArithmeticException("Positive exponents only.");
        }
        BigInteger integer = 1;
        bool flag = false;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer2 = -this % n;
            flag = true;
        }
        else
        {
            integer2 = this % n;
        }
        if ((n.data[0x45] & 0x80000000) != 0)
        {
            n = -n;
        }
        BigInteger constant = new BigInteger();
        int index = n.dataLength << 1;
        constant.data[index] = 1;
        constant.dataLength = index + 1;
        constant /= n;
        int num2 = exp.bitCount();
        int num3 = 0;
        for (int i = 0; i < exp.dataLength; i++)
        {
            uint num5 = 1;
            for (int j = 0; j < 0x20; j++)
            {
                if ((exp.data[i] & num5) != 0)
                {
                    integer = this.BarrettReduction(integer * integer2, n, constant);
                }
                num5 = num5 << 1;
                integer2 = this.BarrettReduction(integer2 * integer2, n, constant);
                if ((integer2.dataLength == 1) && (integer2.data[0] == 1))
                {
                    if (flag && ((exp.data[0] & 1) != 0))
                    {
                        return -integer;
                    }
                    return integer;
                }
                num3++;
                if (num3 == num2)
                {
                    break;
                }
            }
        }
        if (flag && ((exp.data[0] & 1) != 0))
        {
            return -integer;
        }
        return integer;
    }

    private static void multiByteDivide(BigInteger bi1, BigInteger bi2, BigInteger outQuotient, BigInteger outRemainder)
    {
        uint[] numArray = new uint[70];
        int num = bi1.dataLength + 1;
        uint[] buffer = new uint[num];
        uint num2 = 0x80000000;
        uint num3 = bi2.data[bi2.dataLength - 1];
        int shiftVal = 0;
        int num5 = 0;
        while ((num2 != 0) && ((num3 & num2) == 0))
        {
            shiftVal++;
            num2 = num2 >> 1;
        }
        for (int i = 0; i < bi1.dataLength; i++)
        {
            buffer[i] = bi1.data[i];
        }
        shiftLeft(buffer, shiftVal);
        bi2 = bi2 << shiftVal;
        int num7 = num - bi2.dataLength;
        int index = num - 1;
        ulong num9 = bi2.data[bi2.dataLength - 1];
        ulong num10 = bi2.data[bi2.dataLength - 2];
        int num11 = bi2.dataLength + 1;
        uint[] inData = new uint[num11];
        while (num7 > 0)
        {
            ulong num12 = (buffer[index] << 0x20) + buffer[index - 1];
            ulong num13 = num12 / num9;
            ulong num14 = num12 % num9;
            bool flag = false;
            while (!flag)
            {
                flag = true;
                if ((num13 == 0x100000000L) || ((num13 * num10) > ((num14 << 0x20) + buffer[index - 2])))
                {
                    num13 -= (ulong) 1L;
                    num14 += num9;
                    if (num14 < 0x100000000L)
                    {
                        flag = false;
                    }
                }
            }
            for (int j = 0; j < num11; j++)
            {
                inData[j] = buffer[index - j];
            }
            BigInteger integer = new BigInteger(inData);
            BigInteger integer2 = bi2 * num13;
            while (integer2 > integer)
            {
                num13 -= (ulong) 1L;
                integer2 -= bi2;
            }
            BigInteger integer3 = integer - integer2;
            for (int k = 0; k < num11; k++)
            {
                buffer[index - k] = integer3.data[bi2.dataLength - k];
            }
            numArray[num5++] = (uint) num13;
            index--;
            num7--;
        }
        outQuotient.dataLength = num5;
        int num17 = 0;
        int num18 = outQuotient.dataLength - 1;
        while (num18 >= 0)
        {
            outQuotient.data[num17] = numArray[num18];
            num18--;
            num17++;
        }
        while (num17 < 70)
        {
            outQuotient.data[num17] = 0;
            num17++;
        }
        while ((outQuotient.dataLength > 1) && (outQuotient.data[outQuotient.dataLength - 1] == 0))
        {
            outQuotient.dataLength--;
        }
        if (outQuotient.dataLength == 0)
        {
            outQuotient.dataLength = 1;
        }
        outRemainder.dataLength = shiftRight(buffer, shiftVal);
        num17 = 0;
        while (num17 < outRemainder.dataLength)
        {
            outRemainder.data[num17] = buffer[num17];
            num17++;
        }
        while (num17 < 70)
        {
            outRemainder.data[num17] = 0;
            num17++;
        }
    }

    public static BigInteger operator +(BigInteger bi1, BigInteger bi2)
    {
        BigInteger integer = new BigInteger {
            dataLength = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength
        };
        long num = 0L;
        for (int i = 0; i < integer.dataLength; i++)
        {
            long num3 = (bi1.data[i] + bi2.data[i]) + num;
            num = num3 >> 0x20;
            integer.data[i] = (uint) (((ulong) num3) & 0xffffffffL);
        }
        if ((num != 0L) && (integer.dataLength < 70))
        {
            integer.data[integer.dataLength] = (uint) num;
            integer.dataLength++;
        }
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        int index = 0x45;
        if (((bi1.data[index] & 0x80000000) == (bi2.data[index] & 0x80000000)) && ((integer.data[index] & 0x80000000) != (bi1.data[index] & 0x80000000)))
        {
            throw new ArithmeticException();
        }
        return integer;
    }

    public static BigInteger operator &(BigInteger bi1, BigInteger bi2)
    {
        BigInteger integer = new BigInteger();
        int num = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength;
        for (int i = 0; i < num; i++)
        {
            integer.data[i] = bi1.data[i] & bi2.data[i];
        }
        integer.dataLength = 70;
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        return integer;
    }

    public static BigInteger operator |(BigInteger bi1, BigInteger bi2)
    {
        BigInteger integer = new BigInteger();
        int num = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength;
        for (int i = 0; i < num; i++)
        {
            integer.data[i] = bi1.data[i] | bi2.data[i];
        }
        integer.dataLength = 70;
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        return integer;
    }

    public static BigInteger operator --(BigInteger bi1)
    {
        BigInteger integer = new BigInteger(bi1);
        bool flag = true;
        int index = 0;
        while (flag && (index < 70))
        {
            long num = integer.data[index];
            num -= 1L;
            integer.data[index] = (uint) (((ulong) num) & 0xffffffffL);
            if (num >= 0L)
            {
                flag = false;
            }
            index++;
        }
        if (index > integer.dataLength)
        {
            integer.dataLength = index;
        }
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        int num3 = 0x45;
        if (((bi1.data[num3] & 0x80000000) != 0) && ((integer.data[num3] & 0x80000000) != (bi1.data[num3] & 0x80000000)))
        {
            throw new ArithmeticException("Underflow in --.");
        }
        return integer;
    }

    public static BigInteger operator /(BigInteger bi1, BigInteger bi2)
    {
        BigInteger outQuotient = new BigInteger();
        BigInteger outRemainder = new BigInteger();
        int index = 0x45;
        bool flag = false;
        bool flag2 = false;
        if ((bi1.data[index] & 0x80000000) != 0)
        {
            bi1 = -bi1;
            flag2 = true;
        }
        if ((bi2.data[index] & 0x80000000) != 0)
        {
            bi2 = -bi2;
            flag = true;
        }
        if (bi1 >= bi2)
        {
            if (bi2.dataLength == 1)
            {
                singleByteDivide(bi1, bi2, outQuotient, outRemainder);
            }
            else
            {
                multiByteDivide(bi1, bi2, outQuotient, outRemainder);
            }
            if (flag2 != flag)
            {
                return -outQuotient;
            }
        }
        return outQuotient;
    }

    public static bool operator ==(BigInteger bi1, BigInteger bi2)
    {
        return bi1.Equals(bi2);
    }

    public static BigInteger operator ^(BigInteger bi1, BigInteger bi2)
    {
        BigInteger integer = new BigInteger();
        int num = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength;
        for (int i = 0; i < num; i++)
        {
            integer.data[i] = bi1.data[i] ^ bi2.data[i];
        }
        integer.dataLength = 70;
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        return integer;
    }

    public static bool operator >(BigInteger bi1, BigInteger bi2)
    {
        int index = 0x45;
        if (((bi1.data[index] & 0x80000000) != 0) && ((bi2.data[index] & 0x80000000) == 0))
        {
            return false;
        }
        if (((bi1.data[index] & 0x80000000) == 0) && ((bi2.data[index] & 0x80000000) != 0))
        {
            return true;
        }
        int num2 = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength;
        index = num2 - 1;
        while ((index >= 0) && (bi1.data[index] == bi2.data[index]))
        {
            index--;
        }
        if (index < 0)
        {
            return false;
        }
        return (bi1.data[index] > bi2.data[index]);
    }

    public static bool operator >=(BigInteger bi1, BigInteger bi2)
    {
        if (!(bi1 == bi2))
        {
            return (bi1 > bi2);
        }
        return true;
    }

    public static implicit operator BigInteger(int value)
    {
        return new BigInteger((long) value);
    }

    public static implicit operator BigInteger(long value)
    {
        return new BigInteger(value);
    }

    public static implicit operator BigInteger(uint value)
    {
        return new BigInteger((ulong) value);
    }

    public static implicit operator BigInteger(ulong value)
    {
        return new BigInteger(value);
    }

    public static BigInteger operator ++(BigInteger bi1)
    {
        BigInteger integer = new BigInteger(bi1);
        long num2 = 1L;
        int index = 0;
        while ((num2 != 0L) && (index < 70))
        {
            long num = integer.data[index];
            num += 1L;
            integer.data[index] = (uint) (((ulong) num) & 0xffffffffL);
            num2 = num >> 0x20;
            index++;
        }
        if (index <= integer.dataLength)
        {
            while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
            {
                integer.dataLength--;
            }
        }
        else
        {
            integer.dataLength = index;
        }
        int num4 = 0x45;
        if (((bi1.data[num4] & 0x80000000) == 0) && ((integer.data[num4] & 0x80000000) != (bi1.data[num4] & 0x80000000)))
        {
            throw new ArithmeticException("Overflow in ++.");
        }
        return integer;
    }

    public static bool operator !=(BigInteger bi1, BigInteger bi2)
    {
        return !bi1.Equals(bi2);
    }

    public static BigInteger operator <<(BigInteger bi1, int shiftVal)
    {
        BigInteger integer;
        return new BigInteger(bi1) { dataLength = shiftLeft(integer.data, shiftVal) };
    }

    public static bool operator <(BigInteger bi1, BigInteger bi2)
    {
        int index = 0x45;
        if (((bi1.data[index] & 0x80000000) != 0) && ((bi2.data[index] & 0x80000000) == 0))
        {
            return true;
        }
        if (((bi1.data[index] & 0x80000000) == 0) && ((bi2.data[index] & 0x80000000) != 0))
        {
            return false;
        }
        int num2 = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength;
        index = num2 - 1;
        while ((index >= 0) && (bi1.data[index] == bi2.data[index]))
        {
            index--;
        }
        if (index < 0)
        {
            return false;
        }
        return (bi1.data[index] < bi2.data[index]);
    }

    public static bool operator <=(BigInteger bi1, BigInteger bi2)
    {
        if (!(bi1 == bi2))
        {
            return (bi1 < bi2);
        }
        return true;
    }

    public static BigInteger operator %(BigInteger bi1, BigInteger bi2)
    {
        BigInteger outQuotient = new BigInteger();
        BigInteger outRemainder = new BigInteger(bi1);
        int index = 0x45;
        bool flag = false;
        if ((bi1.data[index] & 0x80000000) != 0)
        {
            bi1 = -bi1;
            flag = true;
        }
        if ((bi2.data[index] & 0x80000000) != 0)
        {
            bi2 = -bi2;
        }
        if (bi1 >= bi2)
        {
            if (bi2.dataLength == 1)
            {
                singleByteDivide(bi1, bi2, outQuotient, outRemainder);
            }
            else
            {
                multiByteDivide(bi1, bi2, outQuotient, outRemainder);
            }
            if (flag)
            {
                return -outRemainder;
            }
        }
        return outRemainder;
    }

    public static BigInteger operator *(BigInteger bi1, BigInteger bi2)
    {
        int index = 0x45;
        bool flag = false;
        bool flag2 = false;
        try
        {
            if ((bi1.data[index] & 0x80000000) != 0)
            {
                flag = true;
                bi1 = -bi1;
            }
            if ((bi2.data[index] & 0x80000000) != 0)
            {
                flag2 = true;
                bi2 = -bi2;
            }
        }
        catch (Exception)
        {
        }
        BigInteger integer = new BigInteger();
        try
        {
            for (int i = 0; i < bi1.dataLength; i++)
            {
                if (bi1.data[i] != 0)
                {
                    ulong num3 = 0L;
                    int num4 = 0;
                    for (int j = i; num4 < bi2.dataLength; j++)
                    {
                        ulong num6 = ((bi1.data[i] * bi2.data[num4]) + integer.data[j]) + num3;
                        integer.data[j] = (uint) (num6 & 0xffffffffL);
                        num3 = num6 >> 0x20;
                        num4++;
                    }
                    if (num3 != 0L)
                    {
                        integer.data[i + bi2.dataLength] = (uint) num3;
                    }
                }
            }
        }
        catch (Exception)
        {
            throw new ArithmeticException("Multiplication overflow.");
        }
        integer.dataLength = bi1.dataLength + bi2.dataLength;
        if (integer.dataLength > 70)
        {
            integer.dataLength = 70;
        }
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        if ((integer.data[index] & 0x80000000) != 0)
        {
            if ((flag != flag2) && (integer.data[index] == 0x80000000))
            {
                if (integer.dataLength == 1)
                {
                    return integer;
                }
                bool flag3 = true;
                for (int k = 0; (k < (integer.dataLength - 1)) && flag3; k++)
                {
                    if (integer.data[k] != 0)
                    {
                        flag3 = false;
                    }
                }
                if (flag3)
                {
                    return integer;
                }
            }
            throw new ArithmeticException("Multiplication overflow.");
        }
        if (flag != flag2)
        {
            return -integer;
        }
        return integer;
    }

    public static BigInteger operator ~(BigInteger bi1)
    {
        BigInteger integer = new BigInteger(bi1);
        for (int i = 0; i < 70; i++)
        {
            integer.data[i] = ~bi1.data[i];
        }
        integer.dataLength = 70;
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        return integer;
    }

    public static BigInteger operator >>(BigInteger bi1, int shiftVal)
    {
        BigInteger integer;
        integer = new BigInteger(bi1) {
            dataLength = shiftRight(integer.data, shiftVal)
        };
        if ((bi1.data[0x45] & 0x80000000) != 0)
        {
            for (int i = 0x45; i >= integer.dataLength; i--)
            {
                integer.data[i] = uint.MaxValue;
            }
            uint num2 = 0x80000000;
            for (int j = 0; j < 0x20; j++)
            {
                if ((integer.data[integer.dataLength - 1] & num2) != 0)
                {
                    break;
                }
                integer.data[integer.dataLength - 1] |= num2;
                num2 = num2 >> 1;
            }
            integer.dataLength = 70;
        }
        return integer;
    }

    public static BigInteger operator -(BigInteger bi1, BigInteger bi2)
    {
        BigInteger integer = new BigInteger {
            dataLength = (bi1.dataLength > bi2.dataLength) ? bi1.dataLength : bi2.dataLength
        };
        long num = 0L;
        for (int i = 0; i < integer.dataLength; i++)
        {
            long num3 = (bi1.data[i] - bi2.data[i]) - num;
            integer.data[i] = (uint) (((ulong) num3) & 0xffffffffL);
            if (num3 < 0L)
            {
                num = 1L;
            }
            else
            {
                num = 0L;
            }
        }
        if (num != 0L)
        {
            for (int j = integer.dataLength; j < 70; j++)
            {
                integer.data[j] = uint.MaxValue;
            }
            integer.dataLength = 70;
        }
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        int index = 0x45;
        if (((bi1.data[index] & 0x80000000) != (bi2.data[index] & 0x80000000)) && ((integer.data[index] & 0x80000000) != (bi1.data[index] & 0x80000000)))
        {
            throw new ArithmeticException();
        }
        return integer;
    }

    public static BigInteger operator -(BigInteger bi1)
    {
        if ((bi1.dataLength == 1) && (bi1.data[0] == 0))
        {
            return new BigInteger();
        }
        BigInteger integer = new BigInteger(bi1);
        for (int i = 0; i < 70; i++)
        {
            integer.data[i] = ~bi1.data[i];
        }
        long num3 = 1L;
        for (int j = 0; (num3 != 0L) && (j < 70); j++)
        {
            long num2 = integer.data[j];
            num2 += 1L;
            integer.data[j] = (uint) (((ulong) num2) & 0xffffffffL);
            num3 = num2 >> 0x20;
        }
        if ((bi1.data[0x45] & 0x80000000) == (integer.data[0x45] & 0x80000000))
        {
            throw new ArithmeticException("Overflow in negation.\n");
        }
        integer.dataLength = 70;
        while ((integer.dataLength > 1) && (integer.data[integer.dataLength - 1] == 0))
        {
            integer.dataLength--;
        }
        return integer;
    }

    public bool RabinMillerTest(int confidence)
    {
        BigInteger integer;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        if (integer.dataLength == 1)
        {
            if ((integer.data[0] == 0) || (integer.data[0] == 1))
            {
                return false;
            }
            if ((integer.data[0] == 2) || (integer.data[0] == 3))
            {
                return true;
            }
        }
        if ((integer.data[0] & 1) == 0)
        {
            return false;
        }
        BigInteger integer2 = integer - new BigInteger(1L);
        int num = 0;
        for (int i = 0; i < integer2.dataLength; i++)
        {
            uint num3 = 1;
            for (int k = 0; k < 0x20; k++)
            {
                if ((integer2.data[i] & num3) != 0)
                {
                    i = integer2.dataLength;
                    break;
                }
                num3 = num3 << 1;
                num++;
            }
        }
        BigInteger exp = integer2 >> num;
        int num5 = integer.bitCount();
        BigInteger integer4 = new BigInteger();
        Random rand = new Random();
        for (int j = 0; j < confidence; j++)
        {
            bool flag = false;
            while (!flag)
            {
                int bits = 0;
                while (bits < 2)
                {
                    bits = (int) (rand.NextDouble() * num5);
                }
                integer4.genRandomBits(bits, rand);
                int dataLength = integer4.dataLength;
                if ((dataLength > 1) || ((dataLength == 1) && (integer4.data[0] != 1)))
                {
                    flag = true;
                }
            }
            BigInteger integer5 = integer4.gcd(integer);
            if ((integer5.dataLength == 1) && (integer5.data[0] != 1))
            {
                return false;
            }
            BigInteger integer6 = integer4.modPow(exp, integer);
            bool flag2 = false;
            if ((integer6.dataLength == 1) && (integer6.data[0] == 1))
            {
                flag2 = true;
            }
            for (int m = 0; !flag2 && (m < num); m++)
            {
                if (integer6 == integer2)
                {
                    flag2 = true;
                    break;
                }
                integer6 = (integer6 * integer6) % integer;
            }
            if (!flag2)
            {
                return false;
            }
        }
        return true;
    }

    public void setBit(uint bitNum)
    {
        uint index = bitNum >> 5;
        byte num2 = (byte) (bitNum & 0x1f);
        uint num3 = ((uint) 1) << num2;
        this.data[index] |= num3;
        if (index >= this.dataLength)
        {
            this.dataLength = ((int) index) + 1;
        }
    }

    private static int shiftLeft(uint[] buffer, int shiftVal)
    {
        int num = 0x20;
        int length = buffer.Length;
        while ((length > 1) && (buffer[length - 1] == 0))
        {
            length--;
        }
        for (int i = shiftVal; i > 0; i -= num)
        {
            if (i < num)
            {
                num = i;
            }
            ulong num4 = 0L;
            for (int j = 0; j < length; j++)
            {
                ulong num6 = buffer[j] << num;
                num6 |= num4;
                buffer[j] = (uint) (num6 & 0xffffffffL);
                num4 = num6 >> 0x20;
            }
            if ((num4 != 0L) && ((length + 1) <= buffer.Length))
            {
                buffer[length] = (uint) num4;
                length++;
            }
        }
        return length;
    }

    private static int shiftRight(uint[] buffer, int shiftVal)
    {
        int num = 0x20;
        int num2 = 0;
        int length = buffer.Length;
        while ((length > 1) && (buffer[length - 1] == 0))
        {
            length--;
        }
        for (int i = shiftVal; i > 0; i -= num)
        {
            if (i < num)
            {
                num = i;
                num2 = 0x20 - num;
            }
            ulong num5 = 0L;
            for (int j = length - 1; j >= 0; j--)
            {
                ulong num7 = buffer[j] >> num;
                num7 |= num5;
                num5 = buffer[j] << num2;
                buffer[j] = (uint) num7;
            }
        }
        while ((length > 1) && (buffer[length - 1] == 0))
        {
            length--;
        }
        return length;
    }

    private static void singleByteDivide(BigInteger bi1, BigInteger bi2, BigInteger outQuotient, BigInteger outRemainder)
    {
        uint[] numArray = new uint[70];
        int num = 0;
        for (int i = 0; i < 70; i++)
        {
            outRemainder.data[i] = bi1.data[i];
        }
        outRemainder.dataLength = bi1.dataLength;
        while ((outRemainder.dataLength > 1) && (outRemainder.data[outRemainder.dataLength - 1] == 0))
        {
            outRemainder.dataLength--;
        }
        ulong num3 = bi2.data[0];
        int index = outRemainder.dataLength - 1;
        ulong num5 = outRemainder.data[index];
        if (num5 >= num3)
        {
            ulong num6 = num5 / num3;
            numArray[num++] = (uint) num6;
            outRemainder.data[index] = (uint) (num5 % num3);
        }
        index--;
        while (index >= 0)
        {
            num5 = (outRemainder.data[index + 1] << 0x20) + outRemainder.data[index];
            ulong num7 = num5 / num3;
            numArray[num++] = (uint) num7;
            outRemainder.data[index + 1] = 0;
            outRemainder.data[index--] = (uint) (num5 % num3);
        }
        outQuotient.dataLength = num;
        int num8 = 0;
        int num9 = outQuotient.dataLength - 1;
        while (num9 >= 0)
        {
            outQuotient.data[num8] = numArray[num9];
            num9--;
            num8++;
        }
        while (num8 < 70)
        {
            outQuotient.data[num8] = 0;
            num8++;
        }
        while ((outQuotient.dataLength > 1) && (outQuotient.data[outQuotient.dataLength - 1] == 0))
        {
            outQuotient.dataLength--;
        }
        if (outQuotient.dataLength == 0)
        {
            outQuotient.dataLength = 1;
        }
        while ((outRemainder.dataLength > 1) && (outRemainder.data[outRemainder.dataLength - 1] == 0))
        {
            outRemainder.dataLength--;
        }
    }

    public bool SolovayStrassenTest(int confidence)
    {
        BigInteger integer;
        if ((this.data[0x45] & 0x80000000) != 0)
        {
            integer = -this;
        }
        else
        {
            integer = this;
        }
        if (integer.dataLength == 1)
        {
            if ((integer.data[0] == 0) || (integer.data[0] == 1))
            {
                return false;
            }
            if ((integer.data[0] == 2) || (integer.data[0] == 3))
            {
                return true;
            }
        }
        if ((integer.data[0] & 1) == 0)
        {
            return false;
        }
        int num = integer.bitCount();
        BigInteger a = new BigInteger();
        BigInteger integer3 = integer - 1;
        BigInteger exp = integer3 >> 1;
        Random rand = new Random();
        for (int i = 0; i < confidence; i++)
        {
            bool flag = false;
            while (!flag)
            {
                int bits = 0;
                while (bits < 2)
                {
                    bits = (int) (rand.NextDouble() * num);
                }
                a.genRandomBits(bits, rand);
                int dataLength = a.dataLength;
                if ((dataLength > 1) || ((dataLength == 1) && (a.data[0] != 1)))
                {
                    flag = true;
                }
            }
            BigInteger integer5 = a.gcd(integer);
            if ((integer5.dataLength == 1) && (integer5.data[0] != 1))
            {
                return false;
            }
            BigInteger integer6 = a.modPow(exp, integer);
            if (integer6 == integer3)
            {
                integer6 = -1;
            }
            BigInteger integer7 = Jacobi(a, integer);
            if (integer6 != integer7)
            {
                return false;
            }
        }
        return true;
    }

    public BigInteger sqrt()
    {
        uint num4;
        uint num = (uint) this.bitCount();
        if ((num & 1) != 0)
        {
            num = (num >> 1) + 1;
        }
        else
        {
            num = num >> 1;
        }
        uint num2 = num >> 5;
        byte num3 = (byte) (num & 0x1f);
        BigInteger integer = new BigInteger();
        if (num3 == 0)
        {
            num4 = 0x80000000;
        }
        else
        {
            num4 = ((uint) 1) << num3;
            num2++;
        }
        integer.dataLength = (int) num2;
        for (int i = ((int) num2) - 1; i >= 0; i--)
        {
            while (num4 != 0)
            {
                integer.data[i] ^= num4;
                if ((integer * integer) > this)
                {
                    integer.data[i] ^= num4;
                }
                num4 = num4 >> 1;
            }
            num4 = 0x80000000;
        }
        return integer;
    }

    public string ToHexString()
    {
        string str = this.data[this.dataLength - 1].ToString("X");
        for (int i = this.dataLength - 2; i >= 0; i--)
        {
            str = str + this.data[i].ToString("X8");
        }
        return str;
    }

    public override string ToString()
    {
        return this.ToString(10);
    }

    public string ToString(int radix)
    {
        if ((radix < 2) || (radix > 0x24))
        {
            throw new ArgumentException("Radix must be >= 2 and <= 36");
        }
        string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        string str2 = "";
        BigInteger integer = this;
        bool flag = false;
        if ((integer.data[0x45] & 0x80000000) != 0)
        {
            flag = true;
            try
            {
                integer = -integer;
            }
            catch (Exception)
            {
            }
        }
        BigInteger outQuotient = new BigInteger();
        BigInteger outRemainder = new BigInteger();
        BigInteger integer4 = new BigInteger((long) radix);
        if ((integer.dataLength != 1) || (integer.data[0] != 0))
        {
            while ((integer.dataLength > 1) || ((integer.dataLength == 1) && (integer.data[0] != 0)))
            {
                singleByteDivide(integer, integer4, outQuotient, outRemainder);
                if (outRemainder.data[0] < 10)
                {
                    str2 = outRemainder.data[0] + str2;
                }
                else
                {
                    str2 = str[((int) outRemainder.data[0]) - 10] + str2;
                }
                integer = outQuotient;
            }
            if (flag)
            {
                str2 = "-" + str2;
            }
            return str2;
        }
        return "0";
    }

    public void unsetBit(uint bitNum)
    {
        uint index = bitNum >> 5;
        if (index < this.dataLength)
        {
            byte num2 = (byte) (bitNum & 0x1f);
            uint num3 = ((uint) 1) << num2;
            uint num4 = uint.MaxValue ^ num3;
            this.data[index] &= num4;
            if ((this.dataLength > 1) && (this.data[this.dataLength - 1] == 0))
            {
                this.dataLength--;
            }
        }
    }
}