ai.touchui-vue 1.30.2 → 1.30.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (724) hide show
  1. package/README.md +21 -21
  2. package/lib/ai.touchui-vue.common.js +2087 -2092
  3. package/lib/chat.js +5 -5
  4. package/lib/collapse.js +2 -1
  5. package/lib/color.js +5 -5
  6. package/lib/date-picker.js +2 -1
  7. package/lib/date-range.js +11 -12
  8. package/lib/export.js +3 -3
  9. package/lib/index.js +1 -1
  10. package/lib/locale/format.js +10 -10
  11. package/lib/menu-icon.js +295 -295
  12. package/lib/mixins/migrating.js +20 -20
  13. package/lib/mixins/transition.js +14 -14
  14. package/lib/org.js +2 -1
  15. package/lib/page.js +2 -1
  16. package/lib/range.js +3 -3
  17. package/lib/static/{net-mix.293a4b6.svg → net-mix.dc6e414.svg} +7 -7
  18. package/lib/table.js +734 -740
  19. package/lib/utils/clickoutside.js +11 -11
  20. package/lib/utils/dom.js +13 -13
  21. package/lib/utils/filetransfer.js +4 -4
  22. package/lib/utils/jsencrypt/JSEncrypt.js +77 -77
  23. package/lib/utils/jsencrypt/JSEncryptRSAKey.js +115 -115
  24. package/lib/utils/jsencrypt/jselib/asn1js/asn1.js +4 -4
  25. package/lib/utils/jsencrypt/jselib/jsrsasign/asn1-1.0.js +734 -734
  26. package/lib/utils/jsencrypt/jselib/jsrsasign/yahoo.js +22 -22
  27. package/lib/utils/jsencrypt.js +260 -260
  28. package/lib/utils/md5.js +3 -3
  29. package/lib/utils/mime.js +2 -2
  30. package/lib/utils/ratio.js +54 -53
  31. package/lib/utils/sign.js +12 -12
  32. package/lib/utils/util.js +3 -3
  33. package/lib/utils/validate.js +11 -11
  34. package/package.json +159 -159
  35. package/packages/affix/index.js +8 -8
  36. package/packages/affix/src/affix.vue +139 -139
  37. package/packages/align/index.js +8 -8
  38. package/packages/align/src/directive.js +29 -29
  39. package/packages/animation/index.js +8 -8
  40. package/packages/animation/src/animation.vue +68 -68
  41. package/packages/article/index.js +8 -8
  42. package/packages/article/src/article.vue +23 -23
  43. package/packages/box/index.js +8 -8
  44. package/packages/box/src/box.vue +170 -170
  45. package/packages/button/index.js +8 -8
  46. package/packages/button/src/button.vue +162 -162
  47. package/packages/calendar/index.js +8 -8
  48. package/packages/calendar/src/calendar.vue +1142 -1142
  49. package/packages/card/index.js +10 -10
  50. package/packages/card/src/card-item.vue +92 -92
  51. package/packages/card/src/card.vue +175 -175
  52. package/packages/card-item/index.js +8 -8
  53. package/packages/cascader/index.js +8 -8
  54. package/packages/cascader/src/cascader.vue +814 -814
  55. package/packages/center-scroll/index.js +8 -8
  56. package/packages/center-scroll/src/center-scroll.vue +147 -147
  57. package/packages/chat/index.js +12 -12
  58. package/packages/chat/src/chat.vue +116 -116
  59. package/packages/checkbox/index.js +8 -8
  60. package/packages/checkbox/src/checkbox.vue +262 -262
  61. package/packages/checkboxes/index.js +8 -8
  62. package/packages/checkboxes/src/checkboxes.vue +97 -97
  63. package/packages/collapse/index.js +10 -10
  64. package/packages/collapse/src/collapse-item.vue +188 -188
  65. package/packages/collapse/src/collapse.vue +100 -100
  66. package/packages/color/index.js +8 -8
  67. package/packages/color/src/directive.js +42 -42
  68. package/packages/countdown/index.js +8 -8
  69. package/packages/countdown/src/countdown.vue +128 -128
  70. package/packages/date-picker/index.js +8 -8
  71. package/packages/date-picker/src/date-picker.vue +432 -432
  72. package/packages/date-picker/src/picker.vue +342 -342
  73. package/packages/date-range/index.js +8 -8
  74. package/packages/date-range/src/date-range.vue +384 -384
  75. package/packages/dialog/index.js +8 -8
  76. package/packages/dialog/src/dialog.vue +287 -287
  77. package/packages/dis/index.js +8 -8
  78. package/packages/dis/src/directive.js +42 -42
  79. package/packages/ellipsis/index.js +8 -8
  80. package/packages/ellipsis/src/ellipsis.vue +306 -306
  81. package/packages/emote/index.js +8 -8
  82. package/packages/emote/src/emote.vue +38 -38
  83. package/packages/export/index.js +8 -8
  84. package/packages/export/src/ajax.js +73 -73
  85. package/packages/export/src/export.vue +289 -289
  86. package/packages/filter/index.js +8 -8
  87. package/packages/filter/src/filter.vue +245 -245
  88. package/packages/fix/index.js +8 -8
  89. package/packages/fix/src/fix.vue +221 -221
  90. package/packages/float/index.js +16 -16
  91. package/packages/float/src/directive.js +20 -20
  92. package/packages/float/src/main.vue +642 -642
  93. package/packages/float/src/trigger.vue +31 -31
  94. package/packages/flow/index.js +8 -8
  95. package/packages/flow/src/flow.vue +234 -234
  96. package/packages/flow/src/flowItem.vue +61 -61
  97. package/packages/flow/src/flowLine.vue +168 -168
  98. package/packages/form/index.js +10 -10
  99. package/packages/form/src/form-item.vue +96 -96
  100. package/packages/form/src/form.vue +184 -184
  101. package/packages/grid/index.js +10 -10
  102. package/packages/grid/src/grid-item.vue +65 -65
  103. package/packages/grid/src/grid.vue +190 -190
  104. package/packages/grid-item/index.js +8 -8
  105. package/packages/guider/index.js +8 -8
  106. package/packages/guider/src/guider.vue +168 -168
  107. package/packages/header/index.js +8 -8
  108. package/packages/header/src/header.vue +111 -111
  109. package/packages/hide/index.js +8 -8
  110. package/packages/hide/src/directive.js +57 -57
  111. package/packages/icon/index.js +8 -8
  112. package/packages/icon/src/icon.vue +79 -79
  113. package/packages/import/index.js +8 -8
  114. package/packages/import/src/import.vue +279 -279
  115. package/packages/input/index.js +8 -8
  116. package/packages/input/src/calcTextareaHeight.js +104 -104
  117. package/packages/input/src/input.vue +653 -653
  118. package/packages/ip/index.js +8 -8
  119. package/packages/ip/src/ip.vue +143 -143
  120. package/packages/line/index.js +8 -8
  121. package/packages/line/src/line.vue +29 -29
  122. package/packages/loading/index.js +8 -8
  123. package/packages/loading/src/loading.js +58 -58
  124. package/packages/longtap/index.js +8 -8
  125. package/packages/longtap/src/longtap.js +95 -95
  126. package/packages/menu-icon/index.js +8 -8
  127. package/packages/menu-icon/src/menu-icon.vue +206 -206
  128. package/packages/message/index.js +8 -8
  129. package/packages/message/src/message.vue +9 -9
  130. package/packages/msg/index.js +8 -8
  131. package/packages/msg/src/msg.vue +227 -227
  132. package/packages/org/index.js +8 -8
  133. package/packages/org/src/org.vue +113 -113
  134. package/packages/org/src/orgItem.vue +63 -63
  135. package/packages/padding/index.js +8 -8
  136. package/packages/padding/src/padding.vue +105 -105
  137. package/packages/page/index.js +8 -8
  138. package/packages/page/src/page.vue +297 -297
  139. package/packages/param/index.js +8 -8
  140. package/packages/param/src/param.vue +226 -226
  141. package/packages/pic/index.js +8 -8
  142. package/packages/pic/src/pic-viewer.vue +331 -331
  143. package/packages/pic/src/pic.vue +144 -144
  144. package/packages/popup/index.js +12 -12
  145. package/packages/popup/src/popup-group.vue +47 -47
  146. package/packages/popup/src/popup-item.vue +163 -163
  147. package/packages/popup/src/popup.vue +350 -350
  148. package/packages/progress/index.js +8 -8
  149. package/packages/progress/src/progress.vue +306 -306
  150. package/packages/range/index.js +8 -8
  151. package/packages/range/src/range.vue +612 -612
  152. package/packages/rate/index.js +8 -8
  153. package/packages/rate/src/rate.vue +129 -129
  154. package/packages/reverser/index.js +8 -8
  155. package/packages/reverser/src/reverser.vue +49 -49
  156. package/packages/scroll/index.js +12 -12
  157. package/packages/scroll/src/scroll-point.vue +24 -24
  158. package/packages/scroll/src/scroll-sticky.vue +60 -60
  159. package/packages/scroll/src/scroll.vue +381 -381
  160. package/packages/segment/index.js +8 -8
  161. package/packages/segment/src/segment.vue +618 -618
  162. package/packages/select/index.js +8 -8
  163. package/packages/select/src/select.vue +1445 -1445
  164. package/packages/size/index.js +8 -8
  165. package/packages/size/src/directive.js +33 -33
  166. package/packages/skeleton/index.js +8 -8
  167. package/packages/skeleton/src/skeleton.vue +179 -179
  168. package/packages/slide/index.js +8 -8
  169. package/packages/slide/src/slide.vue +147 -147
  170. package/packages/space/index.js +8 -8
  171. package/packages/space/src/space.vue +53 -53
  172. package/packages/step/index.js +8 -8
  173. package/packages/step/src/step.vue +122 -122
  174. package/packages/submit/index.js +8 -8
  175. package/packages/submit/src/submit.vue +103 -103
  176. package/packages/switch/index.js +9 -9
  177. package/packages/switch/src/component.vue +131 -131
  178. package/packages/tab/index.js +10 -10
  179. package/packages/tab/src/tab-item.vue +85 -85
  180. package/packages/tab/src/tab.vue +590 -590
  181. package/packages/table/index.js +8 -8
  182. package/packages/table/src/table-body.vue +301 -301
  183. package/packages/table/src/table-config.vue +139 -139
  184. package/packages/table/src/table-head.vue +239 -239
  185. package/packages/table/src/table.vue +1455 -1458
  186. package/packages/tag/index.js +8 -8
  187. package/packages/tag/src/tag.vue +129 -129
  188. package/packages/theme/package.json +33 -33
  189. package/packages/theme/src/global/mixin.less +416 -416
  190. package/packages/theme/src/global/reset.less +27 -27
  191. package/packages/theme/src/less/component/affix.less +8 -8
  192. package/packages/theme/src/less/component/article-dark.less +6 -6
  193. package/packages/theme/src/less/component/article.less +39 -39
  194. package/packages/theme/src/less/component/box-dark.less +85 -85
  195. package/packages/theme/src/less/component/box.less +272 -272
  196. package/packages/theme/src/less/component/calendar-dark.less +111 -111
  197. package/packages/theme/src/less/component/calendar.less +282 -282
  198. package/packages/theme/src/less/component/card-dark.less +17 -17
  199. package/packages/theme/src/less/component/card.less +89 -89
  200. package/packages/theme/src/less/component/chat-dark.less +47 -47
  201. package/packages/theme/src/less/component/chat.less +71 -71
  202. package/packages/theme/src/less/component/code-dark.less +41 -41
  203. package/packages/theme/src/less/component/code.less +33 -33
  204. package/packages/theme/src/less/component/cover.less +4 -4
  205. package/packages/theme/src/less/component/dialog-dark.less +54 -54
  206. package/packages/theme/src/less/component/dialog.less +49 -49
  207. package/packages/theme/src/less/component/filter-dark.less +31 -31
  208. package/packages/theme/src/less/component/filter.less +97 -97
  209. package/packages/theme/src/less/component/float-dark.less +26 -26
  210. package/packages/theme/src/less/component/float.less +61 -61
  211. package/packages/theme/src/less/component/form-dark.less +45 -45
  212. package/packages/theme/src/less/component/form.less +322 -322
  213. package/packages/theme/src/less/component/gantt-dark.less +44 -44
  214. package/packages/theme/src/less/component/gantt.less +52 -52
  215. package/packages/theme/src/less/component/guider-dark.less +6 -6
  216. package/packages/theme/src/less/component/guider.less +15 -15
  217. package/packages/theme/src/less/component/header-dark.less +41 -41
  218. package/packages/theme/src/less/component/header.less +121 -121
  219. package/packages/theme/src/less/component/keyboard-dark.less +15 -15
  220. package/packages/theme/src/less/component/keyboard.less +21 -21
  221. package/packages/theme/src/less/component/line-dark.less +20 -20
  222. package/packages/theme/src/less/component/line.less +21 -21
  223. package/packages/theme/src/less/component/msg-dark.less +42 -42
  224. package/packages/theme/src/less/component/msg.less +102 -102
  225. package/packages/theme/src/less/component/page-dark.less +26 -26
  226. package/packages/theme/src/less/component/page.less +26 -26
  227. package/packages/theme/src/less/component/param-dark.less +31 -31
  228. package/packages/theme/src/less/component/param.less +136 -136
  229. package/packages/theme/src/less/component/popup-dark.less +20 -20
  230. package/packages/theme/src/less/component/popup.less +85 -85
  231. package/packages/theme/src/less/component/print.less +121 -121
  232. package/packages/theme/src/less/component/scroll-dark.less +19 -19
  233. package/packages/theme/src/less/component/scroll.less +47 -47
  234. package/packages/theme/src/less/component/skeleton-dark.less +29 -29
  235. package/packages/theme/src/less/component/skeleton.less +78 -78
  236. package/packages/theme/src/less/component/slide.less +70 -70
  237. package/packages/theme/src/less/component/space.less +2 -2
  238. package/packages/theme/src/less/component/step-dark.less +165 -165
  239. package/packages/theme/src/less/component/step.less +147 -147
  240. package/packages/theme/src/less/component/submit.less +40 -40
  241. package/packages/theme/src/less/component/tab-dark.less +221 -221
  242. package/packages/theme/src/less/component/tab.less +459 -459
  243. package/packages/theme/src/less/component/table-dark.less +196 -196
  244. package/packages/theme/src/less/component/table.less +425 -425
  245. package/packages/theme/src/less/component/timeline-dark.less +13 -13
  246. package/packages/theme/src/less/component/timeline.less +114 -114
  247. package/packages/theme/src/less/component/tip-dark.less +76 -76
  248. package/packages/theme/src/less/component/tip.less +139 -139
  249. package/packages/theme/src/less/component/tooltip-dark.less +105 -105
  250. package/packages/theme/src/less/component/tooltip.less +159 -159
  251. package/packages/theme/src/less/component/tree-dark.less +56 -56
  252. package/packages/theme/src/less/component/tree.less +148 -148
  253. package/packages/theme/src/less/element/align.less +32 -32
  254. package/packages/theme/src/less/element/animation.less +5 -5
  255. package/packages/theme/src/less/element/button-dark.less +29 -29
  256. package/packages/theme/src/less/element/button.less +65 -65
  257. package/packages/theme/src/less/element/center-scroll-dark.less +3 -3
  258. package/packages/theme/src/less/element/center-scroll.less +6 -6
  259. package/packages/theme/src/less/element/checkbox-dark.less +68 -68
  260. package/packages/theme/src/less/element/checkbox.less +73 -73
  261. package/packages/theme/src/less/element/color-dark.less +15 -15
  262. package/packages/theme/src/less/element/color.less +33 -33
  263. package/packages/theme/src/less/element/dis.less +9 -9
  264. package/packages/theme/src/less/element/ellipsis.less +35 -35
  265. package/packages/theme/src/less/element/emote.less +5 -5
  266. package/packages/theme/src/less/element/font-dark.less +9 -9
  267. package/packages/theme/src/less/element/font.less +8 -8
  268. package/packages/theme/src/less/element/hide-dark.less +114 -114
  269. package/packages/theme/src/less/element/hide.less +114 -114
  270. package/packages/theme/src/less/element/icon.less +297 -297
  271. package/packages/theme/src/less/element/input-dark.less +205 -205
  272. package/packages/theme/src/less/element/input.less +405 -405
  273. package/packages/theme/src/less/element/menu-icon.less +1 -1
  274. package/packages/theme/src/less/element/pic.less +18 -18
  275. package/packages/theme/src/less/element/progress-dark.less +37 -37
  276. package/packages/theme/src/less/element/progress.less +82 -82
  277. package/packages/theme/src/less/element/radio-dark.less +18 -18
  278. package/packages/theme/src/less/element/radio.less +11 -11
  279. package/packages/theme/src/less/element/range-dark.less +24 -24
  280. package/packages/theme/src/less/element/range.less +56 -56
  281. package/packages/theme/src/less/element/rate.less +17 -17
  282. package/packages/theme/src/less/element/segment-dark.less +119 -119
  283. package/packages/theme/src/less/element/segment.less +197 -197
  284. package/packages/theme/src/less/element/select-dark.less +167 -167
  285. package/packages/theme/src/less/element/select.less +431 -431
  286. package/packages/theme/src/less/element/size.less +10 -10
  287. package/packages/theme/src/less/element/switch-dark.less +7 -7
  288. package/packages/theme/src/less/element/switch.less +37 -37
  289. package/packages/theme/src/less/element/tag-dark.less +115 -115
  290. package/packages/theme/src/less/element/tag.less +159 -159
  291. package/packages/theme/src/less/element/upload-dark.less +26 -26
  292. package/packages/theme/src/less/element/upload.less +64 -64
  293. package/packages/theme/src/less/layout/fix.less +2 -2
  294. package/packages/theme/src/less/layout/flow.less +47 -47
  295. package/packages/theme/src/less/layout/grid-dark.less +28 -28
  296. package/packages/theme/src/less/layout/grid.less +172 -172
  297. package/packages/theme/src/less/layout/org-dark.less +2 -2
  298. package/packages/theme/src/less/layout/org.less +72 -72
  299. package/packages/theme/src/less/layout/padding.less +1 -1
  300. package/packages/theme/src/less/layout/reverser.less +8 -8
  301. package/packages/theme/src/less/theme/B-Design.less +159 -159
  302. package/packages/theme/src/less/theme/aiplan.less +159 -159
  303. package/packages/theme/src/less/theme/aiplangd.less +159 -159
  304. package/packages/theme/src/less/theme/chbn.less +159 -159
  305. package/packages/theme/src/less/theme/default.less +160 -160
  306. package/packages/theme/src/less/theme/dt.less +159 -159
  307. package/packages/theme/src/less/theme/ecloud.less +159 -159
  308. package/packages/theme/src/less/theme/hongkong.less +159 -159
  309. package/packages/theme/src/less/theme/narrow.less +160 -160
  310. package/packages/theme/src/less/theme/sdpf.less +160 -160
  311. package/packages/theme/src/less/theme/upc.less +159 -159
  312. package/packages/theme/src/less/theme/website.less +159 -159
  313. package/packages/theme/src/less/theme/zj.less +159 -159
  314. package/packages/timeline/index.js +8 -8
  315. package/packages/timeline/src/timeline.vue +84 -84
  316. package/packages/tip/index.js +8 -8
  317. package/packages/tip/src/tip.vue +226 -226
  318. package/packages/tooltip/index.js +8 -8
  319. package/packages/tooltip/src/directive.js +180 -180
  320. package/packages/tooltip/src/tooltip.vue +467 -467
  321. package/packages/transfer/index.js +8 -8
  322. package/packages/transfer/src/transfer.vue +293 -293
  323. package/packages/tree/index.js +8 -8
  324. package/packages/tree/src/tree.vue +518 -518
  325. package/packages/tree/src/treeItem.vue +443 -443
  326. package/packages/upload/index.js +8 -8
  327. package/packages/upload/src/upload.vue +860 -860
  328. package/src/index.js +207 -207
  329. package/src/locale/format.js +46 -46
  330. package/src/locale/index.js +48 -48
  331. package/src/locale/lang/en.js +207 -207
  332. package/src/locale/lang/zh-CN.js +207 -207
  333. package/src/mixins/blur.js +9 -9
  334. package/src/mixins/emitter.js +33 -33
  335. package/src/mixins/focus.js +9 -9
  336. package/src/mixins/locale.js +9 -9
  337. package/src/mixins/migrating.js +54 -54
  338. package/src/mixins/tip.js +10 -10
  339. package/src/mixins/transition.js +130 -130
  340. package/src/msg/index.js +107 -107
  341. package/src/svg/menu/main/abnormal-mix.svg +5 -5
  342. package/src/svg/menu/main/abnormal.svg +5 -5
  343. package/src/svg/menu/main/accountManager-mix.svg +5 -5
  344. package/src/svg/menu/main/accountManager.svg +5 -5
  345. package/src/svg/menu/main/agreement-mix.svg +7 -7
  346. package/src/svg/menu/main/agreement.svg +7 -7
  347. package/src/svg/menu/main/ai-mix.svg +5 -5
  348. package/src/svg/menu/main/archives-mix.svg +6 -6
  349. package/src/svg/menu/main/arrearsReport-mix.svg +17 -17
  350. package/src/svg/menu/main/arrearsReport.svg +17 -17
  351. package/src/svg/menu/main/bill-mix.svg +13 -13
  352. package/src/svg/menu/main/bill.svg +13 -13
  353. package/src/svg/menu/main/box-mix.svg +5 -5
  354. package/src/svg/menu/main/broadband-mix.svg +4 -4
  355. package/src/svg/menu/main/broadband.svg +4 -4
  356. package/src/svg/menu/main/card-mix.svg +5 -5
  357. package/src/svg/menu/main/card.svg +5 -5
  358. package/src/svg/menu/main/cash-mix.svg +5 -5
  359. package/src/svg/menu/main/cash.svg +5 -5
  360. package/src/svg/menu/main/cloud-mix.svg +4 -4
  361. package/src/svg/menu/main/cloud.svg +4 -4
  362. package/src/svg/menu/main/clue-mix.svg +10 -10
  363. package/src/svg/menu/main/clue.svg +10 -10
  364. package/src/svg/menu/main/commonUse-mix.svg +4 -4
  365. package/src/svg/menu/main/commonUse.svg +4 -4
  366. package/src/svg/menu/main/construction-mix.svg +7 -7
  367. package/src/svg/menu/main/construction.svg +7 -7
  368. package/src/svg/menu/main/contract-mix.svg +8 -8
  369. package/src/svg/menu/main/contract.svg +8 -8
  370. package/src/svg/menu/main/credit-mix.svg +5 -5
  371. package/src/svg/menu/main/credit.svg +5 -5
  372. package/src/svg/menu/main/data-mix.svg +5 -5
  373. package/src/svg/menu/main/data.svg +5 -5
  374. package/src/svg/menu/main/date-mix.svg +7 -7
  375. package/src/svg/menu/main/deposit-mix.svg +4 -4
  376. package/src/svg/menu/main/device-mix.svg +4 -4
  377. package/src/svg/menu/main/device.svg +4 -4
  378. package/src/svg/menu/main/discrepancy-mix.svg +5 -5
  379. package/src/svg/menu/main/door-mix.svg +6 -6
  380. package/src/svg/menu/main/fault-mix.svg +12 -12
  381. package/src/svg/menu/main/fault.svg +16 -16
  382. package/src/svg/menu/main/finance-mix.svg +11 -11
  383. package/src/svg/menu/main/finance.svg +13 -13
  384. package/src/svg/menu/main/flow-mix.svg +4 -4
  385. package/src/svg/menu/main/flow.svg +4 -4
  386. package/src/svg/menu/main/folder-mix.svg +4 -4
  387. package/src/svg/menu/main/folder.svg +4 -4
  388. package/src/svg/menu/main/friendly-mix.svg +5 -5
  389. package/src/svg/menu/main/fusion-mix.svg +5 -5
  390. package/src/svg/menu/main/fusion.svg +5 -5
  391. package/src/svg/menu/main/gift-mix.svg +8 -8
  392. package/src/svg/menu/main/gift.svg +8 -8
  393. package/src/svg/menu/main/gps-mix.svg +6 -6
  394. package/src/svg/menu/main/gps.svg +6 -6
  395. package/src/svg/menu/main/grid-mix.svg +7 -7
  396. package/src/svg/menu/main/grid.svg +7 -7
  397. package/src/svg/menu/main/group-mix.svg +4 -4
  398. package/src/svg/menu/main/group.svg +4 -4
  399. package/src/svg/menu/main/home-mix.svg +5 -5
  400. package/src/svg/menu/main/home.svg +8 -8
  401. package/src/svg/menu/main/ict-mix.svg +4 -4
  402. package/src/svg/menu/main/industry-mix.svg +5 -5
  403. package/src/svg/menu/main/industry.svg +5 -5
  404. package/src/svg/menu/main/info-mix.svg +9 -9
  405. package/src/svg/menu/main/info.svg +9 -9
  406. package/src/svg/menu/main/integral-mix.svg +5 -5
  407. package/src/svg/menu/main/integral.svg +5 -5
  408. package/src/svg/menu/main/internet-mix.svg +5 -5
  409. package/src/svg/menu/main/internet.svg +5 -5
  410. package/src/svg/menu/main/inventory-mix.svg +5 -5
  411. package/src/svg/menu/main/invoice-mix.svg +6 -6
  412. package/src/svg/menu/main/invoice.svg +14 -14
  413. package/src/svg/menu/main/iot-mix.svg +5 -5
  414. package/src/svg/menu/main/iot.svg +5 -5
  415. package/src/svg/menu/main/label-mix.svg +4 -4
  416. package/src/svg/menu/main/label.svg +4 -4
  417. package/src/svg/menu/main/love-mix.svg +6 -6
  418. package/src/svg/menu/main/love.svg +13 -13
  419. package/src/svg/menu/main/m1-mix.svg +4 -4
  420. package/src/svg/menu/main/m1.svg +4 -4
  421. package/src/svg/menu/main/m2-mix.svg +12 -12
  422. package/src/svg/menu/main/m2.svg +11 -11
  423. package/src/svg/menu/main/m3-mix.svg +6 -6
  424. package/src/svg/menu/main/m3.svg +7 -7
  425. package/src/svg/menu/main/m4-mix.svg +5 -5
  426. package/src/svg/menu/main/m4.svg +7 -7
  427. package/src/svg/menu/main/m5-mix.svg +8 -8
  428. package/src/svg/menu/main/m5.svg +10 -10
  429. package/src/svg/menu/main/mail-mix.svg +5 -5
  430. package/src/svg/menu/main/manual-mix.svg +11 -11
  431. package/src/svg/menu/main/manual.svg +11 -11
  432. package/src/svg/menu/main/market-mix.svg +4 -4
  433. package/src/svg/menu/main/market.svg +4 -4
  434. package/src/svg/menu/main/member-mix.svg +6 -6
  435. package/src/svg/menu/main/member.svg +6 -6
  436. package/src/svg/menu/main/menu-mix.svg +4 -4
  437. package/src/svg/menu/main/menu.svg +4 -4
  438. package/src/svg/menu/main/message-mix.svg +11 -11
  439. package/src/svg/menu/main/message.svg +11 -11
  440. package/src/svg/menu/main/namelist-mix.svg +4 -4
  441. package/src/svg/menu/main/namelist.svg +4 -4
  442. package/src/svg/menu/main/net-mix.svg +7 -7
  443. package/src/svg/menu/main/niche-mix.svg +12 -12
  444. package/src/svg/menu/main/niche.svg +12 -12
  445. package/src/svg/menu/main/notice-mix.svg +4 -4
  446. package/src/svg/menu/main/notice.svg +4 -4
  447. package/src/svg/menu/main/number-mix.svg +6 -6
  448. package/src/svg/menu/main/operations-mix.svg +4 -4
  449. package/src/svg/menu/main/operations.svg +4 -4
  450. package/src/svg/menu/main/order-mix.svg +8 -8
  451. package/src/svg/menu/main/order.svg +8 -8
  452. package/src/svg/menu/main/person-mix.svg +6 -6
  453. package/src/svg/menu/main/person.svg +6 -6
  454. package/src/svg/menu/main/phone-mix.svg +4 -4
  455. package/src/svg/menu/main/phone.svg +4 -4
  456. package/src/svg/menu/main/phoneBill-mix.svg +6 -6
  457. package/src/svg/menu/main/phoneBill.svg +6 -6
  458. package/src/svg/menu/main/preferential-mix.svg +5 -5
  459. package/src/svg/menu/main/preferential.svg +5 -5
  460. package/src/svg/menu/main/print-mix.svg +5 -5
  461. package/src/svg/menu/main/problem-mix.svg +4 -4
  462. package/src/svg/menu/main/problem.svg +4 -4
  463. package/src/svg/menu/main/process-mix.svg +4 -4
  464. package/src/svg/menu/main/process.svg +4 -4
  465. package/src/svg/menu/main/product-mix.svg +5 -5
  466. package/src/svg/menu/main/product.svg +6 -6
  467. package/src/svg/menu/main/qrCode-mix.svg +8 -8
  468. package/src/svg/menu/main/qrCode.svg +8 -8
  469. package/src/svg/menu/main/refuelingBag-mix-mix.svg +4 -4
  470. package/src/svg/menu/main/refuelingBag-mix.svg +4 -4
  471. package/src/svg/menu/main/reportForm-mix.svg +8 -8
  472. package/src/svg/menu/main/reportForm.svg +8 -8
  473. package/src/svg/menu/main/risk-mix.svg +16 -16
  474. package/src/svg/menu/main/risk.svg +17 -17
  475. package/src/svg/menu/main/robot-mix.svg +9 -9
  476. package/src/svg/menu/main/robot.svg +9 -9
  477. package/src/svg/menu/main/satisfaction-mix.svg +4 -4
  478. package/src/svg/menu/main/satisfaction.svg +4 -4
  479. package/src/svg/menu/main/scratchCard-mix.svg +4 -4
  480. package/src/svg/menu/main/sim-mix.svg +4 -4
  481. package/src/svg/menu/main/sim.svg +4 -4
  482. package/src/svg/menu/main/staging-mix.svg +4 -4
  483. package/src/svg/menu/main/staging.svg +4 -4
  484. package/src/svg/menu/main/survey-mix.svg +5 -5
  485. package/src/svg/menu/main/survey.svg +5 -5
  486. package/src/svg/menu/main/tasks-mix.svg +8 -8
  487. package/src/svg/menu/main/tasks.svg +8 -8
  488. package/src/svg/menu/main/telephone-mix.svg +4 -4
  489. package/src/svg/menu/main/topUp-mix.svg +5 -5
  490. package/src/svg/menu/main/trajectory-mix.svg +11 -11
  491. package/src/svg/menu/main/trajectory.svg +23 -23
  492. package/src/svg/menu/main/transmit-mix.svg +5 -5
  493. package/src/svg/menu/main/tv-mix.svg +6 -6
  494. package/src/svg/menu/main/unlock-mix.svg +4 -4
  495. package/src/svg/menu/main/unlock.svg +4 -4
  496. package/src/svg/menu/main/view-mix.svg +5 -5
  497. package/src/svg/menu/main/view.svg +5 -5
  498. package/src/svg/menu/main/visits-mix.svg +19 -19
  499. package/src/svg/menu/main/visits.svg +19 -19
  500. package/src/svg/menu/main/voice-mix.svg +4 -4
  501. package/src/svg/menu/main/voice.svg +4 -4
  502. package/src/svg/menu/main/wiki-mix.svg +4 -4
  503. package/src/svg/menu/main/wiki.svg +4 -4
  504. package/src/svg/menu/main/workOrder-mix.svg +6 -6
  505. package/src/svg/menu/main/workOrder.svg +14 -14
  506. package/src/svg/menu/patch/Mo-space.svg +2 -2
  507. package/src/svg/menu/patch/Mo.svg +3 -3
  508. package/src/svg/menu/patch/add-space.svg +3 -3
  509. package/src/svg/menu/patch/add.svg +3 -3
  510. package/src/svg/menu/patch/address-space.svg +3 -3
  511. package/src/svg/menu/patch/address.svg +3 -3
  512. package/src/svg/menu/patch/approve-space.svg +3 -3
  513. package/src/svg/menu/patch/approve.svg +4 -4
  514. package/src/svg/menu/patch/avoid-space.svg +3 -3
  515. package/src/svg/menu/patch/avoid.svg +3 -3
  516. package/src/svg/menu/patch/batch-space.svg +3 -3
  517. package/src/svg/menu/patch/batch.svg +5 -5
  518. package/src/svg/menu/patch/broadband-space.svg +3 -3
  519. package/src/svg/menu/patch/broadband.svg +4 -4
  520. package/src/svg/menu/patch/cancellation-space.svg +3 -3
  521. package/src/svg/menu/patch/cancellation.svg +3 -3
  522. package/src/svg/menu/patch/center-space.svg +3 -3
  523. package/src/svg/menu/patch/center.svg +5 -5
  524. package/src/svg/menu/patch/change-space.svg +3 -3
  525. package/src/svg/menu/patch/change.svg +4 -4
  526. package/src/svg/menu/patch/click-space.svg +3 -3
  527. package/src/svg/menu/patch/click.svg +4 -4
  528. package/src/svg/menu/patch/close-1-space.svg +3 -3
  529. package/src/svg/menu/patch/close-1.svg +3 -3
  530. package/src/svg/menu/patch/close-space.svg +2 -2
  531. package/src/svg/menu/patch/close.svg +3 -3
  532. package/src/svg/menu/patch/collect-space.svg +3 -3
  533. package/src/svg/menu/patch/collect.svg +3 -3
  534. package/src/svg/menu/patch/comment-space.svg +3 -3
  535. package/src/svg/menu/patch/comment.svg +3 -3
  536. package/src/svg/menu/patch/confirm-space.svg +3 -3
  537. package/src/svg/menu/patch/confirm.svg +3 -3
  538. package/src/svg/menu/patch/contract-space.svg +3 -3
  539. package/src/svg/menu/patch/contract.svg +3 -3
  540. package/src/svg/menu/patch/credit-space.svg +3 -3
  541. package/src/svg/menu/patch/credit.svg +5 -5
  542. package/src/svg/menu/patch/dataMonitoring-space.svg +3 -3
  543. package/src/svg/menu/patch/dataMonitoring.svg +3 -3
  544. package/src/svg/menu/patch/dedicatedCircuit-space.svg +3 -3
  545. package/src/svg/menu/patch/dedicatedCircuit.svg +3 -3
  546. package/src/svg/menu/patch/detail-space.svg +3 -3
  547. package/src/svg/menu/patch/detail.svg +3 -3
  548. package/src/svg/menu/patch/disassemb-space.svg +3 -3
  549. package/src/svg/menu/patch/disassemb.svg +3 -3
  550. package/src/svg/menu/patch/earnestMoney-space.svg +3 -3
  551. package/src/svg/menu/patch/earnestMoney.svg +3 -3
  552. package/src/svg/menu/patch/empower-space.svg +3 -3
  553. package/src/svg/menu/patch/empower.svg +3 -3
  554. package/src/svg/menu/patch/entrust-space.svg +3 -3
  555. package/src/svg/menu/patch/entrust.svg +3 -3
  556. package/src/svg/menu/patch/expedite-space.svg +4 -4
  557. package/src/svg/menu/patch/expedite.svg +4 -4
  558. package/src/svg/menu/patch/flow-space.svg +3 -3
  559. package/src/svg/menu/patch/flow.svg +3 -3
  560. package/src/svg/menu/patch/folder-space.svg +3 -3
  561. package/src/svg/menu/patch/folder.svg +3 -3
  562. package/src/svg/menu/patch/forbidden-space.svg +3 -3
  563. package/src/svg/menu/patch/forbidden.svg +3 -3
  564. package/src/svg/menu/patch/forward-space.svg +3 -3
  565. package/src/svg/menu/patch/forward.svg +3 -3
  566. package/src/svg/menu/patch/fusion-space.svg +3 -3
  567. package/src/svg/menu/patch/fusion.svg +6 -6
  568. package/src/svg/menu/patch/history-space.svg +3 -3
  569. package/src/svg/menu/patch/history.svg +3 -3
  570. package/src/svg/menu/patch/information-space.svg +3 -3
  571. package/src/svg/menu/patch/information.svg +3 -3
  572. package/src/svg/menu/patch/insert-space.svg +3 -3
  573. package/src/svg/menu/patch/insert.svg +3 -3
  574. package/src/svg/menu/patch/letv-space.svg +3 -3
  575. package/src/svg/menu/patch/letv.svg +3 -3
  576. package/src/svg/menu/patch/link-space.svg +3 -3
  577. package/src/svg/menu/patch/link.svg +3 -3
  578. package/src/svg/menu/patch/location-space.svg +3 -3
  579. package/src/svg/menu/patch/location.svg +3 -3
  580. package/src/svg/menu/patch/message-space.svg +3 -3
  581. package/src/svg/menu/patch/message.svg +4 -4
  582. package/src/svg/menu/patch/minus-space.svg +3 -3
  583. package/src/svg/menu/patch/minus.svg +3 -3
  584. package/src/svg/menu/patch/mms-space.svg +3 -3
  585. package/src/svg/menu/patch/mms.svg +3 -3
  586. package/src/svg/menu/patch/monitor-space.svg +3 -3
  587. package/src/svg/menu/patch/monitor.svg +3 -3
  588. package/src/svg/menu/patch/move-space.svg +3 -3
  589. package/src/svg/menu/patch/move.svg +3 -3
  590. package/src/svg/menu/patch/negative-space.svg +2 -2
  591. package/src/svg/menu/patch/negative.svg +3 -3
  592. package/src/svg/menu/patch/net-space.svg +2 -2
  593. package/src/svg/menu/patch/net.svg +3 -3
  594. package/src/svg/menu/patch/news-space.svg +3 -3
  595. package/src/svg/menu/patch/news.svg +3 -3
  596. package/src/svg/menu/patch/notice-space.svg +4 -4
  597. package/src/svg/menu/patch/notice.svg +5 -5
  598. package/src/svg/menu/patch/officialBusiness-space.svg +3 -3
  599. package/src/svg/menu/patch/officialBusiness.svg +4 -4
  600. package/src/svg/menu/patch/pay-space.svg +3 -3
  601. package/src/svg/menu/patch/pay.svg +3 -3
  602. package/src/svg/menu/patch/phone-space.svg +3 -3
  603. package/src/svg/menu/patch/phone.svg +5 -5
  604. package/src/svg/menu/patch/print-space.svg +3 -3
  605. package/src/svg/menu/patch/print.svg +5 -5
  606. package/src/svg/menu/patch/product-space.svg +3 -3
  607. package/src/svg/menu/patch/product.svg +5 -5
  608. package/src/svg/menu/patch/reservation-space.svg +3 -3
  609. package/src/svg/menu/patch/reservation.svg +3 -3
  610. package/src/svg/menu/patch/sale-space.svg +3 -3
  611. package/src/svg/menu/patch/sale.svg +5 -5
  612. package/src/svg/menu/patch/search-space.svg +3 -3
  613. package/src/svg/menu/patch/search.svg +3 -3
  614. package/src/svg/menu/patch/secure-space.svg +3 -3
  615. package/src/svg/menu/patch/secure.svg +5 -5
  616. package/src/svg/menu/patch/setup-space.svg +3 -3
  617. package/src/svg/menu/patch/setup.svg +3 -3
  618. package/src/svg/menu/patch/shift-space.svg +3 -3
  619. package/src/svg/menu/patch/shift.svg +3 -3
  620. package/src/svg/menu/patch/situation-space.svg +3 -3
  621. package/src/svg/menu/patch/situation.svg +3 -3
  622. package/src/svg/menu/patch/special-space.svg +3 -3
  623. package/src/svg/menu/patch/special.svg +3 -3
  624. package/src/svg/menu/patch/tabulation-space.svg +3 -3
  625. package/src/svg/menu/patch/tabulation.svg +8 -8
  626. package/src/svg/menu/patch/track-space.svg +3 -3
  627. package/src/svg/menu/patch/track.svg +5 -5
  628. package/src/svg/menu/patch/transaction-space.svg +3 -3
  629. package/src/svg/menu/patch/transaction.svg +6 -6
  630. package/src/svg/menu/patch/user-space.svg +3 -3
  631. package/src/svg/menu/patch/user.svg +3 -3
  632. package/src/svg/menu/patch/visualize-space.svg +3 -3
  633. package/src/svg/menu/patch/visualize.svg +4 -4
  634. package/src/svg/menu/patch/vnet-space.svg +3 -3
  635. package/src/svg/menu/patch/vnet.svg +3 -3
  636. package/src/tip/tip.js +160 -160
  637. package/src/utils/after-leave.js +27 -27
  638. package/src/utils/ajax.js +59 -59
  639. package/src/utils/array.js +24 -24
  640. package/src/utils/clickoutside.js +105 -105
  641. package/src/utils/compare.js +16 -16
  642. package/src/utils/date.js +34 -34
  643. package/src/utils/disabledArea.js +18 -18
  644. package/src/utils/dom.js +301 -301
  645. package/src/utils/filetransfer.js +287 -287
  646. package/src/utils/isModified.js +20 -20
  647. package/src/utils/jsencrypt/JSEncrypt.js +192 -192
  648. package/src/utils/jsencrypt/JSEncryptRSAKey.js +320 -320
  649. package/src/utils/jsencrypt/index.js +3 -3
  650. package/src/utils/jsencrypt/jselib/asn1js/asn1.d.ts +51 -51
  651. package/src/utils/jsencrypt/jselib/asn1js/asn1.js +565 -565
  652. package/src/utils/jsencrypt/jselib/asn1js/base64.d.ts +5 -5
  653. package/src/utils/jsencrypt/jselib/asn1js/base64.js +88 -88
  654. package/src/utils/jsencrypt/jselib/asn1js/hex.d.ts +3 -3
  655. package/src/utils/jsencrypt/jselib/asn1js/hex.js +64 -64
  656. package/src/utils/jsencrypt/jselib/asn1js/int10.d.ts +9 -9
  657. package/src/utils/jsencrypt/jselib/asn1js/int10.js +87 -87
  658. package/src/utils/jsencrypt/jselib/asn1js/oids.d.ts +9778 -9778
  659. package/src/utils/jsencrypt/jselib/asn1js/oids.js +1962 -1962
  660. package/src/utils/jsencrypt/jselib/jsbn/base64.d.ts +3 -3
  661. package/src/utils/jsencrypt/jselib/jsbn/base64.js +76 -76
  662. package/src/utils/jsencrypt/jselib/jsbn/jsbn.d.ts +98 -98
  663. package/src/utils/jsencrypt/jselib/jsbn/jsbn.js +1754 -1754
  664. package/src/utils/jsencrypt/jselib/jsbn/prng4.d.ts +10 -10
  665. package/src/utils/jsencrypt/jselib/jsbn/prng4.js +46 -46
  666. package/src/utils/jsencrypt/jselib/jsbn/rng.d.ts +3 -3
  667. package/src/utils/jsencrypt/jselib/jsbn/rng.js +78 -78
  668. package/src/utils/jsencrypt/jselib/jsbn/rsa.d.ts +23 -23
  669. package/src/utils/jsencrypt/jselib/jsbn/rsa.js +373 -373
  670. package/src/utils/jsencrypt/jselib/jsbn/util.d.ts +7 -7
  671. package/src/utils/jsencrypt/jselib/jsbn/util.js +58 -58
  672. package/src/utils/jsencrypt/jselib/jsrsasign/asn1-1.0.js +1593 -1593
  673. package/src/utils/jsencrypt/jselib/jsrsasign/yahoo.js +63 -63
  674. package/src/utils/jsencrypt/util.js +58 -58
  675. package/src/utils/jsencrypt.js +263 -263
  676. package/src/utils/md5.js +203 -203
  677. package/src/utils/merge.js +15 -15
  678. package/src/utils/mime.js +75 -75
  679. package/src/utils/print.js +39 -39
  680. package/src/utils/ratio.js +230 -230
  681. package/src/utils/respo.js +9 -9
  682. package/src/utils/shared.js +7 -7
  683. package/src/utils/sign.js +185 -185
  684. package/src/utils/string.js +13 -13
  685. package/src/utils/theme.js +91 -91
  686. package/src/utils/types.js +40 -40
  687. package/src/utils/util.js +286 -286
  688. package/src/utils/uuid.js +12 -12
  689. package/src/utils/validate.js +373 -373
  690. package/packages/.DS_Store +0 -0
  691. package/packages/article/.DS_Store +0 -0
  692. package/packages/chat/.DS_Store +0 -0
  693. package/packages/chat/src/.DS_Store +0 -0
  694. package/packages/date-picker/.DS_Store +0 -0
  695. package/packages/dis/.DS_Store +0 -0
  696. package/packages/emote/.DS_Store +0 -0
  697. package/packages/filter/.DS_Store +0 -0
  698. package/packages/filter/src/.DS_Store +0 -0
  699. package/packages/float/.DS_Store +0 -0
  700. package/packages/flow/.DS_Store +0 -0
  701. package/packages/guider/.DS_Store +0 -0
  702. package/packages/ip/.DS_Store +0 -0
  703. package/packages/org/.DS_Store +0 -0
  704. package/packages/page/.DS_Store +0 -0
  705. package/packages/page/src/.DS_Store +0 -0
  706. package/packages/pic/.DS_Store +0 -0
  707. package/packages/rate/.DS_Store +0 -0
  708. package/packages/reverser/.DS_Store +0 -0
  709. package/packages/reverser/src/.DS_Store +0 -0
  710. package/packages/segment/.DS_Store +0 -0
  711. package/packages/slide/.DS_Store +0 -0
  712. package/packages/tab/.DS_Store +0 -0
  713. package/packages/table/.DS_Store +0 -0
  714. package/packages/theme/src/.DS_Store +0 -0
  715. package/packages/theme/src/img/.DS_Store +0 -0
  716. package/packages/theme/src/img/emote/.DS_Store +0 -0
  717. package/packages/theme/src/less/.DS_Store +0 -0
  718. package/packages/theme/src/less/theme/.DS_Store +0 -0
  719. package/packages/tooltip/.DS_Store +0 -0
  720. package/packages/tree/.DS_Store +0 -0
  721. package/packages/upload/.DS_Store +0 -0
  722. package/src/.DS_Store +0 -0
  723. package/src/svg/.DS_Store +0 -0
  724. package/src/svg/menu/.DS_Store +0 -0
