[Pkg-javascript-commits] [node-miller-rabin] 21/37: bin: introduce cli script
Bastien Roucariès
rouca at moszumanska.debian.org
Thu May 4 10:20:42 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-miller-rabin.
commit d6182d992afef4b393e6643f4c296cd58024e878
Author: Fedor Indutny <fedor at indutny.com>
Date: Mon Apr 27 11:22:55 2015 +0200
bin: introduce cli script
---
bin/miller-rabin | 27 +++++++++++++++++++++++++++
lib/mr.js | 3 +--
package.json | 3 ++-
3 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/bin/miller-rabin b/bin/miller-rabin
new file mode 100755
index 0000000..ca10cc4
--- /dev/null
+++ b/bin/miller-rabin
@@ -0,0 +1,27 @@
+#!/usr/bin/env node
+var bn = require('bn.js');
+var fs = require('fs');
+var mr = require('../').create();
+
+var num = '';
+if (process.argv[2]) {
+ num += fs.readFileSync(process.argv[2]);
+ start(num);
+} else {
+ process.stdin.on('data', function(chunk) {
+ num += chunk.toString().replace(/[^0-9a-f]/gi, '');
+ });
+ process.stdin.once('end', function() {
+ start(num);
+ });
+}
+
+function start(text) {
+ var num = new bn(text, 16);
+
+ var divisor = mr.getDivisor(num);
+ if (!divisor)
+ process.exit(1);
+
+ console.log(divisor.toString(16));
+}
diff --git a/lib/mr.js b/lib/mr.js
index 0d237d2..a9e935b 100644
--- a/lib/mr.js
+++ b/lib/mr.js
@@ -83,7 +83,6 @@ MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
var rn1 = n1.toRed(red);
- var prime = true;
for (; k > 0; k--) {
var a = this._rand(n2);
@@ -110,5 +109,5 @@ MillerRabin.prototype.getDivisor = function getDivisor(n, k) {
}
}
- return prime;
+ return false;
};
diff --git a/package.json b/package.json
index c8a8ccc..838d864 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "1.1.5",
"description": "Miller Rabin algorithm for primality test",
"main": "lib/mr.js",
+ "bin": "bin/miller-rabin",
"scripts": {
"test": "mocha --reporter=spec test/**/*-test.js"
},
@@ -25,7 +26,7 @@
"mocha": "^2.0.1"
},
"dependencies": {
- "bn.js": "^1.0.0",
+ "bn.js": "^2.0.0",
"brorand": "^1.0.1"
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-miller-rabin.git
More information about the Pkg-javascript-commits
mailing list