All-in-One WP Migration - Version 6.84

Version Description

Fixed

  • Set the type of backup file during download via HTML attribute
  • Removed Math_BigInteger class which was causing issues with other plugins
Download this release

Release Info

Developer bangelov
Plugin Icon 128x128 All-in-One WP Migration
Version 6.84
Comparing to
See all releases

Code changes from version 6.83 to 6.84

Files changed (137) hide show
  1. all-in-one-wp-migration.php +2 -2
  2. constants.php +7 -2
  3. deprecated.php +1 -1
  4. exceptions.php +1 -1
  5. functions.php +1 -64
  6. lib/controller/class-ai1wm-backups-controller.php +1 -1
  7. lib/controller/class-ai1wm-export-controller.php +1 -1
  8. lib/controller/class-ai1wm-feedback-controller.php +1 -1
  9. lib/controller/class-ai1wm-import-controller.php +1 -1
  10. lib/controller/class-ai1wm-main-controller.php +1 -1
  11. lib/controller/class-ai1wm-report-controller.php +1 -1
  12. lib/controller/class-ai1wm-status-controller.php +1 -1
  13. lib/controller/class-ai1wm-updater-controller.php +1 -1
  14. lib/model/class-ai1wm-backups.php +1 -1
  15. lib/model/class-ai1wm-compatibility.php +1 -1
  16. lib/model/class-ai1wm-deprecated.php +1 -1
  17. lib/model/class-ai1wm-extensions.php +1 -1
  18. lib/model/class-ai1wm-feedback.php +1 -1
  19. lib/model/class-ai1wm-handler.php +1 -1
  20. lib/model/class-ai1wm-log.php +1 -1
  21. lib/model/class-ai1wm-message.php +1 -1
  22. lib/model/class-ai1wm-notification.php +1 -1
  23. lib/model/class-ai1wm-report.php +1 -1
  24. lib/model/class-ai1wm-status.php +1 -1
  25. lib/model/class-ai1wm-template.php +1 -1
  26. lib/model/class-ai1wm-updater.php +1 -1
  27. lib/model/export/class-ai1wm-export-archive.php +1 -1
  28. lib/model/export/class-ai1wm-export-clean.php +1 -1
  29. lib/model/export/class-ai1wm-export-compatibility.php +1 -1
  30. lib/model/export/class-ai1wm-export-config-file.php +1 -1
  31. lib/model/export/class-ai1wm-export-config.php +1 -1
  32. lib/model/export/class-ai1wm-export-content.php +1 -1
  33. lib/model/export/class-ai1wm-export-database-file.php +1 -1
  34. lib/model/export/class-ai1wm-export-database.php +1 -1
  35. lib/model/export/class-ai1wm-export-download.php +5 -3
  36. lib/model/export/class-ai1wm-export-enumerate.php +1 -1
  37. lib/model/export/class-ai1wm-export-init.php +1 -1
  38. lib/model/import/class-ai1wm-import-blogs.php +1 -1
  39. lib/model/import/class-ai1wm-import-clean.php +1 -1
  40. lib/model/import/class-ai1wm-import-compatibility.php +1 -1
  41. lib/model/import/class-ai1wm-import-confirm.php +1 -1
  42. lib/model/import/class-ai1wm-import-content.php +1 -1
  43. lib/model/import/class-ai1wm-import-database.php +1 -1
  44. lib/model/import/class-ai1wm-import-done.php +4 -1
  45. lib/model/import/class-ai1wm-import-enumerate.php +1 -1
  46. lib/model/import/class-ai1wm-import-mu-plugins.php +2 -1
  47. lib/model/import/class-ai1wm-import-upload.php +1 -1
  48. lib/model/import/class-ai1wm-import-validate.php +1 -1
  49. lib/vendor/math/BigInteger.php +0 -3811
  50. lib/vendor/servmask/archiver/class-ai1wm-archiver.php +1 -1
  51. lib/vendor/servmask/archiver/class-ai1wm-compressor.php +1 -1
  52. lib/vendor/servmask/archiver/class-ai1wm-extractor.php +1 -1
  53. lib/vendor/servmask/command/class-ai1wm-wp-cli-command.php +1 -1
  54. lib/vendor/servmask/cron/class-ai1wm-cron.php +1 -1
  55. lib/vendor/servmask/database/class-ai1wm-database-mysql.php +1 -1
  56. lib/vendor/servmask/database/class-ai1wm-database-mysqli.php +1 -1
  57. lib/vendor/servmask/database/class-ai1wm-database-utility.php +1 -1
  58. lib/vendor/servmask/database/class-ai1wm-database.php +1 -1
  59. lib/vendor/servmask/filesystem/class-ai1wm-directory.php +1 -1
  60. lib/vendor/servmask/filesystem/class-ai1wm-file-htaccess.php +1 -1
  61. lib/vendor/servmask/filesystem/class-ai1wm-file-index.php +1 -1
  62. lib/vendor/servmask/filesystem/class-ai1wm-file-webconfig.php +1 -1
  63. lib/vendor/servmask/filesystem/class-ai1wm-file.php +1 -1
  64. lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php +1 -1
  65. lib/vendor/servmask/filter/class-ai1wm-recursive-extension-filter.php +1 -1
  66. lib/vendor/servmask/iterator/class-ai1wm-recursive-directory-iterator.php +1 -1
  67. lib/vendor/servmask/iterator/class-ai1wm-recursive-iterator-iterator.php +1 -1
  68. lib/view/assets/css/export.min.css +1 -1
  69. lib/view/assets/css/export.min.rtl.css +1 -1
  70. lib/view/assets/javascript/backups.min.js +6 -6
  71. lib/view/assets/javascript/export.min.js +7 -7
  72. lib/view/assets/javascript/import.min.js +6 -6
  73. lib/view/assets/javascript/settings.min.js +3 -3
  74. lib/view/assets/javascript/updater.min.js +1 -1
  75. lib/view/assets/javascript/util.min.js +2 -2
  76. lib/view/backups/index.php +2 -2
  77. lib/view/common/http-authentication.php +1 -1
  78. lib/view/common/leave-feedback.php +1 -1
  79. lib/view/common/maintenance-mode.php +1 -1
  80. lib/view/common/report-problem.php +1 -1
  81. lib/view/common/share-buttons.php +1 -1
  82. lib/view/export/advanced-settings.php +1 -1
  83. lib/view/export/button-azure-storage.php +1 -1
  84. lib/view/export/button-b2.php +1 -1
  85. lib/view/export/button-box.php +1 -1
  86. lib/view/export/button-digitalocean.php +1 -1
  87. lib/view/export/button-dropbox.php +1 -1
  88. lib/view/export/button-file.php +1 -1
  89. lib/view/export/button-ftp.php +1 -1
  90. lib/view/export/button-gcloud-storage.php +1 -1
  91. lib/view/export/button-gdrive.php +1 -1
  92. lib/view/export/button-glacier.php +1 -1
  93. lib/view/export/button-mega.php +1 -1
  94. lib/view/export/button-onedrive.php +1 -1
  95. lib/view/export/button-pcloud.php +1 -1
  96. lib/view/export/button-s3-client.php +1 -1
  97. lib/view/export/button-s3.php +1 -1
  98. lib/view/export/button-webdav.php +1 -1
  99. lib/view/export/export-buttons.php +1 -1
  100. lib/view/export/find-replace.php +1 -1
  101. lib/view/export/help-section.php +1 -1
  102. lib/view/export/index.php +1 -1
  103. lib/view/import/button-azure-storage.php +1 -1
  104. lib/view/import/button-b2.php +1 -1
  105. lib/view/import/button-box.php +1 -1
  106. lib/view/import/button-digitalocean.php +1 -1
  107. lib/view/import/button-dropbox.php +1 -1
  108. lib/view/import/button-file.php +1 -1
  109. lib/view/import/button-ftp.php +1 -1
  110. lib/view/import/button-gcloud-storage.php +1 -1
  111. lib/view/import/button-gdrive.php +1 -1
  112. lib/view/import/button-glacier.php +1 -1
  113. lib/view/import/button-mega.php +1 -1
  114. lib/view/import/button-onedrive.php +1 -1
  115. lib/view/import/button-pcloud.php +1 -1
  116. lib/view/import/button-s3-client.php +1 -1
  117. lib/view/import/button-s3.php +1 -1
  118. lib/view/import/button-url.php +1 -1
  119. lib/view/import/button-webdav.php +1 -1
  120. lib/view/import/import-buttons.php +1 -1
  121. lib/view/import/index.php +1 -1
  122. lib/view/import/pro.php +1 -1
  123. lib/view/main/admin-head.php +1 -1
  124. lib/view/main/backups-htaccess-notice.php +1 -1
  125. lib/view/main/backups-index-notice.php +1 -1
  126. lib/view/main/backups-path-notice.php +1 -1
  127. lib/view/main/backups-webconfig-notice.php +1 -1
  128. lib/view/main/get-support.php +1 -1
  129. lib/view/main/multisite-notice.php +1 -1
  130. lib/view/main/storage-index-notice.php +1 -1
  131. lib/view/main/storage-path-notice.php +1 -1
  132. lib/view/main/wordpress-htaccess-notice.php +1 -1
  133. lib/view/updater/check.php +1 -1
  134. lib/view/updater/modal.php +1 -1
  135. loader.php +1 -7
  136. readme.txt +7 -1
  137. uninstall.php +1 -1
