|
@@ -1,19 +1,17 @@
|
|
|
|
+const helper = require("../utils/Helpers").helpers;
|
|
|
|
+
|
|
class Factorizator {
|
|
class Factorizator {
|
|
- static getRandomInt(min, max) {
|
|
|
|
- min = Math.ceil(min);
|
|
|
|
- max = Math.floor(max);
|
|
|
|
- return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Finds the small multiplier by using Lopatin's method
|
|
* Finds the small multiplier by using Lopatin's method
|
|
* @param what
|
|
* @param what
|
|
|
|
+ * @return {number}
|
|
*/
|
|
*/
|
|
static findSmallMultiplierLopatin(what) {
|
|
static findSmallMultiplierLopatin(what) {
|
|
let g = 0;
|
|
let g = 0;
|
|
for (let i = 0; i < 3; i++) {
|
|
for (let i = 0; i < 3; i++) {
|
|
- let q = 30 || (this.getRandomInt(0, 127) & 15) + 17;
|
|
|
|
- let x = 40 || this.getRandomInt(0, 1000000000) + 1;
|
|
|
|
|
|
+ let q = 30 || (helper.getRandomInt(0, 127) & 15) + 17;
|
|
|
|
+ let x = 40 || helper.getRandomInt(0, 1000000000) + 1;
|
|
|
|
|
|
|
|
|
|
let y = x;
|
|
let y = x;
|
|
@@ -62,7 +60,7 @@ class Factorizator {
|
|
* Calculates the greatest common divisor
|
|
* Calculates the greatest common divisor
|
|
* @param a
|
|
* @param a
|
|
* @param b
|
|
* @param b
|
|
- * @returns {*}
|
|
|
|
|
|
+ * @returns {number}
|
|
*/
|
|
*/
|
|
static gcd(a, b) {
|
|
static gcd(a, b) {
|
|
while (((a !== 0) && (b !== 0))) {
|
|
while (((a !== 0) && (b !== 0))) {
|
|
@@ -84,7 +82,7 @@ class Factorizator {
|
|
/**
|
|
/**
|
|
* Factorizes the given number and returns both the divisor and the number divided by the divisor
|
|
* Factorizes the given number and returns both the divisor and the number divided by the divisor
|
|
* @param pq
|
|
* @param pq
|
|
- * @returns {{divisor: *, divided: *}}
|
|
|
|
|
|
+ * @returns {{divisor: number, divided: number}}
|
|
*/
|
|
*/
|
|
static factorize(pq) {
|
|
static factorize(pq) {
|
|
let divisor = this.findSmallMultiplierLopatin(pq);
|
|
let divisor = this.findSmallMultiplierLopatin(pq);
|