本文整理汇总了PHP中Point::cmp方法的典型用法代码示例。如果您正苦于以下问题:PHP Point::cmp方法的具体用法?PHP Point::cmp怎么用?PHP Point::cmp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Point
的用法示例。
在下文中一共展示了Point::cmp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(Point $generator, Point $point)
{
$this->curve = $generator->getCurve();
$this->generator = $generator;
$this->point = $point;
$n = $generator->getOrder();
if ($n == null) {
throw new ErrorExcpetion("Generator Must have order.");
}
if (Point::cmp(Point::mul($n, $point), Point::$infinity) != 0) {
throw new ErrorException("Generator Point order is bad.");
}
if (extension_loaded('gmp') && USE_EXT == 'GMP') {
if (gmp_cmp($point->getX(), 0) < 0 || gmp_cmp($n, $point->getX()) <= 0 || gmp_cmp($point->getY(), 0) < 0 || gmp_cmp($n, $point->getY()) <= 0) {
throw new ErrorException("Generator Point has x and y out of range.");
}
} else {
if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
if (bccomp($point->getX(), 0) == -1 || bccomp($n, $point->getX()) != 1 || bccomp($point->getY(), 0) == -1 || bccomp($n, $point->getY()) != 1) {
throw new ErrorException("Generator Point has x and y out of range.");
}
} else {
throw new ErrorException("Please install BCMATH or GMP");
}
}
}
示例2: point_is_valid
public static function point_is_valid(Point $generator, $x, $y)
{
if (extension_loaded('gmp') && USE_EXT == 'GMP') {
$n = $generator->getOrder();
$curve = $generator->getCurve();
if (gmp_cmp($x, 0) < 0 || gmp_cmp($n, $x) <= 0 || gmp_cmp($y, 0) < 0 || gmp_cmp($n, $y) <= 0) {
return false;
}
$containment = $curve->contains($x, $y);
if (!$containment) {
return false;
}
$point = new Point($curve, $x, $y);
$op = Point::mul($n, $point);
if (!(Point::cmp($op, Point::$infinity) == 0)) {
return false;
}
return true;
} else {
if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
$n = $generator->getOrder();
$curve = $generator->getCurve();
if (bccomp($x, 0) == -1 || bccomp($n, $x) != 1 || bccomp($y, 0) == -1 || bccomp($n, $y) != 1) {
return false;
}
$containment = $curve->contains($x, $y);
if (!$containment) {
return false;
}
$point = new Point($curve, $x, $y);
$op = Point::mul($n, $point);
if (!(Point::cmp($op, Point::$infinity) == 0)) {
return false;
}
return true;
} else {
throw new ErrorException("Please install BCMATH or GMP");
}
}
}