You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

miller-rabin 599B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/env node
  2. var bn = require('bn.js');
  3. var fs = require('fs');
  4. var mr = require('../').create();
  5. var num = '';
  6. if (process.argv[2]) {
  7. num += fs.readFileSync(process.argv[2]);
  8. start(num);
  9. } else {
  10. process.stdin.on('data', function(chunk) {
  11. num += chunk.toString().replace(/[^0-9a-f]/gi, '');
  12. });
  13. process.stdin.once('end', function() {
  14. start(num);
  15. });
  16. }
  17. function start(text) {
  18. var num = new bn(text, 16);
  19. var divisor = mr.getDivisor(num);
  20. if (!divisor)
  21. process.exit(1);
  22. if (divisor.cmpn(1) === 0)
  23. process.exit(0);
  24. console.log(divisor.toString(16));
  25. }