Skip to content

Commit

Permalink
Merge pull request #6 from barryvdh/patch-1
Browse files Browse the repository at this point in the history
Generate random prime
  • Loading branch information
jenssegers committed Jul 12, 2015
2 parents 1885bc6 + 8929ef3 commit d18f103
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Commands/SparkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

use Jenssegers\Optimus\Optimus;
use phpseclib\Crypt\Random;
use phpseclib\Math\BigInteger;
Expand All @@ -18,7 +17,7 @@ protected function configure()
->setDescription('Generate constructor values for your prime')
->addArgument(
'prime',
InputArgument::REQUIRED,
InputArgument::OPTIONAL,
'Your prime number'
);
}
Expand All @@ -27,6 +26,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$prime = $input->getArgument('prime');

if ( ! $prime) {
$min = new BigInteger(1e7);
$max = new BigInteger(Optimus::MAX_INT);
$prime = $max->randomPrime($min, $max);
}

// Calculate the inverse.
$a = new BigInteger($prime);
$b = new BigInteger(Optimus::MAX_INT + 1);
Expand Down

0 comments on commit d18f103

Please sign in to comment.