@@ -1,1754 +1,1754 @@
1
- // Copyright (c) 2005 Tom Wu
2
- // All Rights Reserved.
3
- // See "LICENSE" for details.
4
- // Basic JavaScript BN library - subset useful for RSA encryption.
5
- import { cbit, int2char, lbit, op_and, op_andnot, op_or, op_xor } from "./util";
6
- // Bits per digit
7
- var dbits;
8
- // JavaScript engine analysis
9
- var canary = 0xdeadbeefcafe;
10
- var j_lm = ((canary & 0xffffff) == 0xefcafe);
11
- //#region
12
- var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
13
- var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
14
- //#endregion
15
- // (public) Constructor
16
- var BigInteger = /** @class */ (function () {
17
- function BigInteger(a, b, c) {
18
- if (a != null) {
19
- if ("number" == typeof a) {
20
- this.fromNumber(a, b, c);
21
- }
22
- else if (b == null && "string" != typeof a) {
23
- this.fromString(a, 256);
24
- }
25
- else {
26
- this.fromString(a, b);
27
- }
28
- }
29
- }
30
- //#region PUBLIC
31
- // BigInteger.prototype.toString = bnToString;
32
- // (public) return string representation in given radix
33
- BigInteger.prototype.toString = function (b) {
34
- if (this.s < 0) {
35
- return "-" + this.negate().toString(b);
36
- }
37
- var k;
38
- if (b == 16) {
39
- k = 4;
40
- }
41
- else if (b == 8) {
42
- k = 3;
43
- }
44
- else if (b == 2) {
45
- k = 1;
46
- }
47
- else if (b == 32) {
48
- k = 5;
49
- }
50
- else if (b == 4) {
51
- k = 2;
52
- }
53
- else {
54
- return this.toRadix(b);
55
- }
56
- var km = (1 << k) - 1;
57
- var d;
58
- var m = false;
59
- var r = "";
60
- var i = this.t;
61
- var p = this.DB - (i * this.DB) % k;
62
- if (i-- > 0) {
63
- if (p < this.DB && (d = this[i] >> p) > 0) {
64
- m = true;
65
- r = int2char(d);
66
- }
67
- while (i >= 0) {
68
- if (p < k) {
69
- d = (this[i] & ((1 << p) - 1)) << (k - p);
70
- d |= this[--i] >> (p += this.DB - k);
71
- }
72
- else {
73
- d = (this[i] >> (p -= k)) & km;
74
- if (p <= 0) {
75
- p += this.DB;
76
- --i;
77
- }
78
- }
79
- if (d > 0) {
80
- m = true;
81
- }
82
- if (m) {
83
- r += int2char(d);
84
- }
85
- }
86
- }
87
- return m ? r : "0";
88
- };
89
- // BigInteger.prototype.negate = bnNegate;
90
- // (public) -this
91
- BigInteger.prototype.negate = function () {
92
- var r = nbi();
93
- BigInteger.ZERO.subTo(this, r);
94
- return r;
95
- };
96
- // BigInteger.prototype.abs = bnAbs;
97
- // (public) |this|
98
- BigInteger.prototype.abs = function () {
99
- return (this.s < 0) ? this.negate() : this;
100
- };
101
- // BigInteger.prototype.compareTo = bnCompareTo;
102
- // (public) return + if this > a, - if this < a, 0 if equal
103
- BigInteger.prototype.compareTo = function (a) {
104
- var r = this.s - a.s;
105
- if (r != 0) {
106
- return r;
107
- }
108
- var i = this.t;
109
- r = i - a.t;
110
- if (r != 0) {
111
- return (this.s < 0) ? -r : r;
112
- }
113
- while (--i >= 0) {
114
- if ((r = this[i] - a[i]) != 0) {
115
- return r;
116
- }
117
- }
118
- return 0;
119
- };
120
- // BigInteger.prototype.bitLength = bnBitLength;
121
- // (public) return the number of bits in "this"
122
- BigInteger.prototype.bitLength = function () {
123
- if (this.t <= 0) {
124
- return 0;
125
- }
126
- return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
127
- };
128
- // BigInteger.prototype.mod = bnMod;
129
- // (public) this mod a
130
- BigInteger.prototype.mod = function (a) {
131
- var r = nbi();
132
- this.abs().divRemTo(a, null, r);
133
- if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
134
- a.subTo(r, r);
135
- }
136
- return r;
137
- };
138
- // BigInteger.prototype.modPowInt = bnModPowInt;
139
- // (public) this^e % m, 0 <= e < 2^32
140
- BigInteger.prototype.modPowInt = function (e, m) {
141
- var z;
142
- if (e < 256 || m.isEven()) {
143
- z = new Classic(m);
144
- }
145
- else {
146
- z = new Montgomery(m);
147
- }
148
- return this.exp(e, z);
149
- };
150
- // BigInteger.prototype.clone = bnClone;
151
- // (public)
152
- BigInteger.prototype.clone = function () {
153
- var r = nbi();
154
- this.copyTo(r);
155
- return r;
156
- };
157
- // BigInteger.prototype.intValue = bnIntValue;
158
- // (public) return value as integer
159
- BigInteger.prototype.intValue = function () {
160
- if (this.s < 0) {
161
- if (this.t == 1) {
162
- return this[0] - this.DV;
163
- }
164
- else if (this.t == 0) {
165
- return -1;
166
- }
167
- }
168
- else if (this.t == 1) {
169
- return this[0];
170
- }
171
- else if (this.t == 0) {
172
- return 0;
173
- }
174
- // assumes 16 < DB < 32
175
- return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
176
- };
177
- // BigInteger.prototype.byteValue = bnByteValue;
178
- // (public) return value as byte
179
- BigInteger.prototype.byteValue = function () {
180
- return (this.t == 0) ? this.s : (this[0] << 24) >> 24;
181
- };
182
- // BigInteger.prototype.shortValue = bnShortValue;
183
- // (public) return value as short (assumes DB>=16)
184
- BigInteger.prototype.shortValue = function () {
185
- return (this.t == 0) ? this.s : (this[0] << 16) >> 16;
186
- };
187
- // BigInteger.prototype.signum = bnSigNum;
188
- // (public) 0 if this == 0, 1 if this > 0
189
- BigInteger.prototype.signum = function () {
190
- if (this.s < 0) {
191
- return -1;
192
- }
193
- else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) {
194
- return 0;
195
- }
196
- else {
197
- return 1;
198
- }
199
- };
200
- // BigInteger.prototype.toByteArray = bnToByteArray;
201
- // (public) convert to bigendian byte array
202
- BigInteger.prototype.toByteArray = function () {
203
- var i = this.t;
204
- var r = [];
205
- r[0] = this.s;
206
- var p = this.DB - (i * this.DB) % 8;
207
- var d;
208
- var k = 0;
209
- if (i-- > 0) {
210
- if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
211
- r[k++] = d | (this.s << (this.DB - p));
212
- }
213
- while (i >= 0) {
214
- if (p < 8) {
215
- d = (this[i] & ((1 << p) - 1)) << (8 - p);
216
- d |= this[--i] >> (p += this.DB - 8);
217
- }
218
- else {
219
- d = (this[i] >> (p -= 8)) & 0xff;
220
- if (p <= 0) {
221
- p += this.DB;
222
- --i;
223
- }
224
- }
225
- if ((d & 0x80) != 0) {
226
- d |= -256;
227
- }
228
- if (k == 0 && (this.s & 0x80) != (d & 0x80)) {
229
- ++k;
230
- }
231
- if (k > 0 || d != this.s) {
232
- r[k++] = d;
233
- }
234
- }
235
- }
236
- return r;
237
- };
238
- // BigInteger.prototype.equals = bnEquals;
239
- BigInteger.prototype.equals = function (a) {
240
- return (this.compareTo(a) == 0);
241
- };
242
- // BigInteger.prototype.min = bnMin;
243
- BigInteger.prototype.min = function (a) {
244
- return (this.compareTo(a) < 0) ? this : a;
245
- };
246
- // BigInteger.prototype.max = bnMax;
247
- BigInteger.prototype.max = function (a) {
248
- return (this.compareTo(a) > 0) ? this : a;
249
- };
250
- // BigInteger.prototype.and = bnAnd;
251
- BigInteger.prototype.and = function (a) {
252
- var r = nbi();
253
- this.bitwiseTo(a, op_and, r);
254
- return r;
255
- };
256
- // BigInteger.prototype.or = bnOr;
257
- BigInteger.prototype.or = function (a) {
258
- var r = nbi();
259
- this.bitwiseTo(a, op_or, r);
260
- return r;
261
- };
262
- // BigInteger.prototype.xor = bnXor;
263
- BigInteger.prototype.xor = function (a) {
264
- var r = nbi();
265
- this.bitwiseTo(a, op_xor, r);
266
- return r;
267
- };
268
- // BigInteger.prototype.andNot = bnAndNot;
269
- BigInteger.prototype.andNot = function (a) {
270
- var r = nbi();
271
- this.bitwiseTo(a, op_andnot, r);
272
- return r;
273
- };
274
- // BigInteger.prototype.not = bnNot;
275
- // (public) ~this
276
- BigInteger.prototype.not = function () {
277
- var r = nbi();
278
- for (var i = 0; i < this.t; ++i) {
279
- r[i] = this.DM & ~this[i];
280
- }
281
- r.t = this.t;
282
- r.s = ~this.s;
283
- return r;
284
- };
285
- // BigInteger.prototype.shiftLeft = bnShiftLeft;
286
- // (public) this << n
287
- BigInteger.prototype.shiftLeft = function (n) {
288
- var r = nbi();
289
- if (n < 0) {
290
- this.rShiftTo(-n, r);
291
- }
292
- else {
293
- this.lShiftTo(n, r);
294
- }
295
- return r;
296
- };
297
- // BigInteger.prototype.shiftRight = bnShiftRight;
298
- // (public) this >> n
299
- BigInteger.prototype.shiftRight = function (n) {
300
- var r = nbi();
301
- if (n < 0) {
302
- this.lShiftTo(-n, r);
303
- }
304
- else {
305
- this.rShiftTo(n, r);
306
- }
307
- return r;
308
- };
309
- // BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
310
- // (public) returns index of lowest 1-bit (or -1 if none)
311
- BigInteger.prototype.getLowestSetBit = function () {
312
- for (var i = 0; i < this.t; ++i) {
313
- if (this[i] != 0) {
314
- return i * this.DB + lbit(this[i]);
315
- }
316
- }
317
- if (this.s < 0) {
318
- return this.t * this.DB;
319
- }
320
- return -1;
321
- };
322
- // BigInteger.prototype.bitCount = bnBitCount;
323
- // (public) return number of set bits
324
- BigInteger.prototype.bitCount = function () {
325
- var r = 0;
326
- var x = this.s & this.DM;
327
- for (var i = 0; i < this.t; ++i) {
328
- r += cbit(this[i] ^ x);
329
- }
330
- return r;
331
- };
332
- // BigInteger.prototype.testBit = bnTestBit;
333
- // (public) true iff nth bit is set
334
- BigInteger.prototype.testBit = function (n) {
335
- var j = Math.floor(n / this.DB);
336
- if (j >= this.t) {
337
- return (this.s != 0);
338
- }
339
- return ((this[j] & (1 << (n % this.DB))) != 0);
340
- };
341
- // BigInteger.prototype.setBit = bnSetBit;
342
- // (public) this | (1<<n)
343
- BigInteger.prototype.setBit = function (n) {
344
- return this.changeBit(n, op_or);
345
- };
346
- // BigInteger.prototype.clearBit = bnClearBit;
347
- // (public) this & ~(1<<n)
348
- BigInteger.prototype.clearBit = function (n) {
349
- return this.changeBit(n, op_andnot);
350
- };
351
- // BigInteger.prototype.flipBit = bnFlipBit;
352
- // (public) this ^ (1<<n)
353
- BigInteger.prototype.flipBit = function (n) {
354
- return this.changeBit(n, op_xor);
355
- };
356
- // BigInteger.prototype.add = bnAdd;
357
- // (public) this + a
358
- BigInteger.prototype.add = function (a) {
359
- var r = nbi();
360
- this.addTo(a, r);
361
- return r;
362
- };
363
- // BigInteger.prototype.subtract = bnSubtract;
364
- // (public) this - a
365
- BigInteger.prototype.subtract = function (a) {
366
- var r = nbi();
367
- this.subTo(a, r);
368
- return r;
369
- };
370
- // BigInteger.prototype.multiply = bnMultiply;
371
- // (public) this * a
372
- BigInteger.prototype.multiply = function (a) {
373
- var r = nbi();
374
- this.multiplyTo(a, r);
375
- return r;
376
- };
377
- // BigInteger.prototype.divide = bnDivide;
378
- // (public) this / a
379
- BigInteger.prototype.divide = function (a) {
380
- var r = nbi();
381
- this.divRemTo(a, r, null);
382
- return r;
383
- };
384
- // BigInteger.prototype.remainder = bnRemainder;
385
- // (public) this % a
386
- BigInteger.prototype.remainder = function (a) {
387
- var r = nbi();
388
- this.divRemTo(a, null, r);
389
- return r;
390
- };
391
- // BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
392
- // (public) [this/a,this%a]
393
- BigInteger.prototype.divideAndRemainder = function (a) {
394
- var q = nbi();
395
- var r = nbi();
396
- this.divRemTo(a, q, r);
397
- return [q, r];
398
- };
399
- // BigInteger.prototype.modPow = bnModPow;
400
- // (public) this^e % m (HAC 14.85)
401
- BigInteger.prototype.modPow = function (e, m) {
402
- var i = e.bitLength();
403
- var k;
404
- var r = nbv(1);
405
- var z;
406
- if (i <= 0) {
407
- return r;
408
- }
409
- else if (i < 18) {
410
- k = 1;
411
- }
412
- else if (i < 48) {
413
- k = 3;
414
- }
415
- else if (i < 144) {
416
- k = 4;
417
- }
418
- else if (i < 768) {
419
- k = 5;
420
- }
421
- else {
422
- k = 6;
423
- }
424
- if (i < 8) {
425
- z = new Classic(m);
426
- }
427
- else if (m.isEven()) {
428
- z = new Barrett(m);
429
- }
430
- else {
431
- z = new Montgomery(m);
432
- }
433
- // precomputation
434
- var g = [];
435
- var n = 3;
436
- var k1 = k - 1;
437
- var km = (1 << k) - 1;
438
- g[1] = z.convert(this);
439
- if (k > 1) {
440
- var g2 = nbi();
441
- z.sqrTo(g[1], g2);
442
- while (n <= km) {
443
- g[n] = nbi();
444
- z.mulTo(g2, g[n - 2], g[n]);
445
- n += 2;
446
- }
447
- }
448
- var j = e.t - 1;
449
- var w;
450
- var is1 = true;
451
- var r2 = nbi();
452
- var t;
453
- i = nbits(e[j]) - 1;
454
- while (j >= 0) {
455
- if (i >= k1) {
456
- w = (e[j] >> (i - k1)) & km;
457
- }
458
- else {
459
- w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i);
460
- if (j > 0) {
461
- w |= e[j - 1] >> (this.DB + i - k1);
462
- }
463
- }
464
- n = k;
465
- while ((w & 1) == 0) {
466
- w >>= 1;
467
- --n;
468
- }
469
- if ((i -= n) < 0) {
470
- i += this.DB;
471
- --j;
472
- }
473
- if (is1) { // ret == 1, don't bother squaring or multiplying it
474
- g[w].copyTo(r);
475
- is1 = false;
476
- }
477
- else {
478
- while (n > 1) {
479
- z.sqrTo(r, r2);
480
- z.sqrTo(r2, r);
481
- n -= 2;
482
- }
483
- if (n > 0) {
484
- z.sqrTo(r, r2);
485
- }
486
- else {
487
- t = r;
488
- r = r2;
489
- r2 = t;
490
- }
491
- z.mulTo(r2, g[w], r);
492
- }
493
- while (j >= 0 && (e[j] & (1 << i)) == 0) {
494
- z.sqrTo(r, r2);
495
- t = r;
496
- r = r2;
497
- r2 = t;
498
- if (--i < 0) {
499
- i = this.DB - 1;
500
- --j;
501
- }
502
- }
503
- }
504
- return z.revert(r);
505
- };
506
- // BigInteger.prototype.modInverse = bnModInverse;
507
- // (public) 1/this % m (HAC 14.61)
508
- BigInteger.prototype.modInverse = function (m) {
509
- var ac = m.isEven();
510
- if ((this.isEven() && ac) || m.signum() == 0) {
511
- return BigInteger.ZERO;
512
- }
513
- var u = m.clone();
514
- var v = this.clone();
515
- var a = nbv(1);
516
- var b = nbv(0);
517
- var c = nbv(0);
518
- var d = nbv(1);
519
- while (u.signum() != 0) {
520
- while (u.isEven()) {
521
- u.rShiftTo(1, u);
522
- if (ac) {
523
- if (!a.isEven() || !b.isEven()) {
524
- a.addTo(this, a);
525
- b.subTo(m, b);
526
- }
527
- a.rShiftTo(1, a);
528
- }
529
- else if (!b.isEven()) {
530
- b.subTo(m, b);
531
- }
532
- b.rShiftTo(1, b);
533
- }
534
- while (v.isEven()) {
535
- v.rShiftTo(1, v);
536
- if (ac) {
537
- if (!c.isEven() || !d.isEven()) {
538
- c.addTo(this, c);
539
- d.subTo(m, d);
540
- }
541
- c.rShiftTo(1, c);
542
- }
543
- else if (!d.isEven()) {
544
- d.subTo(m, d);
545
- }
546
- d.rShiftTo(1, d);
547
- }
548
- if (u.compareTo(v) >= 0) {
549
- u.subTo(v, u);
550
- if (ac) {
551
- a.subTo(c, a);
552
- }
553
- b.subTo(d, b);
554
- }
555
- else {
556
- v.subTo(u, v);
557
- if (ac) {
558
- c.subTo(a, c);
559
- }
560
- d.subTo(b, d);
561
- }
562
- }
563
- if (v.compareTo(BigInteger.ONE) != 0) {
564
- return BigInteger.ZERO;
565
- }
566
- if (d.compareTo(m) >= 0) {
567
- return d.subtract(m);
568
- }
569
- if (d.signum() < 0) {
570
- d.addTo(m, d);
571
- }
572
- else {
573
- return d;
574
- }
575
- if (d.signum() < 0) {
576
- return d.add(m);
577
- }
578
- else {
579
- return d;
580
- }
581
- };
582
- // BigInteger.prototype.pow = bnPow;
583
- // (public) this^e
584
- BigInteger.prototype.pow = function (e) {
585
- return this.exp(e, new NullExp());
586
- };
587
- // BigInteger.prototype.gcd = bnGCD;
588
- // (public) gcd(this,a) (HAC 14.54)
589
- BigInteger.prototype.gcd = function (a) {
590
- var x = (this.s < 0) ? this.negate() : this.clone();
591
- var y = (a.s < 0) ? a.negate() : a.clone();
592
- if (x.compareTo(y) < 0) {
593
- var t = x;
594
- x = y;
595
- y = t;
596
- }
597
- var i = x.getLowestSetBit();
598
- var g = y.getLowestSetBit();
599
- if (g < 0) {
600
- return x;
601
- }
602
- if (i < g) {
603
- g = i;
604
- }
605
- if (g > 0) {
606
- x.rShiftTo(g, x);
607
- y.rShiftTo(g, y);
608
- }
609
- while (x.signum() > 0) {
610
- if ((i = x.getLowestSetBit()) > 0) {
611
- x.rShiftTo(i, x);
612
- }
613
- if ((i = y.getLowestSetBit()) > 0) {
614
- y.rShiftTo(i, y);
615
- }
616
- if (x.compareTo(y) >= 0) {
617
- x.subTo(y, x);
618
- x.rShiftTo(1, x);
619
- }
620
- else {
621
- y.subTo(x, y);
622
- y.rShiftTo(1, y);
623
- }
624
- }
625
- if (g > 0) {
626
- y.lShiftTo(g, y);
627
- }
628
- return y;
629
- };
630
- // BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
631
- // (public) test primality with certainty >= 1-.5^t
632
- BigInteger.prototype.isProbablePrime = function (t) {
633
- var i;
634
- var x = this.abs();
635
- if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
636
- for (i = 0; i < lowprimes.length; ++i) {
637
- if (x[0] == lowprimes[i]) {
638
- return true;
639
- }
640
- }
641
- return false;
642
- }
643
- if (x.isEven()) {
644
- return false;
645
- }
646
- i = 1;
647
- while (i < lowprimes.length) {
648
- var m = lowprimes[i];
649
- var j = i + 1;
650
- while (j < lowprimes.length && m < lplim) {
651
- m *= lowprimes[j++];
652
- }
653
- m = x.modInt(m);
654
- while (i < j) {
655
- if (m % lowprimes[i++] == 0) {
656
- return false;
657
- }
658
- }
659
- }
660
- return x.millerRabin(t);
661
- };
662
- //#endregion PUBLIC
663
- //#region PROTECTED
664
- // BigInteger.prototype.copyTo = bnpCopyTo;
665
- // (protected) copy this to r
666
- BigInteger.prototype.copyTo = function (r) {
667
- for (var i = this.t - 1; i >= 0; --i) {
668
- r[i] = this[i];
669
- }
670
- r.t = this.t;
671
- r.s = this.s;
672
- };
673
- // BigInteger.prototype.fromInt = bnpFromInt;
674
- // (protected) set from integer value x, -DV <= x < DV
675
- BigInteger.prototype.fromInt = function (x) {
676
- this.t = 1;
677
- this.s = (x < 0) ? -1 : 0;
678
- if (x > 0) {
679
- this[0] = x;
680
- }
681
- else if (x < -1) {
682
- this[0] = x + this.DV;
683
- }
684
- else {
685
- this.t = 0;
686
- }
687
- };
688
- // BigInteger.prototype.fromString = bnpFromString;
689
- // (protected) set from string and radix
690
- BigInteger.prototype.fromString = function (s, b) {
691
- var k;
692
- if (b == 16) {
693
- k = 4;
694
- }
695
- else if (b == 8) {
696
- k = 3;
697
- }
698
- else if (b == 256) {
699
- k = 8;
700
- /* byte array */
701
- }
702
- else if (b == 2) {
703
- k = 1;
704
- }
705
- else if (b == 32) {
706
- k = 5;
707
- }
708
- else if (b == 4) {
709
- k = 2;
710
- }
711
- else {
712
- this.fromRadix(s, b);
713
- return;
714
- }
715
- this.t = 0;
716
- this.s = 0;
717
- var i = s.length;
718
- var mi = false;
719
- var sh = 0;
720
- while (--i >= 0) {
721
- var x = (k == 8) ? (+s[i]) & 0xff : intAt(s, i);
722
- if (x < 0) {
723
- if (s.charAt(i) == "-") {
724
- mi = true;
725
- }
726
- continue;
727
- }
728
- mi = false;
729
- if (sh == 0) {
730
- this[this.t++] = x;
731
- }
732
- else if (sh + k > this.DB) {
733
- this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
734
- this[this.t++] = (x >> (this.DB - sh));
735
- }
736
- else {
737
- this[this.t - 1] |= x << sh;
738
- }
739
- sh += k;
740
- if (sh >= this.DB) {
741
- sh -= this.DB;
742
- }
743
- }
744
- if (k == 8 && ((+s[0]) & 0x80) != 0) {
745
- this.s = -1;
746
- if (sh > 0) {
747
- this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
748
- }
749
- }
750
- this.clamp();
751
- if (mi) {
752
- BigInteger.ZERO.subTo(this, this);
753
- }
754
- };
755
- // BigInteger.prototype.clamp = bnpClamp;
756
- // (protected) clamp off excess high words
757
- BigInteger.prototype.clamp = function () {
758
- var c = this.s & this.DM;
759
- while (this.t > 0 && this[this.t - 1] == c) {
760
- --this.t;
761
- }
762
- };
763
- // BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
764
- // (protected) r = this << n*DB
765
- BigInteger.prototype.dlShiftTo = function (n, r) {
766
- var i;
767
- for (i = this.t - 1; i >= 0; --i) {
768
- r[i + n] = this[i];
769
- }
770
- for (i = n - 1; i >= 0; --i) {
771
- r[i] = 0;
772
- }
773
- r.t = this.t + n;
774
- r.s = this.s;
775
- };
776
- // BigInteger.prototype.drShiftTo = bnpDRShiftTo;
777
- // (protected) r = this >> n*DB
778
- BigInteger.prototype.drShiftTo = function (n, r) {
779
- for (var i = n; i < this.t; ++i) {
780
- r[i - n] = this[i];
781
- }
782
- r.t = Math.max(this.t - n, 0);
783
- r.s = this.s;
784
- };
785
- // BigInteger.prototype.lShiftTo = bnpLShiftTo;
786
- // (protected) r = this << n
787
- BigInteger.prototype.lShiftTo = function (n, r) {
788
- var bs = n % this.DB;
789
- var cbs = this.DB - bs;
790
- var bm = (1 << cbs) - 1;
791
- var ds = Math.floor(n / this.DB);
792
- var c = (this.s << bs) & this.DM;
793
- for (var i = this.t - 1; i >= 0; --i) {
794
- r[i + ds + 1] = (this[i] >> cbs) | c;
795
- c = (this[i] & bm) << bs;
796
- }
797
- for (var i = ds - 1; i >= 0; --i) {
798
- r[i] = 0;
799
- }
800
- r[ds] = c;
801
- r.t = this.t + ds + 1;
802
- r.s = this.s;
803
- r.clamp();
804
- };
805
- // BigInteger.prototype.rShiftTo = bnpRShiftTo;
806
- // (protected) r = this >> n
807
- BigInteger.prototype.rShiftTo = function (n, r) {
808
- r.s = this.s;
809
- var ds = Math.floor(n / this.DB);
810
- if (ds >= this.t) {
811
- r.t = 0;
812
- return;
813
- }
814
- var bs = n % this.DB;
815
- var cbs = this.DB - bs;
816
- var bm = (1 << bs) - 1;
817
- r[0] = this[ds] >> bs;
818
- for (var i = ds + 1; i < this.t; ++i) {
819
- r[i - ds - 1] |= (this[i] & bm) << cbs;
820
- r[i - ds] = this[i] >> bs;
821
- }
822
- if (bs > 0) {
823
- r[this.t - ds - 1] |= (this.s & bm) << cbs;
824
- }
825
- r.t = this.t - ds;
826
- r.clamp();
827
- };
828
- // BigInteger.prototype.subTo = bnpSubTo;
829
- // (protected) r = this - a
830
- BigInteger.prototype.subTo = function (a, r) {
831
- var i = 0;
832
- var c = 0;
833
- var m = Math.min(a.t, this.t);
834
- while (i < m) {
835
- c += this[i] - a[i];
836
- r[i++] = c & this.DM;
837
- c >>= this.DB;
838
- }
839
- if (a.t < this.t) {
840
- c -= a.s;
841
- while (i < this.t) {
842
- c += this[i];
843
- r[i++] = c & this.DM;
844
- c >>= this.DB;
845
- }
846
- c += this.s;
847
- }
848
- else {
849
- c += this.s;
850
- while (i < a.t) {
851
- c -= a[i];
852
- r[i++] = c & this.DM;
853
- c >>= this.DB;
854
- }
855
- c -= a.s;
856
- }
857
- r.s = (c < 0) ? -1 : 0;
858
- if (c < -1) {
859
- r[i++] = this.DV + c;
860
- }
861
- else if (c > 0) {
862
- r[i++] = c;
863
- }
864
- r.t = i;
865
- r.clamp();
866
- };
867
- // BigInteger.prototype.multiplyTo = bnpMultiplyTo;
868
- // (protected) r = this * a, r != this,a (HAC 14.12)
869
- // "this" should be the larger one if appropriate.
870
- BigInteger.prototype.multiplyTo = function (a, r) {
871
- var x = this.abs();
872
- var y = a.abs();
873
- var i = x.t;
874
- r.t = i + y.t;
875
- while (--i >= 0) {
876
- r[i] = 0;
877
- }
878
- for (i = 0; i < y.t; ++i) {
879
- r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
880
- }
881
- r.s = 0;
882
- r.clamp();
883
- if (this.s != a.s) {
884
- BigInteger.ZERO.subTo(r, r);
885
- }
886
- };
887
- // BigInteger.prototype.squareTo = bnpSquareTo;
888
- // (protected) r = this^2, r != this (HAC 14.16)
889
- BigInteger.prototype.squareTo = function (r) {
890
- var x = this.abs();
891
- var i = r.t = 2 * x.t;
892
- while (--i >= 0) {
893
- r[i] = 0;
894
- }
895
- for (i = 0; i < x.t - 1; ++i) {
896
- var c = x.am(i, x[i], r, 2 * i, 0, 1);
897
- if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
898
- r[i + x.t] -= x.DV;
899
- r[i + x.t + 1] = 1;
900
- }
901
- }
902
- if (r.t > 0) {
903
- r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
904
- }
905
- r.s = 0;
906
- r.clamp();
907
- };
908
- // BigInteger.prototype.divRemTo = bnpDivRemTo;
909
- // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
910
- // r != q, this != m. q or r may be null.
911
- BigInteger.prototype.divRemTo = function (m, q, r) {
912
- var pm = m.abs();
913
- if (pm.t <= 0) {
914
- return;
915
- }
916
- var pt = this.abs();
917
- if (pt.t < pm.t) {
918
- if (q != null) {
919
- q.fromInt(0);
920
- }
921
- if (r != null) {
922
- this.copyTo(r);
923
- }
924
- return;
925
- }
926
- if (r == null) {
927
- r = nbi();
928
- }
929
- var y = nbi();
930
- var ts = this.s;
931
- var ms = m.s;
932
- var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
933
- if (nsh > 0) {
934
- pm.lShiftTo(nsh, y);
935
- pt.lShiftTo(nsh, r);
936
- }
937
- else {
938
- pm.copyTo(y);
939
- pt.copyTo(r);
940
- }
941
- var ys = y.t;
942
- var y0 = y[ys - 1];
943
- if (y0 == 0) {
944
- return;
945
- }
946
- var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
947
- var d1 = this.FV / yt;
948
- var d2 = (1 << this.F1) / yt;
949
- var e = 1 << this.F2;
950
- var i = r.t;
951
- var j = i - ys;
952
- var t = (q == null) ? nbi() : q;
953
- y.dlShiftTo(j, t);
954
- if (r.compareTo(t) >= 0) {
955
- r[r.t++] = 1;
956
- r.subTo(t, r);
957
- }
958
- BigInteger.ONE.dlShiftTo(ys, t);
959
- t.subTo(y, y); // "negative" y so we can replace sub with am later
960
- while (y.t < ys) {
961
- y[y.t++] = 0;
962
- }
963
- while (--j >= 0) {
964
- // Estimate quotient digit
965
- var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
966
- if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
967
- y.dlShiftTo(j, t);
968
- r.subTo(t, r);
969
- while (r[i] < --qd) {
970
- r.subTo(t, r);
971
- }
972
- }
973
- }
974
- if (q != null) {
975
- r.drShiftTo(ys, q);
976
- if (ts != ms) {
977
- BigInteger.ZERO.subTo(q, q);
978
- }
979
- }
980
- r.t = ys;
981
- r.clamp();
982
- if (nsh > 0) {
983
- r.rShiftTo(nsh, r);
984
- } // Denormalize remainder
985
- if (ts < 0) {
986
- BigInteger.ZERO.subTo(r, r);
987
- }
988
- };
989
- // BigInteger.prototype.invDigit = bnpInvDigit;
990
- // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
991
- // justification:
992
- // xy == 1 (mod m)
993
- // xy = 1+km
994
- // xy(2-xy) = (1+km)(1-km)
995
- // x[y(2-xy)] = 1-k^2m^2
996
- // x[y(2-xy)] == 1 (mod m^2)
997
- // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
998
- // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
999
- // JS multiply "overflows" differently from C/C++, so care is needed here.
1000
- BigInteger.prototype.invDigit = function () {
1001
- if (this.t < 1) {
1002
- return 0;
1003
- }
1004
- var x = this[0];
1005
- if ((x & 1) == 0) {
1006
- return 0;
1007
- }
1008
- var y = x & 3; // y == 1/x mod 2^2
1009
- y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
1010
- y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
1011
- y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
1012
- // last step - calculate inverse mod DV directly;
1013
- // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
1014
- y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
1015
- // we really want the negative inverse, and -DV < y < DV
1016
- return (y > 0) ? this.DV - y : -y;
1017
- };
1018
- // BigInteger.prototype.isEven = bnpIsEven;
1019
- // (protected) true iff this is even
1020
- BigInteger.prototype.isEven = function () {
1021
- return ((this.t > 0) ? (this[0] & 1) : this.s) == 0;
1022
- };
1023
- // BigInteger.prototype.exp = bnpExp;
1024
- // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
1025
- BigInteger.prototype.exp = function (e, z) {
1026
- if (e > 0xffffffff || e < 1) {
1027
- return BigInteger.ONE;
1028
- }
1029
- var r = nbi();
1030
- var r2 = nbi();
1031
- var g = z.convert(this);
1032
- var i = nbits(e) - 1;
1033
- g.copyTo(r);
1034
- while (--i >= 0) {
1035
- z.sqrTo(r, r2);
1036
- if ((e & (1 << i)) > 0) {
1037
- z.mulTo(r2, g, r);
1038
- }
1039
- else {
1040
- var t = r;
1041
- r = r2;
1042
- r2 = t;
1043
- }
1044
- }
1045
- return z.revert(r);
1046
- };
1047
- // BigInteger.prototype.chunkSize = bnpChunkSize;
1048
- // (protected) return x s.t. r^x < DV
1049
- BigInteger.prototype.chunkSize = function (r) {
1050
- return Math.floor(Math.LN2 * this.DB / Math.log(r));
1051
- };
1052
- // BigInteger.prototype.toRadix = bnpToRadix;
1053
- // (protected) convert to radix string
1054
- BigInteger.prototype.toRadix = function (b) {
1055
- if (b == null) {
1056
- b = 10;
1057
- }
1058
- if (this.signum() == 0 || b < 2 || b > 36) {
1059
- return "0";
1060
- }
1061
- var cs = this.chunkSize(b);
1062
- var a = Math.pow(b, cs);
1063
- var d = nbv(a);
1064
- var y = nbi();
1065
- var z = nbi();
1066
- var r = "";
1067
- this.divRemTo(d, y, z);
1068
- while (y.signum() > 0) {
1069
- r = (a + z.intValue()).toString(b).substr(1) + r;
1070
- y.divRemTo(d, y, z);
1071
- }
1072
- return z.intValue().toString(b) + r;
1073
- };
1074
- // BigInteger.prototype.fromRadix = bnpFromRadix;
1075
- // (protected) convert from radix string
1076
- BigInteger.prototype.fromRadix = function (s, b) {
1077
- this.fromInt(0);
1078
- if (b == null) {
1079
- b = 10;
1080
- }
1081
- var cs = this.chunkSize(b);
1082
- var d = Math.pow(b, cs);
1083
- var mi = false;
1084
- var j = 0;
1085
- var w = 0;
1086
- for (var i = 0; i < s.length; ++i) {
1087
- var x = intAt(s, i);
1088
- if (x < 0) {
1089
- if (s.charAt(i) == "-" && this.signum() == 0) {
1090
- mi = true;
1091
- }
1092
- continue;
1093
- }
1094
- w = b * w + x;
1095
- if (++j >= cs) {
1096
- this.dMultiply(d);
1097
- this.dAddOffset(w, 0);
1098
- j = 0;
1099
- w = 0;
1100
- }
1101
- }
1102
- if (j > 0) {
1103
- this.dMultiply(Math.pow(b, j));
1104
- this.dAddOffset(w, 0);
1105
- }
1106
- if (mi) {
1107
- BigInteger.ZERO.subTo(this, this);
1108
- }
1109
- };
1110
- // BigInteger.prototype.fromNumber = bnpFromNumber;
1111
- // (protected) alternate constructor
1112
- BigInteger.prototype.fromNumber = function (a, b, c) {
1113
- if ("number" == typeof b) {
1114
- // new BigInteger(int,int,RNG)
1115
- if (a < 2) {
1116
- this.fromInt(1);
1117
- }
1118
- else {
1119
- this.fromNumber(a, c);
1120
- if (!this.testBit(a - 1)) {
1121
- // force MSB set
1122
- this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1123
- }
1124
- if (this.isEven()) {
1125
- this.dAddOffset(1, 0);
1126
- } // force odd
1127
- while (!this.isProbablePrime(b)) {
1128
- this.dAddOffset(2, 0);
1129
- if (this.bitLength() > a) {
1130
- this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
1131
- }
1132
- }
1133
- }
1134
- }
1135
- else {
1136
- // new BigInteger(int,RNG)
1137
- var x = [];
1138
- var t = a & 7;
1139
- x.length = (a >> 3) + 1;
1140
- b.nextBytes(x);
1141
- if (t > 0) {
1142
- x[0] &= ((1 << t) - 1);
1143
- }
1144
- else {
1145
- x[0] = 0;
1146
- }
1147
- this.fromString(x, 256);
1148
- }
1149
- };
1150
- // BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
1151
- // (protected) r = this op a (bitwise)
1152
- BigInteger.prototype.bitwiseTo = function (a, op, r) {
1153
- var i;
1154
- var f;
1155
- var m = Math.min(a.t, this.t);
1156
- for (i = 0; i < m; ++i) {
1157
- r[i] = op(this[i], a[i]);
1158
- }
1159
- if (a.t < this.t) {
1160
- f = a.s & this.DM;
1161
- for (i = m; i < this.t; ++i) {
1162
- r[i] = op(this[i], f);
1163
- }
1164
- r.t = this.t;
1165
- }
1166
- else {
1167
- f = this.s & this.DM;
1168
- for (i = m; i < a.t; ++i) {
1169
- r[i] = op(f, a[i]);
1170
- }
1171
- r.t = a.t;
1172
- }
1173
- r.s = op(this.s, a.s);
1174
- r.clamp();
1175
- };
1176
- // BigInteger.prototype.changeBit = bnpChangeBit;
1177
- // (protected) this op (1<<n)
1178
- BigInteger.prototype.changeBit = function (n, op) {
1179
- var r = BigInteger.ONE.shiftLeft(n);
1180
- this.bitwiseTo(r, op, r);
1181
- return r;
1182
- };
1183
- // BigInteger.prototype.addTo = bnpAddTo;
1184
- // (protected) r = this + a
1185
- BigInteger.prototype.addTo = function (a, r) {
1186
- var i = 0;
1187
- var c = 0;
1188
- var m = Math.min(a.t, this.t);
1189
- while (i < m) {
1190
- c += this[i] + a[i];
1191
- r[i++] = c & this.DM;
1192
- c >>= this.DB;
1193
- }
1194
- if (a.t < this.t) {
1195
- c += a.s;
1196
- while (i < this.t) {
1197
- c += this[i];
1198
- r[i++] = c & this.DM;
1199
- c >>= this.DB;
1200
- }
1201
- c += this.s;
1202
- }
1203
- else {
1204
- c += this.s;
1205
- while (i < a.t) {
1206
- c += a[i];
1207
- r[i++] = c & this.DM;
1208
- c >>= this.DB;
1209
- }
1210
- c += a.s;
1211
- }
1212
- r.s = (c < 0) ? -1 : 0;
1213
- if (c > 0) {
1214
- r[i++] = c;
1215
- }
1216
- else if (c < -1) {
1217
- r[i++] = this.DV + c;
1218
- }
1219
- r.t = i;
1220
- r.clamp();
1221
- };
1222
- // BigInteger.prototype.dMultiply = bnpDMultiply;
1223
- // (protected) this *= n, this >= 0, 1 < n < DV
1224
- BigInteger.prototype.dMultiply = function (n) {
1225
- this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
1226
- ++this.t;
1227
- this.clamp();
1228
- };
1229
- // BigInteger.prototype.dAddOffset = bnpDAddOffset;
1230
- // (protected) this += n << w words, this >= 0
1231
- BigInteger.prototype.dAddOffset = function (n, w) {
1232
- if (n == 0) {
1233
- return;
1234
- }
1235
- while (this.t <= w) {
1236
- this[this.t++] = 0;
1237
- }
1238
- this[w] += n;
1239
- while (this[w] >= this.DV) {
1240
- this[w] -= this.DV;
1241
- if (++w >= this.t) {
1242
- this[this.t++] = 0;
1243
- }
1244
- ++this[w];
1245
- }
1246
- };
1247
- // BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
1248
- // (protected) r = lower n words of "this * a", a.t <= n
1249
- // "this" should be the larger one if appropriate.
1250
- BigInteger.prototype.multiplyLowerTo = function (a, n, r) {
1251
- var i = Math.min(this.t + a.t, n);
1252
- r.s = 0; // assumes a,this >= 0
1253
- r.t = i;
1254
- while (i > 0) {
1255
- r[--i] = 0;
1256
- }
1257
- for (var j = r.t - this.t; i < j; ++i) {
1258
- r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
1259
- }
1260
- for (var j = Math.min(a.t, n); i < j; ++i) {
1261
- this.am(0, a[i], r, i, 0, n - i);
1262
- }
1263
- r.clamp();
1264
- };
1265
- // BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
1266
- // (protected) r = "this * a" without lower n words, n > 0
1267
- // "this" should be the larger one if appropriate.
1268
- BigInteger.prototype.multiplyUpperTo = function (a, n, r) {
1269
- --n;
1270
- var i = r.t = this.t + a.t - n;
1271
- r.s = 0; // assumes a,this >= 0
1272
- while (--i >= 0) {
1273
- r[i] = 0;
1274
- }
1275
- for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
1276
- r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
1277
- }
1278
- r.clamp();
1279
- r.drShiftTo(1, r);
1280
- };
1281
- // BigInteger.prototype.modInt = bnpModInt;
1282
- // (protected) this % n, n < 2^26
1283
- BigInteger.prototype.modInt = function (n) {
1284
- if (n <= 0) {
1285
- return 0;
1286
- }
1287
- var d = this.DV % n;
1288
- var r = (this.s < 0) ? n - 1 : 0;
1289
- if (this.t > 0) {
1290
- if (d == 0) {
1291
- r = this[0] % n;
1292
- }
1293
- else {
1294
- for (var i = this.t - 1; i >= 0; --i) {
1295
- r = (d * r + this[i]) % n;
1296
- }
1297
- }
1298
- }
1299
- return r;
1300
- };
1301
- // BigInteger.prototype.millerRabin = bnpMillerRabin;
1302
- // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1303
- BigInteger.prototype.millerRabin = function (t) {
1304
- var n1 = this.subtract(BigInteger.ONE);
1305
- var k = n1.getLowestSetBit();
1306
- if (k <= 0) {
1307
- return false;
1308
- }
1309
- var r = n1.shiftRight(k);
1310
- t = (t + 1) >> 1;
1311
- if (t > lowprimes.length) {
1312
- t = lowprimes.length;
1313
- }
1314
- var a = nbi();
1315
- for (var i = 0; i < t; ++i) {
1316
- // Pick bases at random, instead of starting at 2
1317
- a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
1318
- var y = a.modPow(r, this);
1319
- if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1320
- var j = 1;
1321
- while (j++ < k && y.compareTo(n1) != 0) {
1322
- y = y.modPowInt(2, this);
1323
- if (y.compareTo(BigInteger.ONE) == 0) {
1324
- return false;
1325
- }
1326
- }
1327
- if (y.compareTo(n1) != 0) {
1328
- return false;
1329
- }
1330
- }
1331
- }
1332
- return true;
1333
- };
1334
- // BigInteger.prototype.square = bnSquare;
1335
- // (public) this^2
1336
- BigInteger.prototype.square = function () {
1337
- var r = nbi();
1338
- this.squareTo(r);
1339
- return r;
1340
- };
1341
- //#region ASYNC
1342
- // Public API method
1343
- BigInteger.prototype.gcda = function (a, callback) {
1344
- var x = (this.s < 0) ? this.negate() : this.clone();
1345
- var y = (a.s < 0) ? a.negate() : a.clone();
1346
- if (x.compareTo(y) < 0) {
1347
- var t = x;
1348
- x = y;
1349
- y = t;
1350
- }
1351
- var i = x.getLowestSetBit();
1352
- var g = y.getLowestSetBit();
1353
- if (g < 0) {
1354
- callback(x);
1355
- return;
1356
- }
1357
- if (i < g) {
1358
- g = i;
1359
- }
1360
- if (g > 0) {
1361
- x.rShiftTo(g, x);
1362
- y.rShiftTo(g, y);
1363
- }
1364
- // Workhorse of the algorithm, gets called 200 - 800 times per 512 bit keygen.
1365
- var gcda1 = function () {
1366
- if ((i = x.getLowestSetBit()) > 0) {
1367
- x.rShiftTo(i, x);
1368
- }
1369
- if ((i = y.getLowestSetBit()) > 0) {
1370
- y.rShiftTo(i, y);
1371
- }
1372
- if (x.compareTo(y) >= 0) {
1373
- x.subTo(y, x);
1374
- x.rShiftTo(1, x);
1375
- }
1376
- else {
1377
- y.subTo(x, y);
1378
- y.rShiftTo(1, y);
1379
- }
1380
- if (!(x.signum() > 0)) {
1381
- if (g > 0) {
1382
- y.lShiftTo(g, y);
1383
- }
1384
- setTimeout(function () { callback(y); }, 0); // escape
1385
- }
1386
- else {
1387
- setTimeout(gcda1, 0);
1388
- }
1389
- };
1390
- setTimeout(gcda1, 10);
1391
- };
1392
- // (protected) alternate constructor
1393
- BigInteger.prototype.fromNumberAsync = function (a, b, c, callback) {
1394
- if ("number" == typeof b) {
1395
- if (a < 2) {
1396
- this.fromInt(1);
1397
- }
1398
- else {
1399
- this.fromNumber(a, c);
1400
- if (!this.testBit(a - 1)) {
1401
- this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1402
- }
1403
- if (this.isEven()) {
1404
- this.dAddOffset(1, 0);
1405
- }
1406
- var bnp_1 = this;
1407
- var bnpfn1_1 = function () {
1408
- bnp_1.dAddOffset(2, 0);
1409
- if (bnp_1.bitLength() > a) {
1410
- bnp_1.subTo(BigInteger.ONE.shiftLeft(a - 1), bnp_1);
1411
- }
1412
- if (bnp_1.isProbablePrime(b)) {
1413
- setTimeout(function () { callback(); }, 0); // escape
1414
- }
1415
- else {
1416
- setTimeout(bnpfn1_1, 0);
1417
- }
1418
- };
1419
- setTimeout(bnpfn1_1, 0);
1420
- }
1421
- }
1422
- else {
1423
- var x = [];
1424
- var t = a & 7;
1425
- x.length = (a >> 3) + 1;
1426
- b.nextBytes(x);
1427
- if (t > 0) {
1428
- x[0] &= ((1 << t) - 1);
1429
- }
1430
- else {
1431
- x[0] = 0;
1432
- }
1433
- this.fromString(x, 256);
1434
- }
1435
- };
1436
- return BigInteger;
1437
- }());
1438
- export { BigInteger };
1439
- //#region REDUCERS
1440
- //#region NullExp
1441
- var NullExp = /** @class */ (function () {
1442
- function NullExp() {
1443
- }
1444
- // NullExp.prototype.convert = nNop;
1445
- NullExp.prototype.convert = function (x) {
1446
- return x;
1447
- };
1448
- // NullExp.prototype.revert = nNop;
1449
- NullExp.prototype.revert = function (x) {
1450
- return x;
1451
- };
1452
- // NullExp.prototype.mulTo = nMulTo;
1453
- NullExp.prototype.mulTo = function (x, y, r) {
1454
- x.multiplyTo(y, r);
1455
- };
1456
- // NullExp.prototype.sqrTo = nSqrTo;
1457
- NullExp.prototype.sqrTo = function (x, r) {
1458
- x.squareTo(r);
1459
- };
1460
- return NullExp;
1461
- }());
1462
- // Modular reduction using "classic" algorithm
1463
- var Classic = /** @class */ (function () {
1464
- function Classic(m) {
1465
- this.m = m;
1466
- }
1467
- // Classic.prototype.convert = cConvert;
1468
- Classic.prototype.convert = function (x) {
1469
- if (x.s < 0 || x.compareTo(this.m) >= 0) {
1470
- return x.mod(this.m);
1471
- }
1472
- else {
1473
- return x;
1474
- }
1475
- };
1476
- // Classic.prototype.revert = cRevert;
1477
- Classic.prototype.revert = function (x) {
1478
- return x;
1479
- };
1480
- // Classic.prototype.reduce = cReduce;
1481
- Classic.prototype.reduce = function (x) {
1482
- x.divRemTo(this.m, null, x);
1483
- };
1484
- // Classic.prototype.mulTo = cMulTo;
1485
- Classic.prototype.mulTo = function (x, y, r) {
1486
- x.multiplyTo(y, r);
1487
- this.reduce(r);
1488
- };
1489
- // Classic.prototype.sqrTo = cSqrTo;
1490
- Classic.prototype.sqrTo = function (x, r) {
1491
- x.squareTo(r);
1492
- this.reduce(r);
1493
- };
1494
- return Classic;
1495
- }());
1496
- //#endregion
1497
- //#region Montgomery
1498
- // Montgomery reduction
1499
- var Montgomery = /** @class */ (function () {
1500
- function Montgomery(m) {
1501
- this.m = m;
1502
- this.mp = m.invDigit();
1503
- this.mpl = this.mp & 0x7fff;
1504
- this.mph = this.mp >> 15;
1505
- this.um = (1 << (m.DB - 15)) - 1;
1506
- this.mt2 = 2 * m.t;
1507
- }
1508
- // Montgomery.prototype.convert = montConvert;
1509
- // xR mod m
1510
- Montgomery.prototype.convert = function (x) {
1511
- var r = nbi();
1512
- x.abs().dlShiftTo(this.m.t, r);
1513
- r.divRemTo(this.m, null, r);
1514
- if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
1515
- this.m.subTo(r, r);
1516
- }
1517
- return r;
1518
- };
1519
- // Montgomery.prototype.revert = montRevert;
1520
- // x/R mod m
1521
- Montgomery.prototype.revert = function (x) {
1522
- var r = nbi();
1523
- x.copyTo(r);
1524
- this.reduce(r);
1525
- return r;
1526
- };
1527
- // Montgomery.prototype.reduce = montReduce;
1528
- // x = x/R mod m (HAC 14.32)
1529
- Montgomery.prototype.reduce = function (x) {
1530
- while (x.t <= this.mt2) {
1531
- // pad x so am has enough room later
1532
- x[x.t++] = 0;
1533
- }
1534
- for (var i = 0; i < this.m.t; ++i) {
1535
- // faster way of calculating u0 = x[i]*mp mod DV
1536
- var j = x[i] & 0x7fff;
1537
- var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
1538
- // use am to combine the multiply-shift-add into one call
1539
- j = i + this.m.t;
1540
- x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
1541
- // propagate carry
1542
- while (x[j] >= x.DV) {
1543
- x[j] -= x.DV;
1544
- x[++j]++;
1545
- }
1546
- }
1547
- x.clamp();
1548
- x.drShiftTo(this.m.t, x);
1549
- if (x.compareTo(this.m) >= 0) {
1550
- x.subTo(this.m, x);
1551
- }
1552
- };
1553
- // Montgomery.prototype.mulTo = montMulTo;
1554
- // r = "xy/R mod m"; x,y != r
1555
- Montgomery.prototype.mulTo = function (x, y, r) {
1556
- x.multiplyTo(y, r);
1557
- this.reduce(r);
1558
- };
1559
- // Montgomery.prototype.sqrTo = montSqrTo;
1560
- // r = "x^2/R mod m"; x != r
1561
- Montgomery.prototype.sqrTo = function (x, r) {
1562
- x.squareTo(r);
1563
- this.reduce(r);
1564
- };
1565
- return Montgomery;
1566
- }());
1567
- //#endregion Montgomery
1568
- //#region Barrett
1569
- // Barrett modular reduction
1570
- var Barrett = /** @class */ (function () {
1571
- function Barrett(m) {
1572
- this.m = m;
1573
- // setup Barrett
1574
- this.r2 = nbi();
1575
- this.q3 = nbi();
1576
- BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
1577
- this.mu = this.r2.divide(m);
1578
- }
1579
- // Barrett.prototype.convert = barrettConvert;
1580
- Barrett.prototype.convert = function (x) {
1581
- if (x.s < 0 || x.t > 2 * this.m.t) {
1582
- return x.mod(this.m);
1583
- }
1584
- else if (x.compareTo(this.m) < 0) {
1585
- return x;
1586
- }
1587
- else {
1588
- var r = nbi();
1589
- x.copyTo(r);
1590
- this.reduce(r);
1591
- return r;
1592
- }
1593
- };
1594
- // Barrett.prototype.revert = barrettRevert;
1595
- Barrett.prototype.revert = function (x) {
1596
- return x;
1597
- };
1598
- // Barrett.prototype.reduce = barrettReduce;
1599
- // x = x mod m (HAC 14.42)
1600
- Barrett.prototype.reduce = function (x) {
1601
- x.drShiftTo(this.m.t - 1, this.r2);
1602
- if (x.t > this.m.t + 1) {
1603
- x.t = this.m.t + 1;
1604
- x.clamp();
1605
- }
1606
- this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
1607
- this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
1608
- while (x.compareTo(this.r2) < 0) {
1609
- x.dAddOffset(1, this.m.t + 1);
1610
- }
1611
- x.subTo(this.r2, x);
1612
- while (x.compareTo(this.m) >= 0) {
1613
- x.subTo(this.m, x);
1614
- }
1615
- };
1616
- // Barrett.prototype.mulTo = barrettMulTo;
1617
- // r = x*y mod m; x,y != r
1618
- Barrett.prototype.mulTo = function (x, y, r) {
1619
- x.multiplyTo(y, r);
1620
- this.reduce(r);
1621
- };
1622
- // Barrett.prototype.sqrTo = barrettSqrTo;
1623
- // r = x^2 mod m; x != r
1624
- Barrett.prototype.sqrTo = function (x, r) {
1625
- x.squareTo(r);
1626
- this.reduce(r);
1627
- };
1628
- return Barrett;
1629
- }());
1630
- //#endregion
1631
- //#endregion REDUCERS
1632
- // return new, unset BigInteger
1633
- export function nbi() { return new BigInteger(null); }
1634
- export function parseBigInt(str, r) {
1635
- return new BigInteger(str, r);
1636
- }
1637
- // am: Compute w_j += (x*this_i), propagate carries,
1638
- // c is initial carry, returns final carry.
1639
- // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
1640
- // We need to select the fastest one that works in this environment.
1641
- var inBrowser = typeof navigator !== "undefined";
1642
- if (inBrowser && j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
1643
- // am2 avoids a big mult-and-extract completely.
1644
- // Max digit bits should be <= 30 because we do bitwise ops
1645
- // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
1646
- BigInteger.prototype.am = function am2(i, x, w, j, c, n) {
1647
- var xl = x & 0x7fff;
1648
- var xh = x >> 15;
1649
- while (--n >= 0) {
1650
- var l = this[i] & 0x7fff;
1651
- var h = this[i++] >> 15;
1652
- var m = xh * l + h * xl;
1653
- l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff);
1654
- c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
1655
- w[j++] = l & 0x3fffffff;
1656
- }
1657
- return c;
1658
- };
1659
- dbits = 30;
1660
- }
1661
- else if (inBrowser && j_lm && (navigator.appName != "Netscape")) {
1662
- // am1: use a single mult and divide to get the high bits,
1663
- // max digit bits should be 26 because
1664
- // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
1665
- BigInteger.prototype.am = function am1(i, x, w, j, c, n) {
1666
- while (--n >= 0) {
1667
- var v = x * this[i++] + w[j] + c;
1668
- c = Math.floor(v / 0x4000000);
1669
- w[j++] = v & 0x3ffffff;
1670
- }
1671
- return c;
1672
- };
1673
- dbits = 26;
1674
- }
1675
- else { // Mozilla/Netscape seems to prefer am3
1676
- // Alternately, set max digit bits to 28 since some
1677
- // browsers slow down when dealing with 32-bit numbers.
1678
- BigInteger.prototype.am = function am3(i, x, w, j, c, n) {
1679
- var xl = x & 0x3fff;
1680
- var xh = x >> 14;
1681
- while (--n >= 0) {
1682
- var l = this[i] & 0x3fff;
1683
- var h = this[i++] >> 14;
1684
- var m = xh * l + h * xl;
1685
- l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
1686
- c = (l >> 28) + (m >> 14) + xh * h;
1687
- w[j++] = l & 0xfffffff;
1688
- }
1689
- return c;
1690
- };
1691
- dbits = 28;
1692
- }
1693
- BigInteger.prototype.DB = dbits;
1694
- BigInteger.prototype.DM = ((1 << dbits) - 1);
1695
- BigInteger.prototype.DV = (1 << dbits);
1696
- var BI_FP = 52;
1697
- BigInteger.prototype.FV = Math.pow(2, BI_FP);
1698
- BigInteger.prototype.F1 = BI_FP - dbits;
1699
- BigInteger.prototype.F2 = 2 * dbits - BI_FP;
1700
- // Digit conversions
1701
- var BI_RC = [];
1702
- var rr;
1703
- var vv;
1704
- rr = "0".charCodeAt(0);
1705
- for (vv = 0; vv <= 9; ++vv) {
1706
- BI_RC[rr++] = vv;
1707
- }
1708
- rr = "a".charCodeAt(0);
1709
- for (vv = 10; vv < 36; ++vv) {
1710
- BI_RC[rr++] = vv;
1711
- }
1712
- rr = "A".charCodeAt(0);
1713
- for (vv = 10; vv < 36; ++vv) {
1714
- BI_RC[rr++] = vv;
1715
- }
1716
- export function intAt(s, i) {
1717
- var c = BI_RC[s.charCodeAt(i)];
1718
- return (c == null) ? -1 : c;
1719
- }
1720
- // return bigint initialized to value
1721
- export function nbv(i) {
1722
- var r = nbi();
1723
- r.fromInt(i);
1724
- return r;
1725
- }
1726
- // returns bit length of the integer x
1727
- export function nbits(x) {
1728
- var r = 1;
1729
- var t;
1730
- if ((t = x >>> 16) != 0) {
1731
- x = t;
1732
- r += 16;
1733
- }
1734
- if ((t = x >> 8) != 0) {
1735
- x = t;
1736
- r += 8;
1737
- }
1738
- if ((t = x >> 4) != 0) {
1739
- x = t;
1740
- r += 4;
1741
- }
1742
- if ((t = x >> 2) != 0) {
1743
- x = t;
1744
- r += 2;
1745
- }
1746
- if ((t = x >> 1) != 0) {
1747
- x = t;
1748
- r += 1;
1749
- }
1750
- return r;
1751
- }
1752
- // "constants"
1753
- BigInteger.ZERO = nbv(0);
1754
- BigInteger.ONE = nbv(1);
1
+ // Copyright (c) 2005 Tom Wu
2
+ // All Rights Reserved.
3
+ // See "LICENSE" for details.
4
+ // Basic JavaScript BN library - subset useful for RSA encryption.
5
+ import { cbit, int2char, lbit, op_and, op_andnot, op_or, op_xor } from "./util";
6
+ // Bits per digit
7
+ var dbits;
8
+ // JavaScript engine analysis
9
+ var canary = 0xdeadbeefcafe;
10
+ var j_lm = ((canary & 0xffffff) == 0xefcafe);
11
+ //#region
12
+ var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
13
+ var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
14
+ //#endregion
15
+ // (public) Constructor
16
+ var BigInteger = /** @class */ (function () {
17
+ function BigInteger(a, b, c) {
18
+ if (a != null) {
19
+ if ("number" == typeof a) {
20
+ this.fromNumber(a, b, c);
21
+ }
22
+ else if (b == null && "string" != typeof a) {
23
+ this.fromString(a, 256);
24
+ }
25
+ else {
26
+ this.fromString(a, b);
27
+ }
28
+ }
29
+ }
30
+ //#region PUBLIC
31
+ // BigInteger.prototype.toString = bnToString;
32
+ // (public) return string representation in given radix
33
+ BigInteger.prototype.toString = function (b) {
34
+ if (this.s < 0) {
35
+ return "-" + this.negate().toString(b);
36
+ }
37
+ var k;
38
+ if (b == 16) {
39
+ k = 4;
40
+ }
41
+ else if (b == 8) {
42
+ k = 3;
43
+ }
44
+ else if (b == 2) {
45
+ k = 1;
46
+ }
47
+ else if (b == 32) {
48
+ k = 5;
49
+ }
50
+ else if (b == 4) {
51
+ k = 2;
52
+ }
53
+ else {
54
+ return this.toRadix(b);
55
+ }
56
+ var km = (1 << k) - 1;
57
+ var d;
58
+ var m = false;
59
+ var r = "";
60
+ var i = this.t;
61
+ var p = this.DB - (i * this.DB) % k;
62
+ if (i-- > 0) {
63
+ if (p < this.DB && (d = this[i] >> p) > 0) {
64
+ m = true;
65
+ r = int2char(d);
66
+ }
67
+ while (i >= 0) {
68
+ if (p < k) {
69
+ d = (this[i] & ((1 << p) - 1)) << (k - p);
70
+ d |= this[--i] >> (p += this.DB - k);
71
+ }
72
+ else {
73
+ d = (this[i] >> (p -= k)) & km;
74
+ if (p <= 0) {
75
+ p += this.DB;
76
+ --i;
77
+ }
78
+ }
79
+ if (d > 0) {
80
+ m = true;
81
+ }
82
+ if (m) {
83
+ r += int2char(d);
84
+ }
85
+ }
86
+ }
87
+ return m ? r : "0";
88
+ };
89
+ // BigInteger.prototype.negate = bnNegate;
90
+ // (public) -this
91
+ BigInteger.prototype.negate = function () {
92
+ var r = nbi();
93
+ BigInteger.ZERO.subTo(this, r);
94
+ return r;
95
+ };
96
+ // BigInteger.prototype.abs = bnAbs;
97
+ // (public) |this|
98
+ BigInteger.prototype.abs = function () {
99
+ return (this.s < 0) ? this.negate() : this;
100
+ };
101
+ // BigInteger.prototype.compareTo = bnCompareTo;
102
+ // (public) return + if this > a, - if this < a, 0 if equal
103
+ BigInteger.prototype.compareTo = function (a) {
104
+ var r = this.s - a.s;
105
+ if (r != 0) {
106
+ return r;
107
+ }
108
+ var i = this.t;
109
+ r = i - a.t;
110
+ if (r != 0) {
111
+ return (this.s < 0) ? -r : r;
112
+ }
113
+ while (--i >= 0) {
114
+ if ((r = this[i] - a[i]) != 0) {
115
+ return r;
116
+ }
117
+ }
118
+ return 0;
119
+ };
120
+ // BigInteger.prototype.bitLength = bnBitLength;
121
+ // (public) return the number of bits in "this"
122
+ BigInteger.prototype.bitLength = function () {
123
+ if (this.t <= 0) {
124
+ return 0;
125
+ }
126
+ return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM));
127
+ };
128
+ // BigInteger.prototype.mod = bnMod;
129
+ // (public) this mod a
130
+ BigInteger.prototype.mod = function (a) {
131
+ var r = nbi();
132
+ this.abs().divRemTo(a, null, r);
133
+ if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
134
+ a.subTo(r, r);
135
+ }
136
+ return r;
137
+ };
138
+ // BigInteger.prototype.modPowInt = bnModPowInt;
139
+ // (public) this^e % m, 0 <= e < 2^32
140
+ BigInteger.prototype.modPowInt = function (e, m) {
141
+ var z;
142
+ if (e < 256 || m.isEven()) {
143
+ z = new Classic(m);
144
+ }
145
+ else {
146
+ z = new Montgomery(m);
147
+ }
148
+ return this.exp(e, z);
149
+ };
150
+ // BigInteger.prototype.clone = bnClone;
151
+ // (public)
152
+ BigInteger.prototype.clone = function () {
153
+ var r = nbi();
154
+ this.copyTo(r);
155
+ return r;
156
+ };
157
+ // BigInteger.prototype.intValue = bnIntValue;
158
+ // (public) return value as integer
159
+ BigInteger.prototype.intValue = function () {
160
+ if (this.s < 0) {
161
+ if (this.t == 1) {
162
+ return this[0] - this.DV;
163
+ }
164
+ else if (this.t == 0) {
165
+ return -1;
166
+ }
167
+ }
168
+ else if (this.t == 1) {
169
+ return this[0];
170
+ }
171
+ else if (this.t == 0) {
172
+ return 0;
173
+ }
174
+ // assumes 16 < DB < 32
175
+ return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0];
176
+ };
177
+ // BigInteger.prototype.byteValue = bnByteValue;
178
+ // (public) return value as byte
179
+ BigInteger.prototype.byteValue = function () {
180
+ return (this.t == 0) ? this.s : (this[0] << 24) >> 24;
181
+ };
182
+ // BigInteger.prototype.shortValue = bnShortValue;
183
+ // (public) return value as short (assumes DB>=16)
184
+ BigInteger.prototype.shortValue = function () {
185
+ return (this.t == 0) ? this.s : (this[0] << 16) >> 16;
186
+ };
187
+ // BigInteger.prototype.signum = bnSigNum;
188
+ // (public) 0 if this == 0, 1 if this > 0
189
+ BigInteger.prototype.signum = function () {
190
+ if (this.s < 0) {
191
+ return -1;
192
+ }
193
+ else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) {
194
+ return 0;
195
+ }
196
+ else {
197
+ return 1;
198
+ }
199
+ };
200
+ // BigInteger.prototype.toByteArray = bnToByteArray;
201
+ // (public) convert to bigendian byte array
202
+ BigInteger.prototype.toByteArray = function () {
203
+ var i = this.t;
204
+ var r = [];
205
+ r[0] = this.s;
206
+ var p = this.DB - (i * this.DB) % 8;
207
+ var d;
208
+ var k = 0;
209
+ if (i-- > 0) {
210
+ if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
211
+ r[k++] = d | (this.s << (this.DB - p));
212
+ }
213
+ while (i >= 0) {
214
+ if (p < 8) {
215
+ d = (this[i] & ((1 << p) - 1)) << (8 - p);
216
+ d |= this[--i] >> (p += this.DB - 8);
217
+ }
218
+ else {
219
+ d = (this[i] >> (p -= 8)) & 0xff;
220
+ if (p <= 0) {
221
+ p += this.DB;
222
+ --i;
223
+ }
224
+ }
225
+ if ((d & 0x80) != 0) {
226
+ d |= -256;
227
+ }
228
+ if (k == 0 && (this.s & 0x80) != (d & 0x80)) {
229
+ ++k;
230
+ }
231
+ if (k > 0 || d != this.s) {
232
+ r[k++] = d;
233
+ }
234
+ }
235
+ }
236
+ return r;
237
+ };
238
+ // BigInteger.prototype.equals = bnEquals;
239
+ BigInteger.prototype.equals = function (a) {
240
+ return (this.compareTo(a) == 0);
241
+ };
242
+ // BigInteger.prototype.min = bnMin;
243
+ BigInteger.prototype.min = function (a) {
244
+ return (this.compareTo(a) < 0) ? this : a;
245
+ };
246
+ // BigInteger.prototype.max = bnMax;
247
+ BigInteger.prototype.max = function (a) {
248
+ return (this.compareTo(a) > 0) ? this : a;
249
+ };
250
+ // BigInteger.prototype.and = bnAnd;
251
+ BigInteger.prototype.and = function (a) {
252
+ var r = nbi();
253
+ this.bitwiseTo(a, op_and, r);
254
+ return r;
255
+ };
256
+ // BigInteger.prototype.or = bnOr;
257
+ BigInteger.prototype.or = function (a) {
258
+ var r = nbi();
259
+ this.bitwiseTo(a, op_or, r);
260
+ return r;
261
+ };
262
+ // BigInteger.prototype.xor = bnXor;
263
+ BigInteger.prototype.xor = function (a) {
264
+ var r = nbi();
265
+ this.bitwiseTo(a, op_xor, r);
266
+ return r;
267
+ };
268
+ // BigInteger.prototype.andNot = bnAndNot;
269
+ BigInteger.prototype.andNot = function (a) {
270
+ var r = nbi();
271
+ this.bitwiseTo(a, op_andnot, r);
272
+ return r;
273
+ };
274
+ // BigInteger.prototype.not = bnNot;
275
+ // (public) ~this
276
+ BigInteger.prototype.not = function () {
277
+ var r = nbi();
278
+ for (var i = 0; i < this.t; ++i) {
279
+ r[i] = this.DM & ~this[i];
280
+ }
281
+ r.t = this.t;
282
+ r.s = ~this.s;
283
+ return r;
284
+ };
285
+ // BigInteger.prototype.shiftLeft = bnShiftLeft;
286
+ // (public) this << n
287
+ BigInteger.prototype.shiftLeft = function (n) {
288
+ var r = nbi();
289
+ if (n < 0) {
290
+ this.rShiftTo(-n, r);
291
+ }
292
+ else {
293
+ this.lShiftTo(n, r);
294
+ }
295
+ return r;
296
+ };
297
+ // BigInteger.prototype.shiftRight = bnShiftRight;
298
+ // (public) this >> n
299
+ BigInteger.prototype.shiftRight = function (n) {
300
+ var r = nbi();
301
+ if (n < 0) {
302
+ this.lShiftTo(-n, r);
303
+ }
304
+ else {
305
+ this.rShiftTo(n, r);
306
+ }
307
+ return r;
308
+ };
309
+ // BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit;
310
+ // (public) returns index of lowest 1-bit (or -1 if none)
311
+ BigInteger.prototype.getLowestSetBit = function () {
312
+ for (var i = 0; i < this.t; ++i) {
313
+ if (this[i] != 0) {
314
+ return i * this.DB + lbit(this[i]);
315
+ }
316
+ }
317
+ if (this.s < 0) {
318
+ return this.t * this.DB;
319
+ }
320
+ return -1;
321
+ };
322
+ // BigInteger.prototype.bitCount = bnBitCount;
323
+ // (public) return number of set bits
324
+ BigInteger.prototype.bitCount = function () {
325
+ var r = 0;
326
+ var x = this.s & this.DM;
327
+ for (var i = 0; i < this.t; ++i) {
328
+ r += cbit(this[i] ^ x);
329
+ }
330
+ return r;
331
+ };
332
+ // BigInteger.prototype.testBit = bnTestBit;
333
+ // (public) true iff nth bit is set
334
+ BigInteger.prototype.testBit = function (n) {
335
+ var j = Math.floor(n / this.DB);
336
+ if (j >= this.t) {
337
+ return (this.s != 0);
338
+ }
339
+ return ((this[j] & (1 << (n % this.DB))) != 0);
340
+ };
341
+ // BigInteger.prototype.setBit = bnSetBit;
342
+ // (public) this | (1<<n)
343
+ BigInteger.prototype.setBit = function (n) {
344
+ return this.changeBit(n, op_or);
345
+ };
346
+ // BigInteger.prototype.clearBit = bnClearBit;
347
+ // (public) this & ~(1<<n)
348
+ BigInteger.prototype.clearBit = function (n) {
349
+ return this.changeBit(n, op_andnot);
350
+ };
351
+ // BigInteger.prototype.flipBit = bnFlipBit;
352
+ // (public) this ^ (1<<n)
353
+ BigInteger.prototype.flipBit = function (n) {
354
+ return this.changeBit(n, op_xor);
355
+ };
356
+ // BigInteger.prototype.add = bnAdd;
357
+ // (public) this + a
358
+ BigInteger.prototype.add = function (a) {
359
+ var r = nbi();
360
+ this.addTo(a, r);
361
+ return r;
362
+ };
363
+ // BigInteger.prototype.subtract = bnSubtract;
364
+ // (public) this - a
365
+ BigInteger.prototype.subtract = function (a) {
366
+ var r = nbi();
367
+ this.subTo(a, r);
368
+ return r;
369
+ };
370
+ // BigInteger.prototype.multiply = bnMultiply;
371
+ // (public) this * a
372
+ BigInteger.prototype.multiply = function (a) {
373
+ var r = nbi();
374
+ this.multiplyTo(a, r);
375
+ return r;
376
+ };
377
+ // BigInteger.prototype.divide = bnDivide;
378
+ // (public) this / a
379
+ BigInteger.prototype.divide = function (a) {
380
+ var r = nbi();
381
+ this.divRemTo(a, r, null);
382
+ return r;
383
+ };
384
+ // BigInteger.prototype.remainder = bnRemainder;
385
+ // (public) this % a
386
+ BigInteger.prototype.remainder = function (a) {
387
+ var r = nbi();
388
+ this.divRemTo(a, null, r);
389
+ return r;
390
+ };
391
+ // BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder;
392
+ // (public) [this/a,this%a]
393
+ BigInteger.prototype.divideAndRemainder = function (a) {
394
+ var q = nbi();
395
+ var r = nbi();
396
+ this.divRemTo(a, q, r);
397
+ return [q, r];
398
+ };
399
+ // BigInteger.prototype.modPow = bnModPow;
400
+ // (public) this^e % m (HAC 14.85)
401
+ BigInteger.prototype.modPow = function (e, m) {
402
+ var i = e.bitLength();
403
+ var k;
404
+ var r = nbv(1);
405
+ var z;
406
+ if (i <= 0) {
407
+ return r;
408
+ }
409
+ else if (i < 18) {
410
+ k = 1;
411
+ }
412
+ else if (i < 48) {
413
+ k = 3;
414
+ }
415
+ else if (i < 144) {
416
+ k = 4;
417
+ }
418
+ else if (i < 768) {
419
+ k = 5;
420
+ }
421
+ else {
422
+ k = 6;
423
+ }
424
+ if (i < 8) {
425
+ z = new Classic(m);
426
+ }
427
+ else if (m.isEven()) {
428
+ z = new Barrett(m);
429
+ }
430
+ else {
431
+ z = new Montgomery(m);
432
+ }
433
+ // precomputation
434
+ var g = [];
435
+ var n = 3;
436
+ var k1 = k - 1;
437
+ var km = (1 << k) - 1;
438
+ g[1] = z.convert(this);
439
+ if (k > 1) {
440
+ var g2 = nbi();
441
+ z.sqrTo(g[1], g2);
442
+ while (n <= km) {
443
+ g[n] = nbi();
444
+ z.mulTo(g2, g[n - 2], g[n]);
445
+ n += 2;
446
+ }
447
+ }
448
+ var j = e.t - 1;
449
+ var w;
450
+ var is1 = true;
451
+ var r2 = nbi();
452
+ var t;
453
+ i = nbits(e[j]) - 1;
454
+ while (j >= 0) {
455
+ if (i >= k1) {
456
+ w = (e[j] >> (i - k1)) & km;
457
+ }
458
+ else {
459
+ w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i);
460
+ if (j > 0) {
461
+ w |= e[j - 1] >> (this.DB + i - k1);
462
+ }
463
+ }
464
+ n = k;
465
+ while ((w & 1) == 0) {
466
+ w >>= 1;
467
+ --n;
468
+ }
469
+ if ((i -= n) < 0) {
470
+ i += this.DB;
471
+ --j;
472
+ }
473
+ if (is1) { // ret == 1, don't bother squaring or multiplying it
474
+ g[w].copyTo(r);
475
+ is1 = false;
476
+ }
477
+ else {
478
+ while (n > 1) {
479
+ z.sqrTo(r, r2);
480
+ z.sqrTo(r2, r);
481
+ n -= 2;
482
+ }
483
+ if (n > 0) {
484
+ z.sqrTo(r, r2);
485
+ }
486
+ else {
487
+ t = r;
488
+ r = r2;
489
+ r2 = t;
490
+ }
491
+ z.mulTo(r2, g[w], r);
492
+ }
493
+ while (j >= 0 && (e[j] & (1 << i)) == 0) {
494
+ z.sqrTo(r, r2);
495
+ t = r;
496
+ r = r2;
497
+ r2 = t;
498
+ if (--i < 0) {
499
+ i = this.DB - 1;
500
+ --j;
501
+ }
502
+ }
503
+ }
504
+ return z.revert(r);
505
+ };
506
+ // BigInteger.prototype.modInverse = bnModInverse;
507
+ // (public) 1/this % m (HAC 14.61)
508
+ BigInteger.prototype.modInverse = function (m) {
509
+ var ac = m.isEven();
510
+ if ((this.isEven() && ac) || m.signum() == 0) {
511
+ return BigInteger.ZERO;
512
+ }
513
+ var u = m.clone();
514
+ var v = this.clone();
515
+ var a = nbv(1);
516
+ var b = nbv(0);
517
+ var c = nbv(0);
518
+ var d = nbv(1);
519
+ while (u.signum() != 0) {
520
+ while (u.isEven()) {
521
+ u.rShiftTo(1, u);
522
+ if (ac) {
523
+ if (!a.isEven() || !b.isEven()) {
524
+ a.addTo(this, a);
525
+ b.subTo(m, b);
526
+ }
527
+ a.rShiftTo(1, a);
528
+ }
529
+ else if (!b.isEven()) {
530
+ b.subTo(m, b);
531
+ }
532
+ b.rShiftTo(1, b);
533
+ }
534
+ while (v.isEven()) {
535
+ v.rShiftTo(1, v);
536
+ if (ac) {
537
+ if (!c.isEven() || !d.isEven()) {
538
+ c.addTo(this, c);
539
+ d.subTo(m, d);
540
+ }
541
+ c.rShiftTo(1, c);
542
+ }
543
+ else if (!d.isEven()) {
544
+ d.subTo(m, d);
545
+ }
546
+ d.rShiftTo(1, d);
547
+ }
548
+ if (u.compareTo(v) >= 0) {
549
+ u.subTo(v, u);
550
+ if (ac) {
551
+ a.subTo(c, a);
552
+ }
553
+ b.subTo(d, b);
554
+ }
555
+ else {
556
+ v.subTo(u, v);
557
+ if (ac) {
558
+ c.subTo(a, c);
559
+ }
560
+ d.subTo(b, d);
561
+ }
562
+ }
563
+ if (v.compareTo(BigInteger.ONE) != 0) {
564
+ return BigInteger.ZERO;
565
+ }
566
+ if (d.compareTo(m) >= 0) {
567
+ return d.subtract(m);
568
+ }
569
+ if (d.signum() < 0) {
570
+ d.addTo(m, d);
571
+ }
572
+ else {
573
+ return d;
574
+ }
575
+ if (d.signum() < 0) {
576
+ return d.add(m);
577
+ }
578
+ else {
579
+ return d;
580
+ }
581
+ };
582
+ // BigInteger.prototype.pow = bnPow;
583
+ // (public) this^e
584
+ BigInteger.prototype.pow = function (e) {
585
+ return this.exp(e, new NullExp());
586
+ };
587
+ // BigInteger.prototype.gcd = bnGCD;
588
+ // (public) gcd(this,a) (HAC 14.54)
589
+ BigInteger.prototype.gcd = function (a) {
590
+ var x = (this.s < 0) ? this.negate() : this.clone();
591
+ var y = (a.s < 0) ? a.negate() : a.clone();
592
+ if (x.compareTo(y) < 0) {
593
+ var t = x;
594
+ x = y;
595
+ y = t;
596
+ }
597
+ var i = x.getLowestSetBit();
598
+ var g = y.getLowestSetBit();
599
+ if (g < 0) {
600
+ return x;
601
+ }
602
+ if (i < g) {
603
+ g = i;
604
+ }
605
+ if (g > 0) {
606
+ x.rShiftTo(g, x);
607
+ y.rShiftTo(g, y);
608
+ }
609
+ while (x.signum() > 0) {
610
+ if ((i = x.getLowestSetBit()) > 0) {
611
+ x.rShiftTo(i, x);
612
+ }
613
+ if ((i = y.getLowestSetBit()) > 0) {
614
+ y.rShiftTo(i, y);
615
+ }
616
+ if (x.compareTo(y) >= 0) {
617
+ x.subTo(y, x);
618
+ x.rShiftTo(1, x);
619
+ }
620
+ else {
621
+ y.subTo(x, y);
622
+ y.rShiftTo(1, y);
623
+ }
624
+ }
625
+ if (g > 0) {
626
+ y.lShiftTo(g, y);
627
+ }
628
+ return y;
629
+ };
630
+ // BigInteger.prototype.isProbablePrime = bnIsProbablePrime;
631
+ // (public) test primality with certainty >= 1-.5^t
632
+ BigInteger.prototype.isProbablePrime = function (t) {
633
+ var i;
634
+ var x = this.abs();
635
+ if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
636
+ for (i = 0; i < lowprimes.length; ++i) {
637
+ if (x[0] == lowprimes[i]) {
638
+ return true;
639
+ }
640
+ }
641
+ return false;
642
+ }
643
+ if (x.isEven()) {
644
+ return false;
645
+ }
646
+ i = 1;
647
+ while (i < lowprimes.length) {
648
+ var m = lowprimes[i];
649
+ var j = i + 1;
650
+ while (j < lowprimes.length && m < lplim) {
651
+ m *= lowprimes[j++];
652
+ }
653
+ m = x.modInt(m);
654
+ while (i < j) {
655
+ if (m % lowprimes[i++] == 0) {
656
+ return false;
657
+ }
658
+ }
659
+ }
660
+ return x.millerRabin(t);
661
+ };
662
+ //#endregion PUBLIC
663
+ //#region PROTECTED
664
+ // BigInteger.prototype.copyTo = bnpCopyTo;
665
+ // (protected) copy this to r
666
+ BigInteger.prototype.copyTo = function (r) {
667
+ for (var i = this.t - 1; i >= 0; --i) {
668
+ r[i] = this[i];
669
+ }
670
+ r.t = this.t;
671
+ r.s = this.s;
672
+ };
673
+ // BigInteger.prototype.fromInt = bnpFromInt;
674
+ // (protected) set from integer value x, -DV <= x < DV
675
+ BigInteger.prototype.fromInt = function (x) {
676
+ this.t = 1;
677
+ this.s = (x < 0) ? -1 : 0;
678
+ if (x > 0) {
679
+ this[0] = x;
680
+ }
681
+ else if (x < -1) {
682
+ this[0] = x + this.DV;
683
+ }
684
+ else {
685
+ this.t = 0;
686
+ }
687
+ };
688
+ // BigInteger.prototype.fromString = bnpFromString;
689
+ // (protected) set from string and radix
690
+ BigInteger.prototype.fromString = function (s, b) {
691
+ var k;
692
+ if (b == 16) {
693
+ k = 4;
694
+ }
695
+ else if (b == 8) {
696
+ k = 3;
697
+ }
698
+ else if (b == 256) {
699
+ k = 8;
700
+ /* byte array */
701
+ }
702
+ else if (b == 2) {
703
+ k = 1;
704
+ }
705
+ else if (b == 32) {
706
+ k = 5;
707
+ }
708
+ else if (b == 4) {
709
+ k = 2;
710
+ }
711
+ else {
712
+ this.fromRadix(s, b);
713
+ return;
714
+ }
715
+ this.t = 0;
716
+ this.s = 0;
717
+ var i = s.length;
718
+ var mi = false;
719
+ var sh = 0;
720
+ while (--i >= 0) {
721
+ var x = (k == 8) ? (+s[i]) & 0xff : intAt(s, i);
722
+ if (x < 0) {
723
+ if (s.charAt(i) == "-") {
724
+ mi = true;
725
+ }
726
+ continue;
727
+ }
728
+ mi = false;
729
+ if (sh == 0) {
730
+ this[this.t++] = x;
731
+ }
732
+ else if (sh + k > this.DB) {
733
+ this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh;
734
+ this[this.t++] = (x >> (this.DB - sh));
735
+ }
736
+ else {
737
+ this[this.t - 1] |= x << sh;
738
+ }
739
+ sh += k;
740
+ if (sh >= this.DB) {
741
+ sh -= this.DB;
742
+ }
743
+ }
744
+ if (k == 8 && ((+s[0]) & 0x80) != 0) {
745
+ this.s = -1;
746
+ if (sh > 0) {
747
+ this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh;
748
+ }
749
+ }
750
+ this.clamp();
751
+ if (mi) {
752
+ BigInteger.ZERO.subTo(this, this);
753
+ }
754
+ };
755
+ // BigInteger.prototype.clamp = bnpClamp;
756
+ // (protected) clamp off excess high words
757
+ BigInteger.prototype.clamp = function () {
758
+ var c = this.s & this.DM;
759
+ while (this.t > 0 && this[this.t - 1] == c) {
760
+ --this.t;
761
+ }
762
+ };
763
+ // BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
764
+ // (protected) r = this << n*DB
765
+ BigInteger.prototype.dlShiftTo = function (n, r) {
766
+ var i;
767
+ for (i = this.t - 1; i >= 0; --i) {
768
+ r[i + n] = this[i];
769
+ }
770
+ for (i = n - 1; i >= 0; --i) {
771
+ r[i] = 0;
772
+ }
773
+ r.t = this.t + n;
774
+ r.s = this.s;
775
+ };
776
+ // BigInteger.prototype.drShiftTo = bnpDRShiftTo;
777
+ // (protected) r = this >> n*DB
778
+ BigInteger.prototype.drShiftTo = function (n, r) {
779
+ for (var i = n; i < this.t; ++i) {
780
+ r[i - n] = this[i];
781
+ }
782
+ r.t = Math.max(this.t - n, 0);
783
+ r.s = this.s;
784
+ };
785
+ // BigInteger.prototype.lShiftTo = bnpLShiftTo;
786
+ // (protected) r = this << n
787
+ BigInteger.prototype.lShiftTo = function (n, r) {
788
+ var bs = n % this.DB;
789
+ var cbs = this.DB - bs;
790
+ var bm = (1 << cbs) - 1;
791
+ var ds = Math.floor(n / this.DB);
792
+ var c = (this.s << bs) & this.DM;
793
+ for (var i = this.t - 1; i >= 0; --i) {
794
+ r[i + ds + 1] = (this[i] >> cbs) | c;
795
+ c = (this[i] & bm) << bs;
796
+ }
797
+ for (var i = ds - 1; i >= 0; --i) {
798
+ r[i] = 0;
799
+ }
800
+ r[ds] = c;
801
+ r.t = this.t + ds + 1;
802
+ r.s = this.s;
803
+ r.clamp();
804
+ };
805
+ // BigInteger.prototype.rShiftTo = bnpRShiftTo;
806
+ // (protected) r = this >> n
807
+ BigInteger.prototype.rShiftTo = function (n, r) {
808
+ r.s = this.s;
809
+ var ds = Math.floor(n / this.DB);
810
+ if (ds >= this.t) {
811
+ r.t = 0;
812
+ return;
813
+ }
814
+ var bs = n % this.DB;
815
+ var cbs = this.DB - bs;
816
+ var bm = (1 << bs) - 1;
817
+ r[0] = this[ds] >> bs;
818
+ for (var i = ds + 1; i < this.t; ++i) {
819
+ r[i - ds - 1] |= (this[i] & bm) << cbs;
820
+ r[i - ds] = this[i] >> bs;
821
+ }
822
+ if (bs > 0) {
823
+ r[this.t - ds - 1] |= (this.s & bm) << cbs;
824
+ }
825
+ r.t = this.t - ds;
826
+ r.clamp();
827
+ };
828
+ // BigInteger.prototype.subTo = bnpSubTo;
829
+ // (protected) r = this - a
830
+ BigInteger.prototype.subTo = function (a, r) {
831
+ var i = 0;
832
+ var c = 0;
833
+ var m = Math.min(a.t, this.t);
834
+ while (i < m) {
835
+ c += this[i] - a[i];
836
+ r[i++] = c & this.DM;
837
+ c >>= this.DB;
838
+ }
839
+ if (a.t < this.t) {
840
+ c -= a.s;
841
+ while (i < this.t) {
842
+ c += this[i];
843
+ r[i++] = c & this.DM;
844
+ c >>= this.DB;
845
+ }
846
+ c += this.s;
847
+ }
848
+ else {
849
+ c += this.s;
850
+ while (i < a.t) {
851
+ c -= a[i];
852
+ r[i++] = c & this.DM;
853
+ c >>= this.DB;
854
+ }
855
+ c -= a.s;
856
+ }
857
+ r.s = (c < 0) ? -1 : 0;
858
+ if (c < -1) {
859
+ r[i++] = this.DV + c;
860
+ }
861
+ else if (c > 0) {
862
+ r[i++] = c;
863
+ }
864
+ r.t = i;
865
+ r.clamp();
866
+ };
867
+ // BigInteger.prototype.multiplyTo = bnpMultiplyTo;
868
+ // (protected) r = this * a, r != this,a (HAC 14.12)
869
+ // "this" should be the larger one if appropriate.
870
+ BigInteger.prototype.multiplyTo = function (a, r) {
871
+ var x = this.abs();
872
+ var y = a.abs();
873
+ var i = x.t;
874
+ r.t = i + y.t;
875
+ while (--i >= 0) {
876
+ r[i] = 0;
877
+ }
878
+ for (i = 0; i < y.t; ++i) {
879
+ r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
880
+ }
881
+ r.s = 0;
882
+ r.clamp();
883
+ if (this.s != a.s) {
884
+ BigInteger.ZERO.subTo(r, r);
885
+ }
886
+ };
887
+ // BigInteger.prototype.squareTo = bnpSquareTo;
888
+ // (protected) r = this^2, r != this (HAC 14.16)
889
+ BigInteger.prototype.squareTo = function (r) {
890
+ var x = this.abs();
891
+ var i = r.t = 2 * x.t;
892
+ while (--i >= 0) {
893
+ r[i] = 0;
894
+ }
895
+ for (i = 0; i < x.t - 1; ++i) {
896
+ var c = x.am(i, x[i], r, 2 * i, 0, 1);
897
+ if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
898
+ r[i + x.t] -= x.DV;
899
+ r[i + x.t + 1] = 1;
900
+ }
901
+ }
902
+ if (r.t > 0) {
903
+ r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
904
+ }
905
+ r.s = 0;
906
+ r.clamp();
907
+ };
908
+ // BigInteger.prototype.divRemTo = bnpDivRemTo;
909
+ // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
910
+ // r != q, this != m. q or r may be null.
911
+ BigInteger.prototype.divRemTo = function (m, q, r) {
912
+ var pm = m.abs();
913
+ if (pm.t <= 0) {
914
+ return;
915
+ }
916
+ var pt = this.abs();
917
+ if (pt.t < pm.t) {
918
+ if (q != null) {
919
+ q.fromInt(0);
920
+ }
921
+ if (r != null) {
922
+ this.copyTo(r);
923
+ }
924
+ return;
925
+ }
926
+ if (r == null) {
927
+ r = nbi();
928
+ }
929
+ var y = nbi();
930
+ var ts = this.s;
931
+ var ms = m.s;
932
+ var nsh = this.DB - nbits(pm[pm.t - 1]); // normalize modulus
933
+ if (nsh > 0) {
934
+ pm.lShiftTo(nsh, y);
935
+ pt.lShiftTo(nsh, r);
936
+ }
937
+ else {
938
+ pm.copyTo(y);
939
+ pt.copyTo(r);
940
+ }
941
+ var ys = y.t;
942
+ var y0 = y[ys - 1];
943
+ if (y0 == 0) {
944
+ return;
945
+ }
946
+ var yt = y0 * (1 << this.F1) + ((ys > 1) ? y[ys - 2] >> this.F2 : 0);
947
+ var d1 = this.FV / yt;
948
+ var d2 = (1 << this.F1) / yt;
949
+ var e = 1 << this.F2;
950
+ var i = r.t;
951
+ var j = i - ys;
952
+ var t = (q == null) ? nbi() : q;
953
+ y.dlShiftTo(j, t);
954
+ if (r.compareTo(t) >= 0) {
955
+ r[r.t++] = 1;
956
+ r.subTo(t, r);
957
+ }
958
+ BigInteger.ONE.dlShiftTo(ys, t);
959
+ t.subTo(y, y); // "negative" y so we can replace sub with am later
960
+ while (y.t < ys) {
961
+ y[y.t++] = 0;
962
+ }
963
+ while (--j >= 0) {
964
+ // Estimate quotient digit
965
+ var qd = (r[--i] == y0) ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
966
+ if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) { // Try it out
967
+ y.dlShiftTo(j, t);
968
+ r.subTo(t, r);
969
+ while (r[i] < --qd) {
970
+ r.subTo(t, r);
971
+ }
972
+ }
973
+ }
974
+ if (q != null) {
975
+ r.drShiftTo(ys, q);
976
+ if (ts != ms) {
977
+ BigInteger.ZERO.subTo(q, q);
978
+ }
979
+ }
980
+ r.t = ys;
981
+ r.clamp();
982
+ if (nsh > 0) {
983
+ r.rShiftTo(nsh, r);
984
+ } // Denormalize remainder
985
+ if (ts < 0) {
986
+ BigInteger.ZERO.subTo(r, r);
987
+ }
988
+ };
989
+ // BigInteger.prototype.invDigit = bnpInvDigit;
990
+ // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
991
+ // justification:
992
+ // xy == 1 (mod m)
993
+ // xy = 1+km
994
+ // xy(2-xy) = (1+km)(1-km)
995
+ // x[y(2-xy)] = 1-k^2m^2
996
+ // x[y(2-xy)] == 1 (mod m^2)
997
+ // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
998
+ // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
999
+ // JS multiply "overflows" differently from C/C++, so care is needed here.
1000
+ BigInteger.prototype.invDigit = function () {
1001
+ if (this.t < 1) {
1002
+ return 0;
1003
+ }
1004
+ var x = this[0];
1005
+ if ((x & 1) == 0) {
1006
+ return 0;
1007
+ }
1008
+ var y = x & 3; // y == 1/x mod 2^2
1009
+ y = (y * (2 - (x & 0xf) * y)) & 0xf; // y == 1/x mod 2^4
1010
+ y = (y * (2 - (x & 0xff) * y)) & 0xff; // y == 1/x mod 2^8
1011
+ y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff; // y == 1/x mod 2^16
1012
+ // last step - calculate inverse mod DV directly;
1013
+ // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
1014
+ y = (y * (2 - x * y % this.DV)) % this.DV; // y == 1/x mod 2^dbits
1015
+ // we really want the negative inverse, and -DV < y < DV
1016
+ return (y > 0) ? this.DV - y : -y;
1017
+ };
1018
+ // BigInteger.prototype.isEven = bnpIsEven;
1019
+ // (protected) true iff this is even
1020
+ BigInteger.prototype.isEven = function () {
1021
+ return ((this.t > 0) ? (this[0] & 1) : this.s) == 0;
1022
+ };
1023
+ // BigInteger.prototype.exp = bnpExp;
1024
+ // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
1025
+ BigInteger.prototype.exp = function (e, z) {
1026
+ if (e > 0xffffffff || e < 1) {
1027
+ return BigInteger.ONE;
1028
+ }
1029
+ var r = nbi();
1030
+ var r2 = nbi();
1031
+ var g = z.convert(this);
1032
+ var i = nbits(e) - 1;
1033
+ g.copyTo(r);
1034
+ while (--i >= 0) {
1035
+ z.sqrTo(r, r2);
1036
+ if ((e & (1 << i)) > 0) {
1037
+ z.mulTo(r2, g, r);
1038
+ }
1039
+ else {
1040
+ var t = r;
1041
+ r = r2;
1042
+ r2 = t;
1043
+ }
1044
+ }
1045
+ return z.revert(r);
1046
+ };
1047
+ // BigInteger.prototype.chunkSize = bnpChunkSize;
1048
+ // (protected) return x s.t. r^x < DV
1049
+ BigInteger.prototype.chunkSize = function (r) {
1050
+ return Math.floor(Math.LN2 * this.DB / Math.log(r));
1051
+ };
1052
+ // BigInteger.prototype.toRadix = bnpToRadix;
1053
+ // (protected) convert to radix string
1054
+ BigInteger.prototype.toRadix = function (b) {
1055
+ if (b == null) {
1056
+ b = 10;
1057
+ }
1058
+ if (this.signum() == 0 || b < 2 || b > 36) {
1059
+ return "0";
1060
+ }
1061
+ var cs = this.chunkSize(b);
1062
+ var a = Math.pow(b, cs);
1063
+ var d = nbv(a);
1064
+ var y = nbi();
1065
+ var z = nbi();
1066
+ var r = "";
1067
+ this.divRemTo(d, y, z);
1068
+ while (y.signum() > 0) {
1069
+ r = (a + z.intValue()).toString(b).substr(1) + r;
1070
+ y.divRemTo(d, y, z);
1071
+ }
1072
+ return z.intValue().toString(b) + r;
1073
+ };
1074
+ // BigInteger.prototype.fromRadix = bnpFromRadix;
1075
+ // (protected) convert from radix string
1076
+ BigInteger.prototype.fromRadix = function (s, b) {
1077
+ this.fromInt(0);
1078
+ if (b == null) {
1079
+ b = 10;
1080
+ }
1081
+ var cs = this.chunkSize(b);
1082
+ var d = Math.pow(b, cs);
1083
+ var mi = false;
1084
+ var j = 0;
1085
+ var w = 0;
1086
+ for (var i = 0; i < s.length; ++i) {
1087
+ var x = intAt(s, i);
1088
+ if (x < 0) {
1089
+ if (s.charAt(i) == "-" && this.signum() == 0) {
1090
+ mi = true;
1091
+ }
1092
+ continue;
1093
+ }
1094
+ w = b * w + x;
1095
+ if (++j >= cs) {
1096
+ this.dMultiply(d);
1097
+ this.dAddOffset(w, 0);
1098
+ j = 0;
1099
+ w = 0;
1100
+ }
1101
+ }
1102
+ if (j > 0) {
1103
+ this.dMultiply(Math.pow(b, j));
1104
+ this.dAddOffset(w, 0);
1105
+ }
1106
+ if (mi) {
1107
+ BigInteger.ZERO.subTo(this, this);
1108
+ }
1109
+ };
1110
+ // BigInteger.prototype.fromNumber = bnpFromNumber;
1111
+ // (protected) alternate constructor
1112
+ BigInteger.prototype.fromNumber = function (a, b, c) {
1113
+ if ("number" == typeof b) {
1114
+ // new BigInteger(int,int,RNG)
1115
+ if (a < 2) {
1116
+ this.fromInt(1);
1117
+ }
1118
+ else {
1119
+ this.fromNumber(a, c);
1120
+ if (!this.testBit(a - 1)) {
1121
+ // force MSB set
1122
+ this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1123
+ }
1124
+ if (this.isEven()) {
1125
+ this.dAddOffset(1, 0);
1126
+ } // force odd
1127
+ while (!this.isProbablePrime(b)) {
1128
+ this.dAddOffset(2, 0);
1129
+ if (this.bitLength() > a) {
1130
+ this.subTo(BigInteger.ONE.shiftLeft(a - 1), this);
1131
+ }
1132
+ }
1133
+ }
1134
+ }
1135
+ else {
1136
+ // new BigInteger(int,RNG)
1137
+ var x = [];
1138
+ var t = a & 7;
1139
+ x.length = (a >> 3) + 1;
1140
+ b.nextBytes(x);
1141
+ if (t > 0) {
1142
+ x[0] &= ((1 << t) - 1);
1143
+ }
1144
+ else {
1145
+ x[0] = 0;
1146
+ }
1147
+ this.fromString(x, 256);
1148
+ }
1149
+ };
1150
+ // BigInteger.prototype.bitwiseTo = bnpBitwiseTo;
1151
+ // (protected) r = this op a (bitwise)
1152
+ BigInteger.prototype.bitwiseTo = function (a, op, r) {
1153
+ var i;
1154
+ var f;
1155
+ var m = Math.min(a.t, this.t);
1156
+ for (i = 0; i < m; ++i) {
1157
+ r[i] = op(this[i], a[i]);
1158
+ }
1159
+ if (a.t < this.t) {
1160
+ f = a.s & this.DM;
1161
+ for (i = m; i < this.t; ++i) {
1162
+ r[i] = op(this[i], f);
1163
+ }
1164
+ r.t = this.t;
1165
+ }
1166
+ else {
1167
+ f = this.s & this.DM;
1168
+ for (i = m; i < a.t; ++i) {
1169
+ r[i] = op(f, a[i]);
1170
+ }
1171
+ r.t = a.t;
1172
+ }
1173
+ r.s = op(this.s, a.s);
1174
+ r.clamp();
1175
+ };
1176
+ // BigInteger.prototype.changeBit = bnpChangeBit;
1177
+ // (protected) this op (1<<n)
1178
+ BigInteger.prototype.changeBit = function (n, op) {
1179
+ var r = BigInteger.ONE.shiftLeft(n);
1180
+ this.bitwiseTo(r, op, r);
1181
+ return r;
1182
+ };
1183
+ // BigInteger.prototype.addTo = bnpAddTo;
1184
+ // (protected) r = this + a
1185
+ BigInteger.prototype.addTo = function (a, r) {
1186
+ var i = 0;
1187
+ var c = 0;
1188
+ var m = Math.min(a.t, this.t);
1189
+ while (i < m) {
1190
+ c += this[i] + a[i];
1191
+ r[i++] = c & this.DM;
1192
+ c >>= this.DB;
1193
+ }
1194
+ if (a.t < this.t) {
1195
+ c += a.s;
1196
+ while (i < this.t) {
1197
+ c += this[i];
1198
+ r[i++] = c & this.DM;
1199
+ c >>= this.DB;
1200
+ }
1201
+ c += this.s;
1202
+ }
1203
+ else {
1204
+ c += this.s;
1205
+ while (i < a.t) {
1206
+ c += a[i];
1207
+ r[i++] = c & this.DM;
1208
+ c >>= this.DB;
1209
+ }
1210
+ c += a.s;
1211
+ }
1212
+ r.s = (c < 0) ? -1 : 0;
1213
+ if (c > 0) {
1214
+ r[i++] = c;
1215
+ }
1216
+ else if (c < -1) {
1217
+ r[i++] = this.DV + c;
1218
+ }
1219
+ r.t = i;
1220
+ r.clamp();
1221
+ };
1222
+ // BigInteger.prototype.dMultiply = bnpDMultiply;
1223
+ // (protected) this *= n, this >= 0, 1 < n < DV
1224
+ BigInteger.prototype.dMultiply = function (n) {
1225
+ this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
1226
+ ++this.t;
1227
+ this.clamp();
1228
+ };
1229
+ // BigInteger.prototype.dAddOffset = bnpDAddOffset;
1230
+ // (protected) this += n << w words, this >= 0
1231
+ BigInteger.prototype.dAddOffset = function (n, w) {
1232
+ if (n == 0) {
1233
+ return;
1234
+ }
1235
+ while (this.t <= w) {
1236
+ this[this.t++] = 0;
1237
+ }
1238
+ this[w] += n;
1239
+ while (this[w] >= this.DV) {
1240
+ this[w] -= this.DV;
1241
+ if (++w >= this.t) {
1242
+ this[this.t++] = 0;
1243
+ }
1244
+ ++this[w];
1245
+ }
1246
+ };
1247
+ // BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
1248
+ // (protected) r = lower n words of "this * a", a.t <= n
1249
+ // "this" should be the larger one if appropriate.
1250
+ BigInteger.prototype.multiplyLowerTo = function (a, n, r) {
1251
+ var i = Math.min(this.t + a.t, n);
1252
+ r.s = 0; // assumes a,this >= 0
1253
+ r.t = i;
1254
+ while (i > 0) {
1255
+ r[--i] = 0;
1256
+ }
1257
+ for (var j = r.t - this.t; i < j; ++i) {
1258
+ r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
1259
+ }
1260
+ for (var j = Math.min(a.t, n); i < j; ++i) {
1261
+ this.am(0, a[i], r, i, 0, n - i);
1262
+ }
1263
+ r.clamp();
1264
+ };
1265
+ // BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
1266
+ // (protected) r = "this * a" without lower n words, n > 0
1267
+ // "this" should be the larger one if appropriate.
1268
+ BigInteger.prototype.multiplyUpperTo = function (a, n, r) {
1269
+ --n;
1270
+ var i = r.t = this.t + a.t - n;
1271
+ r.s = 0; // assumes a,this >= 0
1272
+ while (--i >= 0) {
1273
+ r[i] = 0;
1274
+ }
1275
+ for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
1276
+ r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
1277
+ }
1278
+ r.clamp();
1279
+ r.drShiftTo(1, r);
1280
+ };
1281
+ // BigInteger.prototype.modInt = bnpModInt;
1282
+ // (protected) this % n, n < 2^26
1283
+ BigInteger.prototype.modInt = function (n) {
1284
+ if (n <= 0) {
1285
+ return 0;
1286
+ }
1287
+ var d = this.DV % n;
1288
+ var r = (this.s < 0) ? n - 1 : 0;
1289
+ if (this.t > 0) {
1290
+ if (d == 0) {
1291
+ r = this[0] % n;
1292
+ }
1293
+ else {
1294
+ for (var i = this.t - 1; i >= 0; --i) {
1295
+ r = (d * r + this[i]) % n;
1296
+ }
1297
+ }
1298
+ }
1299
+ return r;
1300
+ };
1301
+ // BigInteger.prototype.millerRabin = bnpMillerRabin;
1302
+ // (protected) true if probably prime (HAC 4.24, Miller-Rabin)
1303
+ BigInteger.prototype.millerRabin = function (t) {
1304
+ var n1 = this.subtract(BigInteger.ONE);
1305
+ var k = n1.getLowestSetBit();
1306
+ if (k <= 0) {
1307
+ return false;
1308
+ }
1309
+ var r = n1.shiftRight(k);
1310
+ t = (t + 1) >> 1;
1311
+ if (t > lowprimes.length) {
1312
+ t = lowprimes.length;
1313
+ }
1314
+ var a = nbi();
1315
+ for (var i = 0; i < t; ++i) {
1316
+ // Pick bases at random, instead of starting at 2
1317
+ a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
1318
+ var y = a.modPow(r, this);
1319
+ if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
1320
+ var j = 1;
1321
+ while (j++ < k && y.compareTo(n1) != 0) {
1322
+ y = y.modPowInt(2, this);
1323
+ if (y.compareTo(BigInteger.ONE) == 0) {
1324
+ return false;
1325
+ }
1326
+ }
1327
+ if (y.compareTo(n1) != 0) {
1328
+ return false;
1329
+ }
1330
+ }
1331
+ }
1332
+ return true;
1333
+ };
1334
+ // BigInteger.prototype.square = bnSquare;
1335
+ // (public) this^2
1336
+ BigInteger.prototype.square = function () {
1337
+ var r = nbi();
1338
+ this.squareTo(r);
1339
+ return r;
1340
+ };
1341
+ //#region ASYNC
1342
+ // Public API method
1343
+ BigInteger.prototype.gcda = function (a, callback) {
1344
+ var x = (this.s < 0) ? this.negate() : this.clone();
1345
+ var y = (a.s < 0) ? a.negate() : a.clone();
1346
+ if (x.compareTo(y) < 0) {
1347
+ var t = x;
1348
+ x = y;
1349
+ y = t;
1350
+ }
1351
+ var i = x.getLowestSetBit();
1352
+ var g = y.getLowestSetBit();
1353
+ if (g < 0) {
1354
+ callback(x);
1355
+ return;
1356
+ }
1357
+ if (i < g) {
1358
+ g = i;
1359
+ }
1360
+ if (g > 0) {
1361
+ x.rShiftTo(g, x);
1362
+ y.rShiftTo(g, y);
1363
+ }
1364
+ // Workhorse of the algorithm, gets called 200 - 800 times per 512 bit keygen.
1365
+ var gcda1 = function () {
1366
+ if ((i = x.getLowestSetBit()) > 0) {
1367
+ x.rShiftTo(i, x);
1368
+ }
1369
+ if ((i = y.getLowestSetBit()) > 0) {
1370
+ y.rShiftTo(i, y);
1371
+ }
1372
+ if (x.compareTo(y) >= 0) {
1373
+ x.subTo(y, x);
1374
+ x.rShiftTo(1, x);
1375
+ }
1376
+ else {
1377
+ y.subTo(x, y);
1378
+ y.rShiftTo(1, y);
1379
+ }
1380
+ if (!(x.signum() > 0)) {
1381
+ if (g > 0) {
1382
+ y.lShiftTo(g, y);
1383
+ }
1384
+ setTimeout(function () { callback(y); }, 0); // escape
1385
+ }
1386
+ else {
1387
+ setTimeout(gcda1, 0);
1388
+ }
1389
+ };
1390
+ setTimeout(gcda1, 10);
1391
+ };
1392
+ // (protected) alternate constructor
1393
+ BigInteger.prototype.fromNumberAsync = function (a, b, c, callback) {
1394
+ if ("number" == typeof b) {
1395
+ if (a < 2) {
1396
+ this.fromInt(1);
1397
+ }
1398
+ else {
1399
+ this.fromNumber(a, c);
1400
+ if (!this.testBit(a - 1)) {
1401
+ this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this);
1402
+ }
1403
+ if (this.isEven()) {
1404
+ this.dAddOffset(1, 0);
1405
+ }
1406
+ var bnp_1 = this;
1407
+ var bnpfn1_1 = function () {
1408
+ bnp_1.dAddOffset(2, 0);
1409
+ if (bnp_1.bitLength() > a) {
1410
+ bnp_1.subTo(BigInteger.ONE.shiftLeft(a - 1), bnp_1);
1411
+ }
1412
+ if (bnp_1.isProbablePrime(b)) {
1413
+ setTimeout(function () { callback(); }, 0); // escape
1414
+ }
1415
+ else {
1416
+ setTimeout(bnpfn1_1, 0);
1417
+ }
1418
+ };
1419
+ setTimeout(bnpfn1_1, 0);
1420
+ }
1421
+ }
1422
+ else {
1423
+ var x = [];
1424
+ var t = a & 7;
1425
+ x.length = (a >> 3) + 1;
1426
+ b.nextBytes(x);
1427
+ if (t > 0) {
1428
+ x[0] &= ((1 << t) - 1);
1429
+ }
1430
+ else {
1431
+ x[0] = 0;
1432
+ }
1433
+ this.fromString(x, 256);
1434
+ }
1435
+ };
1436
+ return BigInteger;
1437
+ }());
1438
+ export { BigInteger };
1439
+ //#region REDUCERS
1440
+ //#region NullExp
1441
+ var NullExp = /** @class */ (function () {
1442
+ function NullExp() {
1443
+ }
1444
+ // NullExp.prototype.convert = nNop;
1445
+ NullExp.prototype.convert = function (x) {
1446
+ return x;
1447
+ };
1448
+ // NullExp.prototype.revert = nNop;
1449
+ NullExp.prototype.revert = function (x) {
1450
+ return x;
1451
+ };
1452
+ // NullExp.prototype.mulTo = nMulTo;
1453
+ NullExp.prototype.mulTo = function (x, y, r) {
1454
+ x.multiplyTo(y, r);
1455
+ };
1456
+ // NullExp.prototype.sqrTo = nSqrTo;
1457
+ NullExp.prototype.sqrTo = function (x, r) {
1458
+ x.squareTo(r);
1459
+ };
1460
+ return NullExp;
1461
+ }());
1462
+ // Modular reduction using "classic" algorithm
1463
+ var Classic = /** @class */ (function () {
1464
+ function Classic(m) {
1465
+ this.m = m;
1466
+ }
1467
+ // Classic.prototype.convert = cConvert;
1468
+ Classic.prototype.convert = function (x) {
1469
+ if (x.s < 0 || x.compareTo(this.m) >= 0) {
1470
+ return x.mod(this.m);
1471
+ }
1472
+ else {
1473
+ return x;
1474
+ }
1475
+ };
1476
+ // Classic.prototype.revert = cRevert;
1477
+ Classic.prototype.revert = function (x) {
1478
+ return x;
1479
+ };
1480
+ // Classic.prototype.reduce = cReduce;
1481
+ Classic.prototype.reduce = function (x) {
1482
+ x.divRemTo(this.m, null, x);
1483
+ };
1484
+ // Classic.prototype.mulTo = cMulTo;
1485
+ Classic.prototype.mulTo = function (x, y, r) {
1486
+ x.multiplyTo(y, r);
1487
+ this.reduce(r);
1488
+ };
1489
+ // Classic.prototype.sqrTo = cSqrTo;
1490
+ Classic.prototype.sqrTo = function (x, r) {
1491
+ x.squareTo(r);
1492
+ this.reduce(r);
1493
+ };
1494
+ return Classic;
1495
+ }());
1496
+ //#endregion
1497
+ //#region Montgomery
1498
+ // Montgomery reduction
1499
+ var Montgomery = /** @class */ (function () {
1500
+ function Montgomery(m) {
1501
+ this.m = m;
1502
+ this.mp = m.invDigit();
1503
+ this.mpl = this.mp & 0x7fff;
1504
+ this.mph = this.mp >> 15;
1505
+ this.um = (1 << (m.DB - 15)) - 1;
1506
+ this.mt2 = 2 * m.t;
1507
+ }
1508
+ // Montgomery.prototype.convert = montConvert;
1509
+ // xR mod m
1510
+ Montgomery.prototype.convert = function (x) {
1511
+ var r = nbi();
1512
+ x.abs().dlShiftTo(this.m.t, r);
1513
+ r.divRemTo(this.m, null, r);
1514
+ if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
1515
+ this.m.subTo(r, r);
1516
+ }
1517
+ return r;
1518
+ };
1519
+ // Montgomery.prototype.revert = montRevert;
1520
+ // x/R mod m
1521
+ Montgomery.prototype.revert = function (x) {
1522
+ var r = nbi();
1523
+ x.copyTo(r);
1524
+ this.reduce(r);
1525
+ return r;
1526
+ };
1527
+ // Montgomery.prototype.reduce = montReduce;
1528
+ // x = x/R mod m (HAC 14.32)
1529
+ Montgomery.prototype.reduce = function (x) {
1530
+ while (x.t <= this.mt2) {
1531
+ // pad x so am has enough room later
1532
+ x[x.t++] = 0;
1533
+ }
1534
+ for (var i = 0; i < this.m.t; ++i) {
1535
+ // faster way of calculating u0 = x[i]*mp mod DV
1536
+ var j = x[i] & 0x7fff;
1537
+ var u0 = (j * this.mpl + (((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) & x.DM;
1538
+ // use am to combine the multiply-shift-add into one call
1539
+ j = i + this.m.t;
1540
+ x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
1541
+ // propagate carry
1542
+ while (x[j] >= x.DV) {
1543
+ x[j] -= x.DV;
1544
+ x[++j]++;
1545
+ }
1546
+ }
1547
+ x.clamp();
1548
+ x.drShiftTo(this.m.t, x);
1549
+ if (x.compareTo(this.m) >= 0) {
1550
+ x.subTo(this.m, x);
1551
+ }
1552
+ };
1553
+ // Montgomery.prototype.mulTo = montMulTo;
1554
+ // r = "xy/R mod m"; x,y != r
1555
+ Montgomery.prototype.mulTo = function (x, y, r) {
1556
+ x.multiplyTo(y, r);
1557
+ this.reduce(r);
1558
+ };
1559
+ // Montgomery.prototype.sqrTo = montSqrTo;
1560
+ // r = "x^2/R mod m"; x != r
1561
+ Montgomery.prototype.sqrTo = function (x, r) {
1562
+ x.squareTo(r);
1563
+ this.reduce(r);
1564
+ };
1565
+ return Montgomery;
1566
+ }());
1567
+ //#endregion Montgomery
1568
+ //#region Barrett
1569
+ // Barrett modular reduction
1570
+ var Barrett = /** @class */ (function () {
1571
+ function Barrett(m) {
1572
+ this.m = m;
1573
+ // setup Barrett
1574
+ this.r2 = nbi();
1575
+ this.q3 = nbi();
1576
+ BigInteger.ONE.dlShiftTo(2 * m.t, this.r2);
1577
+ this.mu = this.r2.divide(m);
1578
+ }
1579
+ // Barrett.prototype.convert = barrettConvert;
1580
+ Barrett.prototype.convert = function (x) {
1581
+ if (x.s < 0 || x.t > 2 * this.m.t) {
1582
+ return x.mod(this.m);
1583
+ }
1584
+ else if (x.compareTo(this.m) < 0) {
1585
+ return x;
1586
+ }
1587
+ else {
1588
+ var r = nbi();
1589
+ x.copyTo(r);
1590
+ this.reduce(r);
1591
+ return r;
1592
+ }
1593
+ };
1594
+ // Barrett.prototype.revert = barrettRevert;
1595
+ Barrett.prototype.revert = function (x) {
1596
+ return x;
1597
+ };
1598
+ // Barrett.prototype.reduce = barrettReduce;
1599
+ // x = x mod m (HAC 14.42)
1600
+ Barrett.prototype.reduce = function (x) {
1601
+ x.drShiftTo(this.m.t - 1, this.r2);
1602
+ if (x.t > this.m.t + 1) {
1603
+ x.t = this.m.t + 1;
1604
+ x.clamp();
1605
+ }
1606
+ this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
1607
+ this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
1608
+ while (x.compareTo(this.r2) < 0) {
1609
+ x.dAddOffset(1, this.m.t + 1);
1610
+ }
1611
+ x.subTo(this.r2, x);
1612
+ while (x.compareTo(this.m) >= 0) {
1613
+ x.subTo(this.m, x);
1614
+ }
1615
+ };
1616
+ // Barrett.prototype.mulTo = barrettMulTo;
1617
+ // r = x*y mod m; x,y != r
1618
+ Barrett.prototype.mulTo = function (x, y, r) {
1619
+ x.multiplyTo(y, r);
1620
+ this.reduce(r);
1621
+ };
1622
+ // Barrett.prototype.sqrTo = barrettSqrTo;
1623
+ // r = x^2 mod m; x != r
1624
+ Barrett.prototype.sqrTo = function (x, r) {
1625
+ x.squareTo(r);
1626
+ this.reduce(r);
1627
+ };
1628
+ return Barrett;
1629
+ }());
1630
+ //#endregion
1631
+ //#endregion REDUCERS
1632
+ // return new, unset BigInteger
1633
+ export function nbi() { return new BigInteger(null); }
1634
+ export function parseBigInt(str, r) {
1635
+ return new BigInteger(str, r);
1636
+ }
1637
+ // am: Compute w_j += (x*this_i), propagate carries,
1638
+ // c is initial carry, returns final carry.
1639
+ // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
1640
+ // We need to select the fastest one that works in this environment.
1641
+ var inBrowser = typeof navigator !== "undefined";
1642
+ if (inBrowser && j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
1643
+ // am2 avoids a big mult-and-extract completely.
1644
+ // Max digit bits should be <= 30 because we do bitwise ops
1645
+ // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
1646
+ BigInteger.prototype.am = function am2(i, x, w, j, c, n) {
1647
+ var xl = x & 0x7fff;
1648
+ var xh = x >> 15;
1649
+ while (--n >= 0) {
1650
+ var l = this[i] & 0x7fff;
1651
+ var h = this[i++] >> 15;
1652
+ var m = xh * l + h * xl;
1653
+ l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff);
1654
+ c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
1655
+ w[j++] = l & 0x3fffffff;
1656
+ }
1657
+ return c;
1658
+ };
1659
+ dbits = 30;
1660
+ }
1661
+ else if (inBrowser && j_lm && (navigator.appName != "Netscape")) {
1662
+ // am1: use a single mult and divide to get the high bits,
1663
+ // max digit bits should be 26 because
1664
+ // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
1665
+ BigInteger.prototype.am = function am1(i, x, w, j, c, n) {
1666
+ while (--n >= 0) {
1667
+ var v = x * this[i++] + w[j] + c;
1668
+ c = Math.floor(v / 0x4000000);
1669
+ w[j++] = v & 0x3ffffff;
1670
+ }
1671
+ return c;
1672
+ };
1673
+ dbits = 26;
1674
+ }
1675
+ else { // Mozilla/Netscape seems to prefer am3
1676
+ // Alternately, set max digit bits to 28 since some
1677
+ // browsers slow down when dealing with 32-bit numbers.
1678
+ BigInteger.prototype.am = function am3(i, x, w, j, c, n) {
1679
+ var xl = x & 0x3fff;
1680
+ var xh = x >> 14;
1681
+ while (--n >= 0) {
1682
+ var l = this[i] & 0x3fff;
1683
+ var h = this[i++] >> 14;
1684
+ var m = xh * l + h * xl;
1685
+ l = xl * l + ((m & 0x3fff) << 14) + w[j] + c;
1686
+ c = (l >> 28) + (m >> 14) + xh * h;
1687
+ w[j++] = l & 0xfffffff;
1688
+ }
1689
+ return c;
1690
+ };
1691
+ dbits = 28;
1692
+ }
1693
+ BigInteger.prototype.DB = dbits;
1694
+ BigInteger.prototype.DM = ((1 << dbits) - 1);
1695
+ BigInteger.prototype.DV = (1 << dbits);
1696
+ var BI_FP = 52;
1697
+ BigInteger.prototype.FV = Math.pow(2, BI_FP);
1698
+ BigInteger.prototype.F1 = BI_FP - dbits;
1699
+ BigInteger.prototype.F2 = 2 * dbits - BI_FP;
1700
+ // Digit conversions
1701
+ var BI_RC = [];
1702
+ var rr;
1703
+ var vv;
1704
+ rr = "0".charCodeAt(0);
1705
+ for (vv = 0; vv <= 9; ++vv) {
1706
+ BI_RC[rr++] = vv;
1707
+ }
1708
+ rr = "a".charCodeAt(0);
1709
+ for (vv = 10; vv < 36; ++vv) {
1710
+ BI_RC[rr++] = vv;
1711
+ }
1712
+ rr = "A".charCodeAt(0);
1713
+ for (vv = 10; vv < 36; ++vv) {
1714
+ BI_RC[rr++] = vv;
1715
+ }
1716
+ export function intAt(s, i) {
1717
+ var c = BI_RC[s.charCodeAt(i)];
1718
+ return (c == null) ? -1 : c;
1719
+ }
1720
+ // return bigint initialized to value
1721
+ export function nbv(i) {
1722
+ var r = nbi();
1723
+ r.fromInt(i);
1724
+ return r;
1725
+ }
1726
+ // returns bit length of the integer x
1727
+ export function nbits(x) {
1728
+ var r = 1;
1729
+ var t;
1730
+ if ((t = x >>> 16) != 0) {
1731
+ x = t;
1732
+ r += 16;
1733
+ }
1734
+ if ((t = x >> 8) != 0) {
1735
+ x = t;
1736
+ r += 8;
1737
+ }
1738
+ if ((t = x >> 4) != 0) {
1739
+ x = t;
1740
+ r += 4;
1741
+ }
1742
+ if ((t = x >> 2) != 0) {
1743
+ x = t;
1744
+ r += 2;
1745
+ }
1746
+ if ((t = x >> 1) != 0) {
1747
+ x = t;
1748
+ r += 1;
1749
+ }
1750
+ return r;
1751
+ }
1752
+ // "constants"
1753
+ BigInteger.ZERO = nbv(0);
1754
+ BigInteger.ONE = nbv(1);