all-in-one-wp-migration.php CHANGED
@@ -5,12 +5,12 @@
5
* Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
* Author: ServMask
7
* Author URI: https://servmask.com/
8
- * Version: 6.83
9
* Text Domain: all-in-one-wp-migration
10
* Domain Path: /languages
11
* Network: True
12
*
13
- * Copyright (C) 2014-2018 ServMask Inc.
14
*
15
* This program is free software: you can redistribute it and/or modify
16
* it under the terms of the GNU General Public License as published by
5
* Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
* Author: ServMask
7
* Author URI: https://servmask.com/
8
+ * Version: 6.84
9
* Text Domain: all-in-one-wp-migration
10
* Domain Path: /languages
11
* Network: True
12
*
13
+ * Copyright (C) 2014-2019 ServMask Inc.
14
*
15
* This program is free software: you can redistribute it and/or modify
16
* it under the terms of the GNU General Public License as published by
constants.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@ define( 'AI1WM_DEBUG', false );
31
// ==================
32
// = Plugin Version =
33
// ==================
34
- define( 'AI1WM_VERSION', '6.83' );
35
36
// ===============
37
// = Plugin Name =
@@ -183,6 +183,11 @@ define( 'AI1WM_ENDURANCE_BROWSER_CACHE_NAME', 'endurance-browser-cache.php' );
183
// =========================
184
define( 'AI1WM_GD_SYSTEM_PLUGIN_NAME', 'gd-system-plugin.php' );
185
186
// ===================
187
// = Export Log Name =
188
// ===================
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
31
// ==================
32
// = Plugin Version =
33
// ==================
34
+ define( 'AI1WM_VERSION', '6.84' );
35
36
// ===============
37
// = Plugin Name =
183
// =========================
184
define( 'AI1WM_GD_SYSTEM_PLUGIN_NAME', 'gd-system-plugin.php' );
185
186
+ // =======================
187
+ // = Wp Stack Cache Name =
188
+ // =======================
189
+ define( 'AI1WM_WP_STACK_CACHE_NAME', 'wp-stack-cache.php' );
190
+
191
// ===================
192
// = Export Log Name =
193
// ===================
deprecated.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
exceptions.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
functions.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
@@ -1314,52 +1314,6 @@ function ai1wm_copy( $source_file, $destination_file ) {
1314
ai1wm_close( $destination_handle );
1315
}
1316
1317
- /**
1318
- * Get the size of file in bytes
1319
- *
1320
- * This method supports files > 2GB on PHP x86
1321
- *
1322
- * @param string $file_path Path to the file
1323
- * @param boolean $as_string Return the filesize as string instead of BigInteger
1324
- *
1325
- * @return mixed Math_BigInteger|string|null
1326
- */
1327
- function ai1wm_filesize( $file_path, $as_string = true ) {
1328
- $chunk_size = 2000000; // 2MB
1329
- $file_size = new Math_BigInteger( 0 );
1330
-
1331
- try {
1332
- $file_handle = ai1wm_open( $file_path, 'rb' );
1333
-
1334
- while ( ! feof( $file_handle ) ) {
1335
- $bytes = ai1wm_read( $file_handle, $chunk_size );
1336
- $file_size = $file_size->add( new Math_BigInteger( strlen( $bytes ) ) );
1337
- }
1338
-
1339
- ai1wm_close( $file_handle );
1340
-
1341
- return $as_string ? $file_size->toString() : $file_size;
1342
- } catch ( Exception $e ) {
1343
- return null;
1344
- }
1345
- }
1346
-
1347
- /**
1348
- * Return the smaller of two numbers
1349
- *
1350
- * @param Math_BigInteger $a First number
1351
- * @param Math_BigInteger $b Second number
1352
- *
1353
- * @return Math_BigInteger
1354
- */
1355
- function ai1wm_find_smaller_number( Math_BigInteger $a, Math_BigInteger $b ) {
1356
- if ( $a->compare( $b ) === -1 ) {
1357
- return $a;
1358
- }
1359
-
1360
- return $b;
1361
- }
1362
-
1363
/**
1364
* Check whether file size is supported by current PHP version
1365
*
@@ -1386,23 +1340,6 @@ function ai1wm_is_filesize_supported( $file, $php_int_size = PHP_INT_SIZE, $php_
1386
return $size_result;
1387
}
1388
1389
- /**
1390
- * Wrapper around fseek
1391
- *
1392
- * This function works with offsets that are > PHP_INT_MAX
1393
- *
1394
- * @param resource $file_handle Handle to the file
1395
- * @param Math_BigInteger $offset Offset of the file
1396
- */
1397
- function ai1wm_fseek( $file_handle, Math_BigInteger $offset ) {
1398
- $chunk_size = ai1wm_find_smaller_number( new Math_BigInteger( 2000000 ), $offset );
1399
- while ( ! feof( $file_handle ) && $offset->toString() != '0' ) {
1400
- $bytes = ai1wm_read( $file_handle, $chunk_size->toInteger() );
1401
- $offset = $offset->subtract( new Math_BigInteger( strlen( $bytes ) ) );
1402
- $chunk_size = ai1wm_find_smaller_number( $chunk_size, $offset );
1403
- }
1404
- }
1405
-
1406
/**
1407
* Verify secret key
1408
*
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1314
ai1wm_close( $destination_handle );
1315
}
1316
1317
/**
1318
* Check whether file size is supported by current PHP version
1319
*
1340
return $size_result;
1341
}
1342
1343
/**
1344
* Verify secret key
1345
*
lib/controller/class-ai1wm-backups-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-feedback-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-report-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-status-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/controller/class-ai1wm-updater-controller.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-backups.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-compatibility.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-deprecated.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-extensions.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-feedback.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-handler.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-log.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-message.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-notification.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-report.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-status.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-template.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/class-ai1wm-updater.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-archive.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-clean.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-compatibility.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-config-file.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-config.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-content.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-database-file.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-database.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-download.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@ class Ai1wm_Export_Download {
49
}
50
51
// Set archive details
52
$link = ai1wm_backup_url( $params );
53
$size = ai1wm_backup_size( $params );
54
$name = ai1wm_site_name( $blog_id );
@@ -57,7 +58,7 @@ class Ai1wm_Export_Download {
57
Ai1wm_Status::download(
58
sprintf(
59
__(
60
- '<a href="%s" class="ai1wm-button-green ai1wm-emphasize" title="%s">' .
61
'<span>Download %s</span>' .
62
'<em>Size: %s</em>' .
63
'</a>',
@@ -65,7 +66,8 @@ class Ai1wm_Export_Download {
65
),
66
$link,
67
$name,
68
- strlen( $name ) > 25 ? substr( $name, 0, 24 ) . '&hellip;' : $name,
69
$size
70
)
71
);
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
49
}
50
51
// Set archive details
52
+ $file = ai1wm_archive_name( $params );
53
$link = ai1wm_backup_url( $params );
54
$size = ai1wm_backup_size( $params );
55
$name = ai1wm_site_name( $blog_id );
58
Ai1wm_Status::download(
59
sprintf(
60
__(
61
+ '<a href="%s" class="ai1wm-button-green ai1wm-emphasize ai1wm-button-download" title="%s" download="%s">' .
62
'<span>Download %s</span>' .
63
'<em>Size: %s</em>' .
64
'</a>',
66
),
67
$link,
68
$name,
69
+ $file,
70
+ $name,
71
$size
72
)
73
);
lib/model/export/class-ai1wm-export-enumerate.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/export/class-ai1wm-export-init.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-blogs.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-clean.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-compatibility.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-confirm.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-content.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-database.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-done.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
@@ -67,6 +67,7 @@ class Ai1wm_Import_Done {
67
ai1wm_discover_plugin_basename( 'join-my-multisite/joinmymultisite.php' ),
68
ai1wm_discover_plugin_basename( 'multisite-clone-duplicator/multisite-clone-duplicator.php' ),
69
ai1wm_discover_plugin_basename( 'wordpress-mu-domain-mapping/domain_mapping.php' ),
70
) );
71
72
// Deactivate Jetpack modules
@@ -128,6 +129,7 @@ class Ai1wm_Import_Done {
128
ai1wm_discover_plugin_basename( 'join-my-multisite/joinmymultisite.php' ),
129
ai1wm_discover_plugin_basename( 'multisite-clone-duplicator/multisite-clone-duplicator.php' ),
130
ai1wm_discover_plugin_basename( 'wordpress-mu-domain-mapping/domain_mapping.php' ),
131
) );
132
133
// Deactivate Jetpack modules
@@ -191,6 +193,7 @@ class Ai1wm_Import_Done {
191
ai1wm_discover_plugin_basename( 'join-my-multisite/joinmymultisite.php' ),
192
ai1wm_discover_plugin_basename( 'multisite-clone-duplicator/multisite-clone-duplicator.php' ),
193
ai1wm_discover_plugin_basename( 'wordpress-mu-domain-mapping/domain_mapping.php' ),
194
) );
195
196
// Deactivate Jetpack modules
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
67
ai1wm_discover_plugin_basename( 'join-my-multisite/joinmymultisite.php' ),
68
ai1wm_discover_plugin_basename( 'multisite-clone-duplicator/multisite-clone-duplicator.php' ),
69
ai1wm_discover_plugin_basename( 'wordpress-mu-domain-mapping/domain_mapping.php' ),
70
+ ai1wm_discover_plugin_basename( 'pro-sites/pro-sites.php' ),
71
) );
72
73
// Deactivate Jetpack modules
129
ai1wm_discover_plugin_basename( 'join-my-multisite/joinmymultisite.php' ),
130
ai1wm_discover_plugin_basename( 'multisite-clone-duplicator/multisite-clone-duplicator.php' ),
131
ai1wm_discover_plugin_basename( 'wordpress-mu-domain-mapping/domain_mapping.php' ),
132
+ ai1wm_discover_plugin_basename( 'pro-sites/pro-sites.php' ),
133
) );
134
135
// Deactivate Jetpack modules
193
ai1wm_discover_plugin_basename( 'join-my-multisite/joinmymultisite.php' ),
194
ai1wm_discover_plugin_basename( 'multisite-clone-duplicator/multisite-clone-duplicator.php' ),
195
ai1wm_discover_plugin_basename( 'wordpress-mu-domain-mapping/domain_mapping.php' ),
196
+ ai1wm_discover_plugin_basename( 'pro-sites/pro-sites.php' ),
197
) );
198
199
// Deactivate Jetpack modules
lib/model/import/class-ai1wm-import-enumerate.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-mu-plugins.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
@@ -35,6 +35,7 @@ class Ai1wm_Import_Mu_Plugins {
35
AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_ENDURANCE_PHP_EDGE_NAME,
36
AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_ENDURANCE_BROWSER_CACHE_NAME,
37
AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_GD_SYSTEM_PLUGIN_NAME,
38
);
39
40
// Open the archive file for reading
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
35
AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_ENDURANCE_PHP_EDGE_NAME,
36
AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_ENDURANCE_BROWSER_CACHE_NAME,
37
AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_GD_SYSTEM_PLUGIN_NAME,
38
+ AI1WM_MUPLUGINS_NAME . DIRECTORY_SEPARATOR . AI1WM_WP_STACK_CACHE_NAME,
39
);
40
41
// Open the archive file for reading
lib/model/import/class-ai1wm-import-upload.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/model/import/class-ai1wm-import-validate.php CHANGED
@@ -1,6 +1,6 @@
1
<?php
2
/**
3
- * Copyright (C) 2014-2018 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
1
<?php
2
/**
3
+ * Copyright (C) 2014-2019 ServMask Inc.
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
lib/vendor/math/BigInteger.php DELETED
@@ -1,3811 +0,0 @@
1
- <?php
2
-
3
- if ( ! class_exists( 'Math_BigInteger' ) ) {
4
- /**
5
- * Pure-PHP arbitrary precision integer arithmetic library.
6
- *
7
- * Supports base-2, base-10, base-16, and base-256 numbers. Uses the GMP or BCMath extensions, if available,
8
- * and an internal implementation, otherwise.
9
- *
10
- * PHP versions 4 and 5
11
- *
12
- * {@internal (all DocBlock comments regarding implementation - such as the one that follows - refer to the
13
- * {@link MATH_BIGINTEGER_MODE_INTERNAL MATH_BIGINTEGER_MODE_INTERNAL} mode)
14
- *
15
- * Math_BigInteger uses base-2**26 to perform operations such as multiplication and division and
16
- * base-2**52 (ie. two base 2**26 digits) to perform addition and subtraction. Because the largest possible
17
- * value when multiplying two base-2**26 numbers together is a base-2**52 number, double precision floating
18
- * point numbers - numbers that should be supported on most hardware and whose significand is 53 bits - are
19
- * used. As a consequence, bitwise operators such as >> and << cannot be used, nor can the modulo operator %,
20
- * which only supports integers. Although this fact will slow this library down, the fact that such a high
21
- * base is being used should more than compensate.
22
- *
23
- * Numbers are stored in {@link http://en.wikipedia.org/wiki/Endianness little endian} format. ie.
24
- * (new Math_BigInteger(pow(2, 26)))->value = array(0, 1)
25
- *
26
- * Useful resources are as follows:
27
- *
28
- * - {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf Handbook of Applied Cryptography (HAC)}
29
- * - {@link http://math.libtomcrypt.com/files/tommath.pdf Multi-Precision Math (MPM)}
30
- * - Java's BigInteger classes. See /j2se/src/share/classes/java/math in jdk-1_5_0-src-jrl.zip
31
- *
32
- * Here's an example of how to use this library:
33
- * <code>
34
- * <?php
35
- * include 'Math/BigInteger.php';
36
- *
37
- * $a = new Math_BigInteger(2);
38
- * $b = new Math_BigInteger(3);
39
- *
40
- * $c = $a->add($b);
41
- *
42
- * echo $c->toString(); // outputs 5
43
- * ?>
44
- * </code>
45
- *
46
- * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
47
- * of this software and associated documentation files (the "Software"), to deal
48
- * in the Software without restriction, including without limitation the rights
49
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50
- * copies of the Software, and to permit persons to whom the Software is
51
- * furnished to do so, subject to the following conditions:
52
- *
53
- * The above copyright notice and this permission notice shall be included in
54
- * all copies or substantial portions of the Software.
55
- *
56
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
62
- * THE SOFTWARE.
63
- *
64
- * @category Math
65
- * @package Math_BigInteger
66
- * @author Jim Wigginton <terrafrost@php.net>
67
- * @copyright 2006 Jim Wigginton
68
- * @license http://www.opensource.org/licenses/mit-license.html MIT License
69
- * @link http://pear.php.net/package/Math_BigInteger
70
- */
71
-
72
- /**#@+
73
- * Reduction constants
74
- *
75
- * @access private
76
- * @see self::_reduce()
77
- */
78
- /**
79
- * @see self::_montgomery()
80
- * @see self::_prepMontgomery()
81
- */
82
- define('MATH_BIGINTEGER_MONTGOMERY', 0);
83
- /**
84
- * @see self::_barrett()
85
- */
86
- define('MATH_BIGINTEGER_BARRETT', 1);
87
- /**
88
- * @see self::_mod2()
89
- */
90
- define('MATH_BIGINTEGER_POWEROF2', 2);
91
- /**
92
- * @see self::_remainder()
93
- */
94
- define('MATH_BIGINTEGER_CLASSIC', 3);
95
- /**
96
- * @see self::__clone()
97
- */
98
- define('MATH_BIGINTEGER_NONE', 4);
99
- /**#@-*/
100
-
101
- /**#@+
102
- * Array constants
103
- *
104
- * Rather than create a thousands and thousands of new Math_BigInteger objects in repeated function calls to add() and
105
- * multiply() or whatever, we'll just work directly on arrays, taking them in as parameters and returning them.
106
- *
107
- * @access private
108
- */
109
- /**
110
- * $result[MATH_BIGINTEGER_VALUE] contains the value.
111
- */
112
- define('MATH_BIGINTEGER_VALUE', 0);
113
- /**
114
- * $result[MATH_BIGINTEGER_SIGN] contains the sign.
115
- */
116
- define('MATH_BIGINTEGER_SIGN', 1);
117
- /**#@-*/
118
-
119
- /**#@+
120
- * @access private
121
- * @see self::_montgomery()
122
- * @see self::_barrett()
123
- */
124
- /**
125
- * Cache constants
126
- *
127
- * $cache[MATH_BIGINTEGER_VARIABLE] tells us whether or not the cached data is still valid.
128
- */
129
- define('MATH_BIGINTEGER_VARIABLE', 0);
130
- /**
131
- * $cache[MATH_BIGINTEGER_DATA] contains the cached data.
132
- */
133
- define('MATH_BIGINTEGER_DATA', 1);
134
- /**#@-*/
135
-
136
- /**#@+
137
- * Mode constants.
138
- *
139
- * @access private
140
- * @see self::Math_BigInteger()
141
- */
142
- /**
143
- * To use the pure-PHP implementation
144
- */
145
- define('MATH_BIGINTEGER_MODE_INTERNAL', 1);
146
- /**
147
- * To use the BCMath library
148
- *
149
- * (if enabled; otherwise, the internal implementation will be used)
150
- */
151
- define('MATH_BIGINTEGER_MODE_BCMATH', 2);
152
- /**
153
- * To use the GMP library
154
- *
155
- * (if present; otherwise, either the BCMath or the internal implementation will be used)
156
- */
157
- define('MATH_BIGINTEGER_MODE_GMP', 3);
158
- /**#@-*/
159
-
160
- /**
161
- * Karatsuba Cutoff
162
- *
163
- * At what point do we switch between Karatsuba multiplication and schoolbook long multiplication?
164
- *
165
- * @access private
166
- */
167
- define('MATH_BIGINTEGER_KARATSUBA_CUTOFF', 25);
168
-
169
- /**
170
- * Pure-PHP arbitrary precision integer arithmetic library. Supports base-2, base-10, base-16, and base-256
171
- * numbers.
172
- *
173
- * @package Math_BigInteger
174
- * @author Jim Wigginton <terrafrost@php.net>
175
- * @access public
176
- */
177
- class Math_BigInteger
178
- {
179
- /**
180
- * Holds the BigInteger's value.
181
- *
182
- * @var array
183
- * @access private
184
- */
185
- var $value;
186
-
187
- /**
188
- * Holds the BigInteger's magnitude.
189
- *
190
- * @var bool
191
- * @access private
192
- */
193
- var $is_negative = false;
194
-
195
- /**
196
- * Precision
197
- *
198
- * @see self::setPrecision()
199
- * @access private
200
- */
201
- var $precision = -1;
202
-
203
- /**
204
- * Precision Bitmask
205
- *
206
- * @see self::setPrecision()
207
- * @access private
208
- */
209
- var $bitmask = false;
210
-
211
- /**
212
- * Mode independent value used for serialization.
213
- *
214
- * If the bcmath or gmp extensions are installed $this->value will be a non-serializable resource, hence the need for
215
- * a variable that'll be serializable regardless of whether or not extensions are being used. Unlike $this->value,
216
- * however, $this->hex is only calculated when $this->__sleep() is called.
217
- *
218
- * @see self::__sleep()
219
- * @see self::__wakeup()
220
- * @var string
221
- * @access private
222
- */
223
- var $hex;
224
-
225
- /**
226
- * Converts base-2, base-10, base-16, and binary strings (base-256) to BigIntegers.
227
- *
228
- * If the second parameter - $base - is negative, then it will be assumed that the number's are encoded using
229
- * two's compliment. The sole exception to this is -10, which is treated the same as 10 is.
230
- *
231
- * Here's an example:
232
- * <code>
233
- * <?php
234
- * include 'Math/BigInteger.php';
235
- *
236
- * $a = new Math_BigInteger('0x32', 16); // 50 in base-16
237
- *
238
- * echo $a->toString(); // outputs 50
239
- * ?>
240
- * </code>
241
- *
242
- * @param $x base-10 number or base-$base number if $base set.
243
- * @param int $base
244
- * @return Math_BigInteger
245
- * @access public
246
- */
247
- function __construct($x = 0, $base = 10)
248
- {
249
- if (!defined('MATH_BIGINTEGER_MODE')) {
250
- switch (true) {
251
- case extension_loaded('gmp'):
252
- define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
253
- break;
254
- case extension_loaded('bcmath'):
255
- define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_BCMATH);
256
- break;
257
- default:
258
- define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
259
- }
260
- }
261
-
262
- if (extension_loaded('openssl') && !defined('MATH_BIGINTEGER_OPENSSL_DISABLE') && !defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
263
- // some versions of XAMPP have mismatched versions of OpenSSL which causes it not to work
264
- ob_start();
265
- @phpinfo();
266
- $content = ob_get_contents();
267
- ob_end_clean();
268
-
269
- preg_match_all('#OpenSSL (Header|Library) Version(.*)#im', $content, $matches);
270
-
271
- $versions = array();
272
- if (!empty($matches[1])) {
273
- for ($i = 0; $i < count($matches[1]); $i++) {
274
- $fullVersion = trim(str_replace('=>', '', strip_tags($matches[2][$i])));
275
-
276
- // Remove letter part in OpenSSL version
277
- if (!preg_match('/(\d+\.\d+\.\d+)/i', $fullVersion, $m)) {
278
- $versions[$matches[1][$i]] = $fullVersion;
279
- } else {
280
- $versions[$matches[1][$i]] = $m[0];
281
- }
282
- }
283
- }
284
-
285
- // it doesn't appear that OpenSSL versions were reported upon until PHP 5.3+
286
- switch (true) {
287
- case !isset($versions['Header']):
288
- case !isset($versions['Library']):
289
- case $versions['Header'] == $versions['Library']:
290
- case version_compare($versions['Header'], '1.0.0') >= 0 && version_compare($versions['Library'], '1.0.0') >= 0:
291
- define('MATH_BIGINTEGER_OPENSSL_ENABLED', true);
292
- break;
293
- default:
294
- define('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
295
- }
296
- }
297
-
298
- if (!defined('PHP_INT_SIZE')) {
299
- define('PHP_INT_SIZE', 4);
300
- }
301
-
302
- if (!defined('MATH_BIGINTEGER_BASE') && MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_INTERNAL) {
303
- switch (PHP_INT_SIZE) {
304
- case 8: // use 64-bit integers if int size is 8 bytes
305
- define('MATH_BIGINTEGER_BASE', 31);
306
- define('MATH_BIGINTEGER_BASE_FULL', 0x80000000);
307
- define('MATH_BIGINTEGER_MAX_DIGIT', 0x7FFFFFFF);
308
- define('MATH_BIGINTEGER_MSB', 0x40000000);
309
- // 10**9 is the closest we can get to 2**31 without passing it
310
- define('MATH_BIGINTEGER_MAX10', 1000000000);
311
- define('MATH_BIGINTEGER_MAX10_LEN', 9);
312
- // the largest digit that may be used in addition / subtraction
313
- define('MATH_BIGINTEGER_MAX_DIGIT2', pow(2, 62));
314
- break;
315
- //case 4: // use 64-bit floats if int size is 4 bytes
316
- default:
317
- define('MATH_BIGINTEGER_BASE', 26);
318
- define('MATH_BIGINTEGER_BASE_FULL', 0x4000000);
319
- define('MATH_BIGINTEGER_MAX_DIGIT', 0x3FFFFFF);
320
- define('MATH_BIGINTEGER_MSB', 0x2000000);
321
- // 10**7 is the closest to 2**26 without passing it
322
- define('MATH_BIGINTEGER_MAX10', 10000000);
323
- define('MATH_BIGINTEGER_MAX10_LEN', 7);
324
- // the largest digit that may be used in addition / subtraction
325
- // we do pow(2, 52) instead of using 4503599627370496 directly because some
326
- // PHP installations will truncate 4503599627370496.
327
- define('MATH_BIGINTEGER_MAX_DIGIT2', pow(2, 52));
328
- }
329
- }
330
-
331
- switch (MATH_BIGINTEGER_MODE) {
332
- case MATH_BIGINTEGER_MODE_GMP:
333
- switch (true) {
334
- case is_resource($x) && get_resource_type($x) == 'GMP integer':
335
- // PHP 5.6 switched GMP from using resources to objects
336
- case is_object($x) && get_class($x) == 'GMP':
337
- $this->value = $x;
338
- return;
339
- }
340
- $this->value = gmp_init(0);
341
- break;
342
- case MATH_BIGINTEGER_MODE_BCMATH:
343
- $this->value = '0';
344
- break;
345
- default:
346
- $this->value = array();
347
- }
348
-
349
- // '0' counts as empty() but when the base is 256 '0' is equal to ord('0') or 48
350
- // '0' is the only value like this per http://php.net/empty
351
- if (empty($x) && (abs($base) != 256 || $x !== '0')) {
352
- return;
353
- }
354
-
355
- switch ($base) {
356
- case -256:
357
- if (ord($x[0]) & 0x80) {
358
- $x = ~$x;
359
- $this->is_negative = true;
360
- }
361
- case 256:
362
- switch (MATH_BIGINTEGER_MODE) {
363
- case MATH_BIGINTEGER_MODE_GMP:
364
- $sign = $this->is_negative ? '-' : '';
365
- $this->value = gmp_init($sign . '0x' . bin2hex($x));
366
- break;
367
- case MATH_BIGINTEGER_MODE_BCMATH:
368
- // round $len to the nearest 4 (thanks, DavidMJ!)
369
- $len = (strlen($x) + 3) & 0xFFFFFFFC;
370
-
371
- $x = str_pad($x, $len, chr(0), STR_PAD_LEFT);
372
-
373
- for ($i = 0; $i < $len; $i+= 4) {
374
- $this->value = bcmul($this->value, '4294967296', 0); // 4294967296 == 2**32
375
- $this->value = bcadd($this->value, 0x1000000 * ord($x[$i]) + ((ord($x[$i + 1]) << 16) | (ord($x[$i + 2]) << 8) | ord($x[$i + 3])), 0);
376
- }
377
-
378
- if ($this->is_negative) {
379
- $this->value = '-' . $this->value;
380
- }
381
-
382
- break;
383
- // converts a base-2**8 (big endian / msb) number to base-2**26 (little endian / lsb)
384
- default:
385
- while (strlen($x)) {
386
- $this->value[] = $this->_bytes2int($this->_base256_rshift($x, MATH_BIGINTEGER_BASE));
387
- }
388
- }
389
-
390
- if ($this->is_negative) {
391
- if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_INTERNAL) {
392
- $this->is_negative = false;
393
- }
394
- $temp = $this->add(new Math_BigInteger('-1'));
395
- $this->value = $temp->value;
396
- }
397
- break;
398
- case 16:
399
- case -16:
400
- if ($base > 0 && $x[0] == '-') {
401
- $this->is_negative = true;
402
- $x = substr($x, 1);
403
- }
404
-
405
- $x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#', '$1', $x);
406
-
407
- $is_negative = false;
408
- if ($base < 0 && hexdec($x[0]) >= 8) {
409
- $this->is_negative = $is_negative = true;
410
- $x = bin2hex(~pack('H*', $x));
411
- }
412
-
413
- switch (MATH_BIGINTEGER_MODE) {
414
- case MATH_BIGINTEGER_MODE_GMP:
415
- $temp = $this->is_negative ? '-0x' . $x : '0x' . $x;
416
- $this->value = gmp_init($temp);
417
- $this->is_negative = false;
418
- break;
419
- case MATH_BIGINTEGER_MODE_BCMATH:
420
- $x = (strlen($x) & 1) ? '0' . $x : $x;
421
- $temp = new Math_BigInteger(pack('H*', $x), 256);
422
- $this->value = $this->is_negative ? '-' . $temp->value : $temp->value;
423
- $this->is_negative = false;
424
- break;
425
- default:
426
- $x = (strlen($x) & 1) ? '0' . $x : $x;
427
- $temp = new Math_BigInteger(pack('H*', $x), 256);
428
- $this->value = $temp->value;
429
- }
430
-
431
- if ($is_negative) {
432
- $temp = $this->add(new Math_BigInteger('-1'));
433
- $this->value = $temp->value;
434
- }
435
- break;
436
- case 10:
437
- case -10:
438
- // (?<!^)(?:-).*: find any -'s that aren't at the beginning and then any characters that follow that
439
- // (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals)
440
- // [^-0-9].*: find any non-numeric characters and then any characters that follow that
441
- $x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x);
442
-
443
- switch (MATH_BIGINTEGER_MODE) {
444
- case MATH_BIGINTEGER_MODE_GMP:
445
- $this->value = gmp_init($x);
446
- break;
447
- case MATH_BIGINTEGER_MODE_BCMATH:
448
- // explicitly casting $x to a string is necessary, here, since doing $x[0] on -1 yields different
449
- // results then doing it on '-1' does (modInverse does $x[0])
450
- $this->value = $x === '-' ? '0' : (string) $x;
451
- break;
452
- default:
453
- $temp = new Math_BigInteger();
454
-
455
- $multiplier = new Math_BigInteger();
456
- $multiplier->value = array(MATH_BIGINTEGER_MAX10);
457
-
458
- if ($x[0] == '-') {
459
- $this->is_negative = true;
460
- $x = substr($x, 1);
461
- }
462
-
463
- $x = str_pad($x, strlen($x) + ((MATH_BIGINTEGER_MAX10_LEN - 1) * strlen($x)) % MATH_BIGINTEGER_MAX10_LEN, 0, STR_PAD_LEFT);
464
- while (strlen($x)) {
465
- $temp = $temp->multiply($multiplier);
466
- $temp = $temp->add(new Math_BigInteger($this->_int2bytes(substr($x, 0, MATH_BIGINTEGER_MAX10_LEN)), 256));
467
- $x = substr($x, MATH_BIGINTEGER_MAX10_LEN);
468
- }
469
-
470
- $this->value = $temp->value;
471
- }
472
- break;
473
- case 2: // base-2 support originally implemented by Lluis Pamies - thanks!
474
- case -2:
475
- if ($base > 0 && $x[0] == '-') {
476
- $this->is_negative = true;
477
- $x = substr($x, 1);
478
- }
479
-
480
- $x = preg_replace('#^([01]*).*#', '$1', $x);
481
- $x = str_pad($x, strlen($x) + (3 * strlen($x)) % 4, 0, STR_PAD_LEFT);
482
-
483
- $str = '0x';
484
- while (strlen($x)) {
485
- $part = substr($x, 0, 4);
486
- $str.= dechex(bindec($part));
487
- $x = substr($x, 4);
488
- }
489
-
490
- if ($this->is_negative) {
491
- $str = '-' . $str;
492
- }
493
-
494
- $temp = new Math_BigInteger($str, 8 * $base); // ie. either -16 or +16
495
- $this->value = $temp->value;
496
- $this->is_negative = $temp->is_negative;
497
-
498
- break;
499
- default:
500
- // base not supported, so we'll let $this == 0
501
- }
502
- }
503
-
504
- /**
505
- * PHP4 compatible Default Constructor.
506
- *
507
- * @see self::__construct()
508
- * @param $x base-10 number or base-$base number if $base set.
509
- * @param int $base
510
- * @access public
511
- */
512
- function Math_BigInteger($x = 0, $base = 10)
513
- {
514
- $this->__construct($x, $base);
515
- }
516
-
517
- /**
518
- * Converts a BigInteger to a byte string (eg. base-256).
519
- *
520
- * Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're
521
- * saved as two's compliment.
522
- *
523
- * Here's an example:
524
- * <code>
525
- * <?php
526
- * include 'Math/BigInteger.php';
527
- *
528
- * $a = new Math_BigInteger('65');
529
- *
530
- * echo $a->toBytes(); // outputs chr(65)
531
- * ?>
532
- * </code>
533
- *
534
- * @param bool $twos_compliment
535
- * @return string
536
- * @access public
537
- * @internal Converts a base-2**26 number to base-2**8
538
- */
539
- function toBytes($twos_compliment = false)
540
- {
541
- if ($twos_compliment) {
542
- $comparison = $this->compare(new Math_BigInteger());
543
- if ($comparison == 0) {
544
- return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
545
- }
546
-
547
- $temp = $comparison < 0 ? $this->add(new Math_BigInteger(1)) : $this->copy();
548
- $bytes = $temp->toBytes();
549
-
550
- if (empty($bytes)) { // eg. if the number we're trying to convert is -1
551
- $bytes = chr(0);
552
- }
553
-
554
- if (ord($bytes[0]) & 0x80) {
555
- $bytes = chr(0) . $bytes;
556
- }
557
-
558
- return $comparison < 0 ? ~$bytes : $bytes;
559
- }
560
-
561
- switch (MATH_BIGINTEGER_MODE) {
562
- case MATH_BIGINTEGER_MODE_GMP:
563
- if (gmp_cmp($this->value, gmp_init(0)) == 0) {
564
- return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
565
- }
566
-
567
- $temp = gmp_strval(gmp_abs($this->value), 16);
568
- $temp = (strlen($temp) & 1) ? '0' . $temp : $temp;
569
- $temp = pack('H*', $temp);
570
-
571
- return $this->precision > 0 ?
572
- substr(str_pad($temp, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :
573
- ltrim($temp, chr(0));
574
- case MATH_BIGINTEGER_MODE_BCMATH:
575
- if ($this->value === '0') {
576
- return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
577
- }
578
-
579
- $value = '';
580
- $current = $this->value;
581
-
582
- if ($current[0] == '-') {
583
- $current = substr($current, 1);
584
- }
585
-
586
- while (bccomp($current, '0', 0) > 0) {
587
- $temp = bcmod($current, '16777216');
588
- $value = chr($temp >> 16) . chr($temp >> 8) . chr($temp) . $value;
589
- $current = bcdiv($current, '16777216', 0);
590
- }
591
-
592
- return $this->precision > 0 ?
593
- substr(str_pad($value, $this->precision >> 3, chr(0), STR_PAD_LEFT), -($this->precision >> 3)) :
594
- ltrim($value, chr(0));
595
- }
596
-
597
- if (!count($this->value)) {
598
- return $this->precision > 0 ? str_repeat(chr(0), ($this->precision + 1) >> 3) : '';
599
- }
600
- $result = $this->_int2bytes($this->value[count($this->value) - 1]);
601
-
602
- $temp = $this->copy();
603
-
604
- for ($i = count($temp->value) - 2; $i >= 0; --$i) {
605
- $temp->_base256_lshift($result, MATH_BIGINTEGER_BASE);
606
- $result = $result | str_pad($temp->_int2bytes($temp->value[$i]), strlen($result), chr(0), STR_PAD_LEFT);
607
- }
608
-
609
- return $this->precision > 0 ?
610
- str_pad(substr($result, -(($this->precision + 7) >> 3)), ($this->precision + 7) >> 3, chr(0), STR_PAD_LEFT) :
611
- $result;
612
- }
613
-
614
- /**
615
- * Converts a BigInteger to a hex string (eg. base-16)).
616
- *
617
- * Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're
618
- * saved as two's compliment.
619
- *
620
- * Here's an example:
621
- * <code>
622
- * <?php
623
- * include 'Math/BigInteger.php';
624
- *
625
- * $a = new Math_BigInteger('65');
626
- *
627
- * echo $a->toHex(); // outputs '41'
628
- * ?>
629
- * </code>
630
- *
631
- * @param bool $twos_compliment
632
- * @return string
633
- * @access public
634
- * @internal Converts a base-2**26 number to base-2**8
635
- */
636
- function toHex($twos_compliment = false)
637
- {
638
- return bin2hex($this->toBytes($twos_compliment));
639
- }
640
-
641
- /**
642
- * Converts a BigInteger to a bit string (eg. base-2).
643
- *
644
- * Negative numbers are saved as positive numbers, unless $twos_compliment is set to true, at which point, they're
645
- * saved as two's compliment.
646
- *
647
- * Here's an example:
648
- * <code>
649
- * <?php
650
- * include 'Math/BigInteger.php';
651
- *
652
- * $a = new Math_BigInteger('65');
653
- *
654
- * echo $a->toBits(); // outputs '1000001'
655
- * ?>
656
- * </code>
657
- *
658
- * @param bool $twos_compliment
659
- * @return string
660
- * @access public
661
- * @internal Converts a base-2**26 number to base-2**2
662
- */
663
- function toBits($twos_compliment = false)
664
- {
665
- $hex = $this->toHex($twos_compliment);
666
- $bits = '';
667
- for ($i = strlen($hex) - 8, $start = strlen($hex) & 7; $i >= $start; $i-=8) {
668
- $bits = str_pad(decbin(hexdec(substr($hex, $i, 8))), 32, '0', STR_PAD_LEFT) . $bits;
669
- }
670
- if ($start) { // hexdec('') == 0
671
- $bits = str_pad(decbin(hexdec(substr($hex, 0, $start))), 8, '0', STR_PAD_LEFT) . $bits;
672
- }
673
- $result = $this->precision > 0 ? substr($bits, -$this->precision) : ltrim($bits, '0');
674
-
675
- if ($twos_compliment && $this->compare(new Math_BigInteger()) > 0 && $this->precision <= 0) {
676
- return '0' . $result;
677
- }
678
-
679
- return $result;
680
- }
681
-
682
- /**
683
- * Converts a BigInteger to a base-10 number.
684
- *
685
- * Here's an example:
686
- * <code>
687
- * <?php
688
- * include 'Math/BigInteger.php';
689
- *
690
- * $a = new Math_BigInteger('50');
691
- *
692
- * echo $a->toString(); // outputs 50
693
- * ?>
694
- * </code>
695
- *
696
- * @return string
697
- * @access public
698
- * @internal Converts a base-2**26 number to base-10**7 (which is pretty much base-10)
699
- */
700
- function toString()
701
- {
702
- switch (MATH_BIGINTEGER_MODE) {
703
- case MATH_BIGINTEGER_MODE_GMP:
704
- return gmp_strval($this->value);
705
- case MATH_BIGINTEGER_MODE_BCMATH:
706
- if ($this->value === '0') {
707
- return '0';
708
- }
709
-
710
- return ltrim($this->value, '0');
711
- }
712
-
713
- if (!count($this->value)) {
714
- return '0';
715
- }
716
-
717
- $temp = $this->copy();
718
- $temp->is_negative = false;
719
-
720
- $divisor = new Math_BigInteger();
721
- $divisor->value = array(MATH_BIGINTEGER_MAX10);
722
- $result = '';
723
- while (count($temp->value)) {
724
- list($temp, $mod) = $temp->divide($divisor);
725
- $result = str_pad(isset($mod->value[0]) ? $mod->value[0] : '', MATH_BIGINTEGER_MAX10_LEN, '0', STR_PAD_LEFT) . $result;
726
- }
727
- $result = ltrim($result, '0');
728
- if (empty($result)) {
729
- $result = '0';
730
- }
731
-
732
- if ($this->is_negative) {
733
- $result = '-' . $result;
734
- }
735
-
736
- return $result;
737
- }
738
-
739
- function toInteger()
740
- {
741
- return (int) $this->toString();
742
- }
743
-
744
- /**
745
- * Copy an object
746
- *
747
- * PHP5 passes objects by reference while PHP4 passes by value. As such, we need a function to guarantee
748
- * that all objects are passed by value, when appropriate. More information can be found here:
749
- *
750
- * {@link http://php.net/language.oop5.basic#51624}
751
- *
752
- * @access public
753
- * @see self::__clone()
754
- * @return Math_BigInteger
755
- */
756
- function copy()
757
- {
758
- $temp = new Math_BigInteger();
759
- $temp->value = $this->value;
760
- $temp->is_negative = $this->is_negative;
761
- $temp->precision = $this->precision;
762
- $temp->bitmask = $this->bitmask;
763
- return $temp;
764
- }
765
-
766
- /**
767
- * __toString() magic method
768
- *
769
- * Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call
770
- * toString().
771
- *
772
- * @access public
773
- * @internal Implemented per a suggestion by Techie-Michael - thanks!
774
- */
775
- function __toString()
776
- {
777
- return $this->toString();
778
- }
779
-
780
- /**
781
- * __clone() magic method
782
- *
783
- * Although you can call Math_BigInteger::__toString() directly in PHP5, you cannot call Math_BigInteger::__clone()
784
- * directly in PHP5. You can in PHP4 since it's not a magic method, but in PHP5, you have to call it by using the PHP5
785
- * only syntax of $y = clone $x. As such, if you're trying to write an application that works on both PHP4 and PHP5,
786
- * call Math_BigInteger::copy(), instead.
787
- *
788
- * @access public
789
- * @see self::copy()
790
- * @return Math_BigInteger
791
- */
792
- function __clone()
793
- {
794
- return $this->copy();
795
- }
796
-
797
- /**
798
- * __sleep() magic method
799
- *
800
- * Will be called, automatically, when serialize() is called on a Math_BigInteger object.
801
- *
802
- * @see self::__wakeup()
803
- * @access public
804
- */
805
- function __sleep()
806
- {
807
- $this->hex = $this->toHex(true);
808
- $vars = array('hex');
809
- if ($this->precision > 0) {
810
- $vars[] = 'precision';
811
- }
812
- return $vars;
813
- }
814
-
815
- /**
816
- * __wakeup() magic method
817
- *
818
- * Will be called, automatically, when unserialize() is called on a Math_BigInteger object.
819
- *
820
- * @see self::__sleep()
821
- * @access public
822
- */
823
- function __wakeup()
824
- {
825
- $temp = new Math_BigInteger($this->hex, -16);
826
- $this->value = $temp->value;
827
- $this->is_negative = $temp->is_negative;
828
- if ($this->precision > 0) {
829
- // recalculate $this->bitmask
830
- $this->setPrecision($this->precision);
831
- }
832
- }
833
-
834
- /**
835
- * __debugInfo() magic method
836
- *
837
- * Will be called, automatically, when print_r() or var_dump() are called
838
- *
839
- * @access public
840
- */
841
- function __debugInfo()
842
- {
843
- $opts = array();
844
- switch (MATH_BIGINTEGER_MODE) {
845
- case MATH_BIGINTEGER_MODE_GMP:
846
- $engine = 'gmp';
847
- break;
848
- case MATH_BIGINTEGER_MODE_BCMATH:
849
- $engine = 'bcmath';
850
- break;
851
- case MATH_BIGINTEGER_MODE_INTERNAL:
852
- $engine = 'internal';
853
- $opts[] = PHP_INT_SIZE == 8 ? '64-bit' : '32-bit';
854
- }
855
- if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
856
- $opts[] = 'OpenSSL';
857
- }
858
- if (!empty($opts)) {
859
- $engine.= ' (' . implode($opts, ', ') . ')';
860
- }
861
- return array(
862
- 'value' => '0x' . $this->toHex(true),
863
- 'engine' => $engine
864
- );
865
- }
866
-
867
- /**
868
- * Adds two BigIntegers.
869
- *
870
- * Here's an example:
871
- * <code>
872
- * <?php
873
- * include 'Math/BigInteger.php';
874
- *
875
- * $a = new Math_BigInteger('10');
876
- * $b = new Math_BigInteger('20');
877
- *
878
- * $c = $a->add($b);
879
- *
880
- * echo $c->toString(); // outputs 30
881
- * ?>
882
- * </code>
883
- *
884
- * @param Math_BigInteger $y
885
- * @return Math_BigInteger
886
- * @access public
887
- * @internal Performs base-2**52 addition
888
- */
889
- function add($y)
890
- {
891
- switch (MATH_BIGINTEGER_MODE) {
892
- case MATH_BIGINTEGER_MODE_GMP:
893
- $temp = new Math_BigInteger();
894
- $temp->value = gmp_add($this->value, $y->value);
895
-
896
- return $this->_normalize($temp);
897
- case MATH_BIGINTEGER_MODE_BCMATH:
898
- $temp = new Math_BigInteger();
899
- $temp->value = bcadd($this->value, $y->value, 0);
900
-
901
- return $this->_normalize($temp);
902
- }
903
-
904
- $temp = $this->_add($this->value, $this->is_negative, $y->value, $y->is_negative);
905
-
906
- $result = new Math_BigInteger();
907
- $result->value = $temp[MATH_BIGINTEGER_VALUE];
908
- $result->is_negative = $temp[MATH_BIGINTEGER_SIGN];
909
-
910
- return $this->_normalize($result);
911
- }
912
-
913
- /**
914
- * Performs addition.
915
- *
916
- * @param array $x_value
917
- * @param bool $x_negative
918
- * @param array $y_value
919
- * @param bool $y_negative
920
- * @return array
921
- * @access private
922
- */
923
- function _add($x_value, $x_negative, $y_value, $y_negative)
924
- {
925
- $x_size = count($x_value);
926
- $y_size = count($y_value);
927
-
928
- if ($x_size == 0) {
929
- return array(
930
- MATH_BIGINTEGER_VALUE => $y_value,
931
- MATH_BIGINTEGER_SIGN => $y_negative
932
- );
933
- } elseif ($y_size == 0) {
934
- return array(
935
- MATH_BIGINTEGER_VALUE => $x_value,
936
- MATH_BIGINTEGER_SIGN => $x_negative
937
- );
938
- }
939
-
940
- // subtract, if appropriate
941
- if ($x_negative != $y_negative) {
942
- if ($x_value == $y_value) {
943
- return array(
944
- MATH_BIGINTEGER_VALUE => array(),
945
- MATH_BIGINTEGER_SIGN => false
946
- );
947
- }
948
-
949
- $temp = $this->_subtract($x_value, false, $y_value, false);
950
- $temp[MATH_BIGINTEGER_SIGN] = $this->_compare($x_value, false, $y_value, false) > 0 ?
951
- $x_negative : $y_negative;
952
-
953
- return $temp;
954
- }
955
-
956
- if ($x_size < $y_size) {
957
- $size = $x_size;
958
- $value = $y_value;
959
- } else {
960
- $size = $y_size;
961
- $value = $x_value;
962
- }
963
-
964
- $value[count($value)] = 0; // just in case the carry adds an extra digit
965
-
966
- $carry = 0;
967
- for ($i = 0, $j = 1; $j < $size; $i+=2, $j+=2) {
968
- $sum = $x_value[$j] * MATH_BIGINTEGER_BASE_FULL + $x_value[$i] + $y_value[$j] * MATH_BIGINTEGER_BASE_FULL + $y_value[$i] + $carry;
969
- $carry = $sum >= MATH_BIGINTEGER_MAX_DIGIT2; // eg. floor($sum / 2**52); only possible values (in any base) are 0 and 1
970
- $sum = $carry ? $sum - MATH_BIGINTEGER_MAX_DIGIT2 : $sum;
971
-
972
- $temp = MATH_BIGINTEGER_BASE === 26 ? intval($sum / 0x4000000) : ($sum >> 31);
973
-
974
- $value[$i] = (int) ($sum - MATH_BIGINTEGER_BASE_FULL * $temp); // eg. a faster alternative to fmod($sum, 0x4000000)
975
- $value[$j] = $temp;
976
- }
977
-
978
- if ($j == $size) { // ie. if $y_size is odd
979
- $sum = $x_value[$i] + $y_value[$i] + $carry;
980
- $carry = $sum >= MATH_BIGINTEGER_BASE_FULL;
981
- $value[$i] = $carry ? $sum - MATH_BIGINTEGER_BASE_FULL : $sum;
982
- ++$i; // ie. let $i = $j since we've just done $value[$i]
983
- }
984
-
985
- if ($carry) {
986
- for (; $value[$i] == MATH_BIGINTEGER_MAX_DIGIT; ++$i) {
987
- $value[$i] = 0;
988
- }
989
- ++$value[$i];
990
- }
991
-
992
- return array(
993
- MATH_BIGINTEGER_VALUE => $this->_trim($value),
994
- MATH_BIGINTEGER_SIGN => $x_negative
995
- );
996
- }
997
-
998
- /**
999
- * Subtracts two BigIntegers.
1000
- *
1001
- * Here's an example:
1002
- * <code>
1003
- * <?php
1004
- * include 'Math/BigInteger.php';
1005
- *
1006
- * $a = new Math_BigInteger('10');
1007
- * $b = new Math_BigInteger('20');
1008
- *
1009
- * $c = $a->subtract($b);
1010
- *
1011
- * echo $c->toString(); // outputs -10
1012
- * ?>
1013
- * </code>
1014
- *
1015
- * @param Math_BigInteger $y
1016
- * @return Math_BigInteger
1017
- * @access public
1018
- * @internal Performs base-2**52 subtraction
1019
- */
1020
- function subtract($y)
1021
- {
1022
- switch (MATH_BIGINTEGER_MODE) {
1023
- case MATH_BIGINTEGER_MODE_GMP:
1024
- $temp = new Math_BigInteger();
1025
- $temp->value = gmp_sub($this->value, $y->value);
1026
-
1027
- return $this->_normalize($temp);
1028
- case MATH_BIGINTEGER_MODE_BCMATH:
1029
- $temp = new Math_BigInteger();
1030
- $temp->value = bcsub($this->value, $y->value, 0);
1031
-
1032
- return $this->_normalize($temp);
1033
- }
1034
-
1035
- $temp = $this->_subtract($this->value, $this->is_negative, $y->value, $y->is_negative);
1036
-
1037
- $result = new Math_BigInteger();
1038
- $result->value = $temp[MATH_BIGINTEGER_VALUE];
1039
- $result->is_negative = $temp[MATH_BIGINTEGER_SIGN];
1040
-
1041
- return $this->_normalize($result);
1042
- }
1043
-
1044
- /**
1045
- * Performs subtraction.
1046
- *
1047
- * @param array $x_value
1048
- * @param bool $x_negative
1049
- * @param array $y_value
1050
- * @param bool $y_negative
1051
- * @return array
1052
- * @access private
1053
- */
1054
- function _subtract($x_value, $x_negative, $y_value, $y_negative)
1055
- {
1056
- $x_size = count($x_value);
1057
- $y_size = count($y_value);
1058
-
1059
- if ($x_size == 0) {
1060
- return array(
1061
- MATH_BIGINTEGER_VALUE => $y_value,
1062
- MATH_BIGINTEGER_SIGN => !$y_negative
1063
- );
1064
- } elseif ($y_size == 0) {
1065
- return array(
1066
- MATH_BIGINTEGER_VALUE => $x_value,
1067
- MATH_BIGINTEGER_SIGN => $x_negative
1068
- );
1069
- }
1070
-
1071
- // add, if appropriate (ie. -$x - +$y or +$x - -$y)
1072
- if ($x_negative != $y_negative) {
1073
- $temp = $this->_add($x_value, false, $y_value, false);
1074
- $temp[MATH_BIGINTEGER_SIGN] = $x_negative;
1075
-
1076
- return $temp;
1077
- }
1078
-
1079
- $diff = $this->_compare($x_value, $x_negative, $y_value, $y_negative);
1080
-
1081
- if (!$diff) {
1082
- return array(
1083
- MATH_BIGINTEGER_VALUE => array(),
1084
- MATH_BIGINTEGER_SIGN => false
1085
- );
1086
- }
1087
-
1088
- // switch $x and $y around, if appropriate.
1089
- if ((!$x_negative && $diff < 0) || ($x_negative && $diff > 0)) {
1090
- $temp = $x_value;
1091
- $x_value = $y_value;
1092
- $y_value = $temp;
1093
-
1094
- $x_negative = !$x_negative;
1095
-
1096
- $x_size = count($x_value);
1097
- $y_size = count($y_value);
1098
- }
1099
-
1100
- // at this point, $x_value should be at least as big as - if not bigger than - $y_value
1101
-
1102
- $carry = 0;
1103
- for ($i = 0, $j = 1; $j < $y_size; $i+=2, $j+=2) {
1104
- $sum = $x_value[$j] * MATH_BIGINTEGER_BASE_FULL + $x_value[$i] - $y_value[$j] * MATH_BIGINTEGER_BASE_FULL - $y_value[$i] - $carry;
1105
- $carry = $sum < 0; // eg. floor($sum / 2**52); only possible values (in any base) are 0 and 1
1106
- $sum = $carry ? $sum + MATH_BIGINTEGER_MAX_DIGIT2 : $sum;
1107
-
1108
- $temp = MATH_BIGINTEGER_BASE === 26 ? intval($sum / 0x4000000) : ($sum >> 31);
1109
-
1110
- $x_value[$i] = (int) ($sum - MATH_BIGINTEGER_BASE_FULL * $temp);
1111
- $x_value[$j] = $temp;
1112
- }
1113
-
1114
- if ($j == $y_size) { // ie. if $y_size is odd
1115
- $sum = $x_value[$i] - $y_value[$i] - $carry;
1116
- $carry = $sum < 0;
1117
- $x_value[$i] = $carry ? $sum + MATH_BIGINTEGER_BASE_FULL : $sum;
1118
- ++$i;
1119
- }
1120
-
1121
- if ($carry) {
1122
- for (; !$x_value[$i]; ++$i) {
1123
- $x_value[$i] = MATH_BIGINTEGER_MAX_DIGIT;
1124
- }
1125
- --$x_value[$i];
1126
- }
1127
-
1128
- return array(
1129
- MATH_BIGINTEGER_VALUE => $this->_trim($x_value),
1130
- MATH_BIGINTEGER_SIGN => $x_negative
1131
- );
1132
- }
1133
-
1134
- /**
1135
- * Multiplies two BigIntegers
1136
- *
1137
- * Here's an example:
1138
- * <code>
1139
- * <?php
1140
- * include 'Math/BigInteger.php';
1141
- *
1142
- * $a = new Math_BigInteger('10');
1143
- * $b = new Math_BigInteger('20');
1144
- *
1145
- * $c = $a->multiply($b);
1146
- *
1147
- * echo $c->toString(); // outputs 200
1148
- * ?>
1149
- * </code>
1150
- *
1151
- * @param Math_BigInteger $x
1152
- * @return Math_BigInteger
1153
- * @access public
1154
- */
1155
- function multiply($x)
1156
- {
1157
- switch (MATH_BIGINTEGER_MODE) {
1158
- case MATH_BIGINTEGER_MODE_GMP:
1159
- $temp = new Math_BigInteger();
1160
- $temp->value = gmp_mul($this->value, $x->value);
1161
-
1162
- return $this->_normalize($temp);
1163
- case MATH_BIGINTEGER_MODE_BCMATH:
1164
- $temp = new Math_BigInteger();
1165
- $temp->value = bcmul($this->value, $x->value, 0);
1166
-
1167
- return $this->_normalize($temp);
1168
- }
1169
-
1170
- $temp = $this->_multiply($this->value, $this->is_negative, $x->value, $x->is_negative);
1171
-
1172
- $product = new Math_BigInteger();
1173
- $product->value = $temp[MATH_BIGINTEGER_VALUE];
1174
- $product->is_negative = $temp[MATH_BIGINTEGER_SIGN];
1175
-
1176
- return $this->_normalize($product);
1177
- }
1178
-
1179
- /**
1180
- * Performs multiplication.
1181
- *
1182
- * @param array $x_value
1183
- * @param bool $x_negative
1184
- * @param array $y_value
1185
- * @param bool $y_negative
1186
- * @return array
1187
- * @access private
1188
- */
1189
- function _multiply($x_value, $x_negative, $y_value, $y_negative)
1190
- {
1191
- //if ( $x_value == $y_value ) {
1192
- // return array(
1193
- // MATH_BIGINTEGER_VALUE => $this->_square($x_value),
1194
- // MATH_BIGINTEGER_SIGN => $x_sign != $y_value
1195
- // );
1196
- //}
1197
-
1198
- $x_length = count($x_value);
1199
- $y_length = count($y_value);
1200
-
1201
- if (!$x_length || !$y_length) { // a 0 is being multiplied
1202
- return array(
1203
- MATH_BIGINTEGER_VALUE => array(),
1204
- MATH_BIGINTEGER_SIGN => false
1205
- );
1206
- }
1207
-
1208
- return array(
1209
- MATH_BIGINTEGER_VALUE => min($x_length, $y_length) < 2 * MATH_BIGINTEGER_KARATSUBA_CUTOFF ?
1210
- $this->_trim($this->_regularMultiply($x_value, $y_value)) :
1211
- $this->_trim($this->_karatsuba($x_value, $y_value)),
1212
- MATH_BIGINTEGER_SIGN => $x_negative != $y_negative
1213
- );
1214
- }
1215
-
1216
- /**
1217
- * Performs long multiplication on two BigIntegers
1218
- *
1219
- * Modeled after 'multiply' in MutableBigInteger.java.
1220
- *
1221
- * @param array $x_value
1222
- * @param array $y_value
1223
- * @return array
1224
- * @access private
1225
- */
1226
- function _regularMultiply($x_value, $y_value)
1227
- {
1228
- $x_length = count($x_value);
1229
- $y_length = count($y_value);
1230
-
1231
- if (!$x_length || !$y_length) { // a 0 is being multiplied
1232
- return array();
1233
- }
1234
-
1235
- if ($x_length < $y_length) {
1236
- $temp = $x_value;
1237
- $x_value = $y_value;
1238
- $y_value = $temp;
1239
-
1240
- $x_length = count($x_value);
1241
- $y_length = count($y_value);
1242
- }
1243
-
1244
- $product_value = $this->_array_repeat(0, $x_length + $y_length);
1245
-
1246
- // the following for loop could be removed if the for loop following it
1247
- // (the one with nested for loops) initially set $i to 0, but
1248
- // doing so would also make the result in one set of unnecessary adds,
1249
- // since on the outermost loops first pass, $product->value[$k] is going
1250
- // to always be 0
1251
-
1252
- $carry = 0;
1253
-
1254
- for ($j = 0; $j < $x_length; ++$j) { // ie. $i = 0
1255
- $temp = $x_value[$j] * $y_value[0] + $carry; // $product_value[$k] == 0
1256
- $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1257
- $product_value[$j] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1258
- }
1259
-
1260
- $product_value[$j] = $carry;
1261
-
1262
- // the above for loop is what the previous comment was talking about. the
1263
- // following for loop is the "one with nested for loops"
1264
- for ($i = 1; $i < $y_length; ++$i) {
1265
- $carry = 0;
1266
-
1267
- for ($j = 0, $k = $i; $j < $x_length; ++$j, ++$k) {
1268
- $temp = $product_value[$k] + $x_value[$j] * $y_value[$i] + $carry;
1269
- $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1270
- $product_value[$k] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1271
- }
1272
-
1273
- $product_value[$k] = $carry;
1274
- }
1275
-
1276
- return $product_value;
1277
- }
1278
-
1279
- /**
1280
- * Performs Karatsuba multiplication on two BigIntegers
1281
- *
1282
- * See {@link http://en.wikipedia.org/wiki/Karatsuba_algorithm Karatsuba algorithm} and
1283
- * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=120 MPM 5.2.3}.
1284
- *
1285
- * @param array $x_value
1286
- * @param array $y_value
1287
- * @return array
1288
- * @access private
1289
- */
1290
- function _karatsuba($x_value, $y_value)
1291
- {
1292
- $m = min(count($x_value) >> 1, count($y_value) >> 1);
1293
-
1294
- if ($m < MATH_BIGINTEGER_KARATSUBA_CUTOFF) {
1295
- return $this->_regularMultiply($x_value, $y_value);
1296
- }
1297
-
1298
- $x1 = array_slice($x_value, $m);
1299
- $x0 = array_slice($x_value, 0, $m);
1300
- $y1 = array_slice($y_value, $m);
1301
- $y0 = array_slice($y_value, 0, $m);
1302
-
1303
- $z2 = $this->_karatsuba($x1, $y1);
1304
- $z0 = $this->_karatsuba($x0, $y0);
1305
-
1306
- $z1 = $this->_add($x1, false, $x0, false);
1307
- $temp = $this->_add($y1, false, $y0, false);
1308
- $z1 = $this->_karatsuba($z1[MATH_BIGINTEGER_VALUE], $temp[MATH_BIGINTEGER_VALUE]);
1309
- $temp = $this->_add($z2, false, $z0, false);
1310
- $z1 = $this->_subtract($z1, false, $temp[MATH_BIGINTEGER_VALUE], false);
1311
-
1312
- $z2 = array_merge(array_fill(0, 2 * $m, 0), $z2);
1313
- $z1[MATH_BIGINTEGER_VALUE] = array_merge(array_fill(0, $m, 0), $z1[MATH_BIGINTEGER_VALUE]);
1314
-
1315
- $xy = $this->_add($z2, false, $z1[MATH_BIGINTEGER_VALUE], $z1[MATH_BIGINTEGER_SIGN]);
1316
- $xy = $this->_add($xy[MATH_BIGINTEGER_VALUE], $xy[MATH_BIGINTEGER_SIGN], $z0, false);
1317
-
1318
- return $xy[MATH_BIGINTEGER_VALUE];
1319
- }
1320
-
1321
- /**
1322
- * Performs squaring
1323
- *
1324
- * @param array $x
1325
- * @return array
1326
- * @access private
1327
- */
1328
- function _square($x = false)
1329
- {
1330
- return count($x) < 2 * MATH_BIGINTEGER_KARATSUBA_CUTOFF ?
1331
- $this->_trim($this->_baseSquare($x)) :
1332
- $this->_trim($this->_karatsubaSquare($x));
1333
- }
1334
-
1335
- /**
1336
- * Performs traditional squaring on two BigIntegers
1337
- *
1338
- * Squaring can be done faster than multiplying a number by itself can be. See
1339
- * {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=7 HAC 14.2.4} /
1340
- * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=141 MPM 5.3} for more information.
1341
- *
1342
- * @param array $value
1343
- * @return array
1344
- * @access private
1345
- */
1346
- function _baseSquare($value)
1347
- {
1348
- if (empty($value)) {
1349
- return array();
1350
- }
1351
- $square_value = $this->_array_repeat(0, 2 * count($value));
1352
-
1353
- for ($i = 0, $max_index = count($value) - 1; $i <= $max_index; ++$i) {
1354
- $i2 = $i << 1;
1355
-
1356
- $temp = $square_value[$i2] + $value[$i] * $value[$i];
1357
- $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1358
- $square_value[$i2] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1359
-
1360
- // note how we start from $i+1 instead of 0 as we do in multiplication.
1361
- for ($j = $i + 1, $k = $i2 + 1; $j <= $max_index; ++$j, ++$k) {
1362
- $temp = $square_value[$k] + 2 * $value[$j] * $value[$i] + $carry;
1363
- $carry = MATH_BIGINTEGER_BASE === 26 ? intval($temp / 0x4000000) : ($temp >> 31);
1364
- $square_value[$k] = (int) ($temp - MATH_BIGINTEGER_BASE_FULL * $carry);
1365
- }
1366
-
1367
- // the following line can yield values larger 2**15. at this point, PHP should switch
1368
- // over to floats.
1369
- $square_value[$i + $max_index + 1] = $carry;
1370
- }
1371
-
1372
- return $square_value;
1373
- }
1374
-
1375
- /**
1376
- * Performs Karatsuba "squaring" on two BigIntegers
1377
- *
1378
- * See {@link http://en.wikipedia.org/wiki/Karatsuba_algorithm Karatsuba algorithm} and
1379
- * {@link http://math.libtomcrypt.com/files/tommath.pdf#page=151 MPM 5.3.4}.
1380
- *
1381
- * @param array $value
1382
- * @return array
1383
- * @access private
1384
- */
1385
- function _karatsubaSquare($value)
1386
- {
1387
- $m = count($value) >> 1;
1388
-
1389
- if ($m < MATH_BIGINTEGER_KARATSUBA_CUTOFF) {
1390
- return $this->_baseSquare($value);
1391
- }
1392
-
1393
- $x1 = array_slice($value, $m);
1394
- $x0 = array_slice($value, 0, $m);
1395
-
1396
- $z2 = $this->_karatsubaSquare($x1);
1397
- $z0 = $this->_karatsubaSquare($x0);
1398
-
1399
- $z1 = $this->_add($x1, false, $x0, false);
1400
- $z1 = $this->_karatsubaSquare($z1[MATH_BIGINTEGER_VALUE]);
1401
- $temp = $this->_add($z2, false, $z0, false);
1402
- $z1 = $this->_subtract($z1, false, $temp[MATH_BIGINTEGER_VALUE], false);
1403
-
1404
- $z2 = array_merge(array_fill(0, 2 * $m, 0), $z2);
1405
- $z1[MATH_BIGINTEGER_VALUE] = array_merge(array_fill(0, $m, 0), $z1[MATH_BIGINTEGER_VALUE]);
1406
-
1407
- $xx = $this->_add($z2, false, $z1[MATH_BIGINTEGER_VALUE], $z1[MATH_BIGINTEGER_SIGN]);
1408
- $xx = $this->_add($xx[MATH_BIGINTEGER_VALUE], $xx[MATH_BIGINTEGER_SIGN], $z0, false);
1409
-
1410
- return $xx[MATH_BIGINTEGER_VALUE];
1411
- }
1412
-
1413
- /**
1414
- * Divides two BigIntegers.
1415
- *
1416
- * Returns an array whose first element contains the quotient and whose second element contains the
1417
- * "common residue". If the remainder would be positive, the "common residue" and the remainder are the
1418
- * same. If the remainder would be negative, the "common residue" is equal to the sum of the remainder
1419
- * and the divisor (basically, the "common residue" is the first positive modulo).
1420
- *
1421
- * Here's an example:
1422
- * <code>
1423
- * <?php
1424
- * include 'Math/BigInteger.php';
1425
- *
1426
- * $a = new Math_BigInteger('10');
1427
- * $b = new Math_BigInteger('20');
1428
- *
1429
- * list($quotient, $remainder) = $a->divide($b);
1430
- *
1431
- * echo $quotient->toString(); // outputs 0
1432
- * echo "\r\n";
1433
- * echo $remainder->toString(); // outputs 10
1434
- * ?>
1435
- * </code>
1436
- *
1437
- * @param Math_BigInteger $y
1438
- * @return array
1439
- * @access public
1440
- * @internal This function is based off of {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=9 HAC 14.20}.
1441
- */
1442
- function divide($y)
1443
- {
1444
- switch (MATH_BIGINTEGER_MODE) {
1445
- case MATH_BIGINTEGER_MODE_GMP:
1446
- $quotient = new Math_BigInteger();
1447
- $remainder = new Math_BigInteger();
1448
-
1449
- list($quotient->value, $remainder->value) = gmp_div_qr($this->value, $y->value);
1450
-
1451
- if (gmp_sign($remainder->value) < 0) {
1452
- $remainder->value = gmp_add($remainder->value, gmp_abs($y->value));
1453
- }
1454
-
1455
- return array($this->_normalize($quotient), $this->_normalize($remainder));
1456
- case MATH_BIGINTEGER_MODE_BCMATH:
1457
- $quotient = new Math_BigInteger();
1458
- $remainder = new Math_BigInteger();
1459
-
1460
- $quotient->value = bcdiv($this->value, $y->value, 0);
1461
- $remainder->value = bcmod($this->value, $y->value);
1462
-
1463
- if ($remainder->value[0] == '-') {
1464
- $remainder->value = bcadd($remainder->value, $y->value[0] == '-' ? substr($y->value, 1) : $y->value, 0);
1465
- }
1466
-
1467
- return array($this->_normalize($quotient), $this->_normalize($remainder));
1468
- }
1469
-
1470
- if (count($y->value) == 1) {
1471
- list($q, $r) = $this->_divide_digit($this->value, $y->value[0]);
1472
- $quotient = new Math_BigInteger();
1473
- $remainder = new Math_BigInteger();
1474
- $quotient->value = $q;
1475
- $remainder->value = array($r);
1476
- $quotient->is_negative = $this->is_negative != $y->is_negative;
1477
- return array($this->_normalize($quotient), $this->_normalize($remainder));
1478
- }
1479
-
1480
- static $zero;
1481
- if (!isset($zero)) {
1482
- $zero = new Math_BigInteger();
1483
- }
1484
-
1485
- $x = $this->copy();
1486
- $y = $y->copy();
1487
-
1488
- $x_sign = $x->is_negative;
1489
- $y_sign = $y->is_negative;
1490
-
1491
- $x->is_negative = $y->is_negative = false;
1492
-
1493
- $diff = $x->compare($y);
1494
-
1495
- if (!$diff) {
1496
- $temp = new Math_BigInteger();
1497
- $temp->value = array(1);
1498
- $temp->is_negative = $x_sign != $y_sign;
1499
- return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger()));
1500
- }
1501
-
1502
- if ($diff < 0) {
1503
- // if $x is negative, "add" $y.
1504
- if ($x_sign) {
1505
- $x = $y->subtract($x);
1506
- }
1507
- return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x));
1508
- }
1509
-
1510
- // normalize $x and $y as described in HAC 14.23 / 14.24
1511
- $msb = $y->value[count($y->value) - 1];
1512
- for ($shift = 0; !($msb & MATH_BIGINTEGER_MSB); ++$shift) {
1513
- $msb <<= 1;
1514
- }
1515
- $x->_lshift($shift);
1516
- $y->_lshift($shift);
1517
- $y_value = &$y->value;
1518
-
1519
- $x_max = count($x->value) - 1;
1520
- $y_max = count($y->value) - 1;
1521
-
1522
- $quotient = new Math_BigInteger();
1523
- $quotient_value = &$quotient->value;
1524
- $quotient_value = $this->_array_repeat(0, $x_max - $y_max + 1);
1525
-
1526
- static $temp, $lhs, $rhs;
1527
- if (!isset($temp)) {
1528
- $temp = new Math_BigInteger();
1529
- $lhs = new Math_BigInteger();
1530
- $rhs = new Math_BigInteger();
1531
- }
1532
- $temp_value = &$temp->value;
1533
- $rhs_value = &$rhs->value;
1534
-
1535
- // $temp = $y << ($x_max - $y_max-1) in base 2**26
1536
- $temp_value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y_value);
1537
-
1538
- while ($x->compare($temp) >= 0) {
1539
- // calculate the "common residue"
1540
- ++$quotient_value[$x_max - $y_max];
1541
- $x = $x->subtract($temp);
1542
- $x_max = count($x->value) - 1;
1543
- }
1544
-
1545
- for ($i = $x_max; $i >= $y_max + 1; --$i) {
1546
- $x_value = &$x->value;
1547
- $x_window = array(
1548
- isset($x_value[$i]) ? $x_value[$i] : 0,
1549
- isset($x_value[$i - 1]) ? $x_value[$i - 1] : 0,
1550
- isset($x_value[$i - 2]) ? $x_value[$i - 2] : 0
1551
- );
1552
- $y_window = array(
1553
- $y_value[$y_max],
1554
- ($y_max > 0) ? $y_value[$y_max - 1] : 0
1555
- );
1556
-
1557
- $q_index = $i - $y_max - 1;
1558
- if ($x_window[0] == $y_window[0]) {
1559
- $quotient_value[$q_index] = MATH_BIGINTEGER_MAX_DIGIT;
1560
- } else {
1561
- $quotient_value[$q_index] = $this->_safe_divide(
1562
- $x_window[0] * MATH_BIGINTEGER_BASE_FULL + $x_window[1],
1563
- $y_window[0]
1564
- );
1565
- }
1566
-
1567
- $temp_value = array($y_window[1], $y_window[0]);
1568
-
1569
- $lhs->value = array($quotient_value[$q_index]);
1570
- $lhs = $lhs->multiply($temp);
1571
-
1572
- $rhs_value = array($x_window[2], $x_window[1], $x_window[0]);
1573
-
1574
- while ($lhs->compare($rhs) > 0) {
1575
- --$quotient_value[$q_index];
1576
-
1577
- $lhs->value = array($quotient_value[$q_index]);
1578
- $lhs = $lhs->multiply($temp);
1579
- }
1580
-
1581
- $adjust = $this->_array_repeat(0, $q_index);
1582
- $temp_value = array($quotient_value[$q_index]);
1583
- $temp = $temp->multiply($y);
1584
- $temp_value = &$temp->value;
1585
- $temp_value = array_merge($adjust, $temp_value);
1586
-
1587
- $x = $x->subtract($temp);
1588
-
1589
- if ($x->compare($zero) < 0) {
1590
- $temp_value = array_merge($adjust, $y_value);
1591
- $x = $x->add($temp);
1592
-
1593
- --$quotient_value[$q_index];
1594
- }
1595
-
1596
- $x_max = count($x_value) - 1;
1597
- }
1598
-
1599
- // unnormalize the remainder
1600
- $x->_rshift($shift);
1601
-
1602
- $quotient->is_negative = $x_sign != $y_sign;
1603
-
1604
- // calculate the "common residue", if appropriate
1605
- if ($x_sign) {
1606
- $y->_rshift($shift);
1607
- $x = $y->subtract($x);
1608
- }
1609
-
1610
- return array($this->_normalize($quotient), $this->_normalize($x));
1611
- }
1612
-
1613
- /**
1614
- * Divides a BigInteger by a regular integer
1615
- *
1616
- * abc / x = a00 / x + b0 / x + c / x
1617
- *
1618
- * @param array $dividend
1619
- * @param array $divisor
1620
- * @return array
1621
- * @access private
1622
- */
1623
- function _divide_digit($dividend, $divisor)
1624
- {
1625
- $carry = 0;
1626
- $result = array();
1627
-
1628
- for ($i = count($dividend) - 1; $i >= 0; --$i) {
1629
- $temp = MATH_BIGINTEGER_BASE_FULL * $carry + $dividend[$i];
1630
- $result[$i] = $this->_safe_divide($temp, $divisor);
1631
- $carry = (int) ($temp - $divisor * $result[$i]);
1632
- }
1633
-
1634
- return array($result, $carry);
1635
- }
1636
-
1637
- /**
1638
- * Performs modular exponentiation.
1639
- *
1640
- * Here's an example:
1641
- * <code>
1642
- * <?php
1643
- * include 'Math/BigInteger.php';
1644
- *
1645
- * $a = new Math_BigInteger('10');
1646
- * $b = new Math_BigInteger('20');
1647
- * $c = new Math_BigInteger('30');
1648
- *
1649
- * $c = $a->modPow($b, $c);
1650
- *
1651
- * echo $c->toString(); // outputs 10
1652
- * ?>
1653
- * </code>
1654
- *
1655
- * @param Math_BigInteger $e
1656
- * @param Math_BigInteger $n
1657
- * @return Math_BigInteger
1658
- * @access public
1659
- * @internal The most naive approach to modular exponentiation has very unreasonable requirements, and
1660
- * and although the approach involving repeated squaring does vastly better, it, too, is impractical
1661
- * for our purposes. The reason being that division - by far the most complicated and time-consuming
1662
- * of the basic operations (eg. +,-,*,/) - occurs multiple times within it.
1663
- *
1664
- * Modular reductions resolve this issue. Although an individual modular reduction takes more time
1665
- * then an individual division, when performed in succession (with the same modulo), they're a lot faster.
1666
- *
1667
- * The two most commonly used modular reductions are Barrett and Montgomery reduction. Montgomery reduction,
1668
- * although faster, only works when the gcd of the modulo and of the base being used is 1. In RSA, when the
1669
- * base is a power of two, the modulo - a product of two primes - is always going to have a gcd of 1 (because
1670
- * the product of two odd numbers is odd), but what about when RSA isn't used?
1671
- *
1672
- * In contrast, Barrett reduction has no such constraint. As such, some bigint implementations perform a
1673
- * Barrett reduction after every operation in the modpow function. Others perform Barrett reductions when the
1674
- * modulo is even and Montgomery reductions when the modulo is odd. BigInteger.java's modPow method, however,
1675
- * uses a trick involving the Chinese Remainder Theorem to factor the even modulo into two numbers - one odd and
1676
- * the other, a power of two - and recombine them, later. This is the method that this modPow function uses.
1677
- * {@link http://islab.oregonstate.edu/papers/j34monex.pdf Montgomery Reduction with Even Modulus} elaborates.
1678
- */
1679
- function modPow($e, $n)
1680
- {
1681
- $n = $this->bitmask !== false && $this->bitmask->compare($n) < 0 ? $this->bitmask : $n->abs();
1682
-
1683
- if ($e->compare(new Math_BigInteger()) < 0) {
1684
- $e = $e->abs();
1685
-
1686
- $temp = $this->modInverse($n);
1687
- if ($temp === false) {
1688
- return false;
1689
- }
1690
-
1691
- return $this->_normalize($temp->modPow($e, $n));
1692
- }
1693
-
1694
- if (MATH_BIGINTEGER_MODE == MATH_BIGINTEGER_MODE_GMP) {
1695
- $temp = new Math_BigInteger();
1696
- $temp->value = gmp_powm($this->value, $e->value, $n->value);
1697
-
1698
- return $this->_normalize($temp);
1699
- }
1700
-
1701
- if ($this->compare(new Math_BigInteger()) < 0 || $this->compare($n) > 0) {
1702
- list(, $temp) = $this->divide($n);
1703
- return $temp->modPow($e, $n);
1704
- }
1705
-
1706
- if (defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) {
1707
- $components = array(
1708
- 'modulus' => $n->toBytes(true),
1709
- 'publicExponent' => $e->toBytes(true)
1710
- );
1711
-
1712
- $components = array(
1713
- 'modulus' => pack('Ca*a*', 2, $this->_encodeASN1Length(strlen($components['modulus'])), $components['modulus']),
1714
- 'publicExponent' => pack('Ca*a*', 2, $this->_encodeASN1Length(strlen($components['publicExponent'])), $components['publicExponent'])
1715
- );
1716
-
1717
- $RSAPublicKey = pack(