| | 425 | def BKZ_FP(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 426 | r""" |
|---|
| | 427 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 428 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 429 | describe here only the differences in the calling syntax. |
|---|
| | 430 | |
|---|
| | 431 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 432 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 433 | but the running time increases exponentially with BlockSize. |
|---|
| | 434 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 435 | |
|---|
| | 436 | * The optional parameter "prune" can be set to any positive |
|---|
| | 437 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 438 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 439 | running time, and hence allow much bigger block size, but the |
|---|
| | 440 | quality of the reduction is of course not as good in general. |
|---|
| | 441 | Higher values of prune mean better quality, and slower running |
|---|
| | 442 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 443 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 444 | |
|---|
| | 445 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 446 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 447 | of the block reduction algorithm. This seems adequate for |
|---|
| | 448 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 449 | precision uniformly throughout. |
|---|
| | 450 | |
|---|
| | 451 | INPUT: |
|---|
| | 452 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 453 | delta -- reduction parameter (default: 0.99) |
|---|
| | 454 | BlockSize -- see above (default: 10) |
|---|
| | 455 | prune -- see above (default: 0) |
|---|
| | 456 | verbose -- print verbose output (default: False) |
|---|
| | 457 | |
|---|
| | 458 | EXAMPLE: |
|---|
| | 459 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 460 | sage: a = A._ntl_() |
|---|
| | 461 | sage: a.BKZ_FP(); a |
|---|
| | 462 | 2 |
|---|
| | 463 | [ |
|---|
| | 464 | [0 0 0 0 0] |
|---|
| | 465 | [0 0 0 0 0] |
|---|
| | 466 | [0 0 0 0 0] |
|---|
| | 467 | [0 1 2 3 4] |
|---|
| | 468 | [5 3 1 -1 -3] |
|---|
| | 469 | ] |
|---|
| | 470 | |
|---|
| | 471 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 472 | sage: r = a.BKZ_FP(U=U); U |
|---|
| | 473 | [ |
|---|
| | 474 | [0 1 0 0 0] |
|---|
| | 475 | [1 0 0 0 0] |
|---|
| | 476 | [0 0 1 0 0] |
|---|
| | 477 | [0 0 0 1 0] |
|---|
| | 478 | [0 0 0 0 1] |
|---|
| | 479 | ] |
|---|
| | 480 | """ |
|---|
| | 481 | if U is None: |
|---|
| | 482 | _sig_on |
|---|
| | 483 | rank = mat_ZZ_BKZ_FP(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 484 | _sig_off |
|---|
| | 485 | return rank |
|---|
| | 486 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 487 | _sig_on |
|---|
| | 488 | rank = mat_ZZ_BKZ_FP_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 489 | _sig_off |
|---|
| | 490 | return rank |
|---|
| | 491 | else: |
|---|
| | 492 | raise TypeError, "parameter U has wrong type." |
|---|
| | 493 | |
|---|
| | 494 | def BKZ_QP(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 495 | r""" |
|---|
| | 496 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 497 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 498 | describe here only the differences in the calling syntax. |
|---|
| | 499 | |
|---|
| | 500 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 501 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 502 | but the running time increases exponentially with BlockSize. |
|---|
| | 503 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 504 | |
|---|
| | 505 | * The optional parameter "prune" can be set to any positive |
|---|
| | 506 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 507 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 508 | running time, and hence allow much bigger block size, but the |
|---|
| | 509 | quality of the reduction is of course not as good in general. |
|---|
| | 510 | Higher values of prune mean better quality, and slower running |
|---|
| | 511 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 512 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 513 | |
|---|
| | 514 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 515 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 516 | of the block reduction algorithm. This seems adequate for |
|---|
| | 517 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 518 | precision uniformly throughout. |
|---|
| | 519 | |
|---|
| | 520 | INPUT: |
|---|
| | 521 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 522 | delta -- reduction parameter (default: 0.99) |
|---|
| | 523 | BlockSize -- see above (default: 10) |
|---|
| | 524 | prune -- see above (default: 0) |
|---|
| | 525 | verbose -- print verbose output (default: False) |
|---|
| | 526 | |
|---|
| | 527 | EXAMPLE: |
|---|
| | 528 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 529 | sage: a = A._ntl_() |
|---|
| | 530 | sage: a.BKZ_QP(); a |
|---|
| | 531 | 2 |
|---|
| | 532 | [ |
|---|
| | 533 | [0 0 0 0 0] |
|---|
| | 534 | [0 0 0 0 0] |
|---|
| | 535 | [0 0 0 0 0] |
|---|
| | 536 | [0 1 2 3 4] |
|---|
| | 537 | [5 3 1 -1 -3] |
|---|
| | 538 | ] |
|---|
| | 539 | |
|---|
| | 540 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 541 | sage: r = a.BKZ_QP(U=U); U |
|---|
| | 542 | [ |
|---|
| | 543 | [0 1 0 0 0] |
|---|
| | 544 | [1 0 0 0 0] |
|---|
| | 545 | [0 0 1 0 0] |
|---|
| | 546 | [0 0 0 1 0] |
|---|
| | 547 | [0 0 0 0 1] |
|---|
| | 548 | ] |
|---|
| | 549 | """ |
|---|
| | 550 | if U is None: |
|---|
| | 551 | _sig_on |
|---|
| | 552 | rank = mat_ZZ_BKZ_QP(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 553 | _sig_off |
|---|
| | 554 | return rank |
|---|
| | 555 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 556 | _sig_on |
|---|
| | 557 | rank = mat_ZZ_BKZ_QP_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 558 | _sig_off |
|---|
| | 559 | return rank |
|---|
| | 560 | else: |
|---|
| | 561 | raise TypeError, "parameter U has wrong type." |
|---|
| | 562 | |
|---|
| | 563 | def BKZ_QP1(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 564 | r""" |
|---|
| | 565 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 566 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 567 | describe here only the differences in the calling syntax. |
|---|
| | 568 | |
|---|
| | 569 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 570 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 571 | but the running time increases exponentially with BlockSize. |
|---|
| | 572 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 573 | |
|---|
| | 574 | * The optional parameter "prune" can be set to any positive |
|---|
| | 575 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 576 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 577 | running time, and hence allow much bigger block size, but the |
|---|
| | 578 | quality of the reduction is of course not as good in general. |
|---|
| | 579 | Higher values of prune mean better quality, and slower running |
|---|
| | 580 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 581 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 582 | |
|---|
| | 583 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 584 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 585 | of the block reduction algorithm. This seems adequate for |
|---|
| | 586 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 587 | precision uniformly throughout. |
|---|
| | 588 | |
|---|
| | 589 | INPUT: |
|---|
| | 590 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 591 | delta -- reduction parameter (default: 0.99) |
|---|
| | 592 | BlockSize -- see above (default: 10) |
|---|
| | 593 | prune -- see above (default: 0) |
|---|
| | 594 | verbose -- print verbose output (default: False) |
|---|
| | 595 | |
|---|
| | 596 | EXAMPLE: |
|---|
| | 597 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 598 | sage: a = A._ntl_() |
|---|
| | 599 | sage: a.BKZ_QP1(); a |
|---|
| | 600 | 2 |
|---|
| | 601 | [ |
|---|
| | 602 | [0 0 0 0 0] |
|---|
| | 603 | [0 0 0 0 0] |
|---|
| | 604 | [0 0 0 0 0] |
|---|
| | 605 | [0 1 2 3 4] |
|---|
| | 606 | [5 3 1 -1 -3] |
|---|
| | 607 | ] |
|---|
| | 608 | |
|---|
| | 609 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 610 | sage: r = a.BKZ_QP1(U=U); U |
|---|
| | 611 | [ |
|---|
| | 612 | [0 1 0 0 0] |
|---|
| | 613 | [1 0 0 0 0] |
|---|
| | 614 | [0 0 1 0 0] |
|---|
| | 615 | [0 0 0 1 0] |
|---|
| | 616 | [0 0 0 0 1] |
|---|
| | 617 | ] |
|---|
| | 618 | """ |
|---|
| | 619 | if U is None: |
|---|
| | 620 | _sig_on |
|---|
| | 621 | rank = mat_ZZ_BKZ_QP1(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 622 | _sig_off |
|---|
| | 623 | return rank |
|---|
| | 624 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 625 | _sig_on |
|---|
| | 626 | rank = mat_ZZ_BKZ_QP1_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 627 | _sig_off |
|---|
| | 628 | return rank |
|---|
| | 629 | else: |
|---|
| | 630 | raise TypeError, "parameter U has wrong type." |
|---|
| | 631 | |
|---|
| | 632 | def BKZ_XD(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 633 | r""" |
|---|
| | 634 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 635 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 636 | describe here only the differences in the calling syntax. |
|---|
| | 637 | |
|---|
| | 638 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 639 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 640 | but the running time increases exponentially with BlockSize. |
|---|
| | 641 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 642 | |
|---|
| | 643 | * The optional parameter "prune" can be set to any positive |
|---|
| | 644 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 645 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 646 | running time, and hence allow much bigger block size, but the |
|---|
| | 647 | quality of the reduction is of course not as good in general. |
|---|
| | 648 | Higher values of prune mean better quality, and slower running |
|---|
| | 649 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 650 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 651 | |
|---|
| | 652 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 653 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 654 | of the block reduction algorithm. This seems adequate for |
|---|
| | 655 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 656 | precision uniformly throughout. |
|---|
| | 657 | |
|---|
| | 658 | INPUT: |
|---|
| | 659 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 660 | delta -- reduction parameter (default: 0.99) |
|---|
| | 661 | BlockSize -- see above (default: 10) |
|---|
| | 662 | prune -- see above (default: 0) |
|---|
| | 663 | verbose -- print verbose output (default: False) |
|---|
| | 664 | |
|---|
| | 665 | EXAMPLE: |
|---|
| | 666 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 667 | sage: a = A._ntl_() |
|---|
| | 668 | sage: a.BKZ_XD(); a |
|---|
| | 669 | 2 |
|---|
| | 670 | [ |
|---|
| | 671 | [0 0 0 0 0] |
|---|
| | 672 | [0 0 0 0 0] |
|---|
| | 673 | [0 0 0 0 0] |
|---|
| | 674 | [0 1 2 3 4] |
|---|
| | 675 | [5 3 1 -1 -3] |
|---|
| | 676 | ] |
|---|
| | 677 | |
|---|
| | 678 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 679 | sage: r = a.BKZ_XD(U=U); U |
|---|
| | 680 | [ |
|---|
| | 681 | [0 1 0 0 0] |
|---|
| | 682 | [1 0 0 0 0] |
|---|
| | 683 | [0 0 1 0 0] |
|---|
| | 684 | [0 0 0 1 0] |
|---|
| | 685 | [0 0 0 0 1] |
|---|
| | 686 | ] |
|---|
| | 687 | """ |
|---|
| | 688 | if U is None: |
|---|
| | 689 | _sig_on |
|---|
| | 690 | rank = mat_ZZ_BKZ_XD(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 691 | _sig_off |
|---|
| | 692 | return rank |
|---|
| | 693 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 694 | _sig_on |
|---|
| | 695 | rank = mat_ZZ_BKZ_XD_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 696 | _sig_off |
|---|
| | 697 | return rank |
|---|
| | 698 | else: |
|---|
| | 699 | raise TypeError, "parameter U has wrong type." |
|---|
| | 700 | |
|---|
| | 701 | def BKZ_RR(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 702 | r""" |
|---|
| | 703 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 704 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 705 | describe here only the differences in the calling syntax. |
|---|
| | 706 | |
|---|
| | 707 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 708 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 709 | but the running time increases exponentially with BlockSize. |
|---|
| | 710 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 711 | |
|---|
| | 712 | * The optional parameter "prune" can be set to any positive |
|---|
| | 713 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 714 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 715 | running time, and hence allow much bigger block size, but the |
|---|
| | 716 | quality of the reduction is of course not as good in general. |
|---|
| | 717 | Higher values of prune mean better quality, and slower running |
|---|
| | 718 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 719 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 720 | |
|---|
| | 721 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 722 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 723 | of the block reduction algorithm. This seems adequate for |
|---|
| | 724 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 725 | precision uniformly throughout. |
|---|
| | 726 | |
|---|
| | 727 | INPUT: |
|---|
| | 728 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 729 | delta -- reduction parameter (default: 0.99) |
|---|
| | 730 | BlockSize -- see above (default: 10) |
|---|
| | 731 | prune -- see above (default: 0) |
|---|
| | 732 | verbose -- print verbose output (default: False) |
|---|
| | 733 | |
|---|
| | 734 | EXAMPLE: |
|---|
| | 735 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 736 | sage: a = A._ntl_() |
|---|
| | 737 | sage: a.BKZ_RR(); a |
|---|
| | 738 | 2 |
|---|
| | 739 | [ |
|---|
| | 740 | [0 0 0 0 0] |
|---|
| | 741 | [0 0 0 0 0] |
|---|
| | 742 | [0 0 0 0 0] |
|---|
| | 743 | [0 1 2 3 4] |
|---|
| | 744 | [5 3 1 -1 -3] |
|---|
| | 745 | ] |
|---|
| | 746 | |
|---|
| | 747 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 748 | sage: r = a.BKZ_RR(U=U); U |
|---|
| | 749 | [ |
|---|
| | 750 | [0 1 0 0 0] |
|---|
| | 751 | [1 0 0 0 0] |
|---|
| | 752 | [0 0 1 0 0] |
|---|
| | 753 | [0 0 0 1 0] |
|---|
| | 754 | [0 0 0 0 1] |
|---|
| | 755 | ] |
|---|
| | 756 | """ |
|---|
| | 757 | if U is None: |
|---|
| | 758 | _sig_on |
|---|
| | 759 | rank = mat_ZZ_BKZ_RR(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 760 | _sig_off |
|---|
| | 761 | return rank |
|---|
| | 762 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 763 | _sig_on |
|---|
| | 764 | rank = mat_ZZ_BKZ_RR_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 765 | _sig_off |
|---|
| | 766 | return rank |
|---|
| | 767 | else: |
|---|
| | 768 | raise TypeError, "parameter U has wrong type." |
|---|
| | 769 | |
|---|
| | 770 | def G_BKZ_FP(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 771 | r""" |
|---|
| | 772 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 773 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 774 | describe here only the differences in the calling syntax. |
|---|
| | 775 | |
|---|
| | 776 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 777 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 778 | but the running time increases exponentially with BlockSize. |
|---|
| | 779 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 780 | |
|---|
| | 781 | * The optional parameter "prune" can be set to any positive |
|---|
| | 782 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 783 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 784 | running time, and hence allow much bigger block size, but the |
|---|
| | 785 | quality of the reduction is of course not as good in general. |
|---|
| | 786 | Higher values of prune mean better quality, and slower running |
|---|
| | 787 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 788 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 789 | |
|---|
| | 790 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 791 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 792 | of the block reduction algorithm. This seems adequate for |
|---|
| | 793 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 794 | precision uniformly throughout. |
|---|
| | 795 | |
|---|
| | 796 | INPUT: |
|---|
| | 797 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 798 | delta -- reduction parameter (default: 0.99) |
|---|
| | 799 | BlockSize -- see above (default: 10) |
|---|
| | 800 | prune -- see above (default: 0) |
|---|
| | 801 | verbose -- print verbose output (default: False) |
|---|
| | 802 | |
|---|
| | 803 | EXAMPLE: |
|---|
| | 804 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 805 | sage: a = A._ntl_() |
|---|
| | 806 | sage: a.G_BKZ_FP(); a |
|---|
| | 807 | 2 |
|---|
| | 808 | [ |
|---|
| | 809 | [0 0 0 0 0] |
|---|
| | 810 | [0 0 0 0 0] |
|---|
| | 811 | [0 0 0 0 0] |
|---|
| | 812 | [0 1 2 3 4] |
|---|
| | 813 | [5 3 1 -1 -3] |
|---|
| | 814 | ] |
|---|
| | 815 | |
|---|
| | 816 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 817 | sage: r = a.G_BKZ_FP(U=U); U |
|---|
| | 818 | [ |
|---|
| | 819 | [0 1 0 0 0] |
|---|
| | 820 | [1 0 0 0 0] |
|---|
| | 821 | [0 0 1 0 0] |
|---|
| | 822 | [0 0 0 1 0] |
|---|
| | 823 | [0 0 0 0 1] |
|---|
| | 824 | ] |
|---|
| | 825 | """ |
|---|
| | 826 | if U is None: |
|---|
| | 827 | _sig_on |
|---|
| | 828 | rank = mat_ZZ_G_BKZ_FP(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 829 | _sig_off |
|---|
| | 830 | return rank |
|---|
| | 831 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 832 | _sig_on |
|---|
| | 833 | rank = mat_ZZ_G_BKZ_FP_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 834 | _sig_off |
|---|
| | 835 | return rank |
|---|
| | 836 | else: |
|---|
| | 837 | raise TypeError, "parameter U has wrong type." |
|---|
| | 838 | |
|---|
| | 839 | def G_BKZ_QP(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 840 | r""" |
|---|
| | 841 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 842 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 843 | describe here only the differences in the calling syntax. |
|---|
| | 844 | |
|---|
| | 845 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 846 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 847 | but the running time increases exponentially with BlockSize. |
|---|
| | 848 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 849 | |
|---|
| | 850 | * The optional parameter "prune" can be set to any positive |
|---|
| | 851 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 852 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 853 | running time, and hence allow much bigger block size, but the |
|---|
| | 854 | quality of the reduction is of course not as good in general. |
|---|
| | 855 | Higher values of prune mean better quality, and slower running |
|---|
| | 856 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 857 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 858 | |
|---|
| | 859 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 860 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 861 | of the block reduction algorithm. This seems adequate for |
|---|
| | 862 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 863 | precision uniformly throughout. |
|---|
| | 864 | |
|---|
| | 865 | INPUT: |
|---|
| | 866 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 867 | delta -- reduction parameter (default: 0.99) |
|---|
| | 868 | BlockSize -- see above (default: 10) |
|---|
| | 869 | prune -- see above (default: 0) |
|---|
| | 870 | verbose -- print verbose output (default: False) |
|---|
| | 871 | |
|---|
| | 872 | EXAMPLE: |
|---|
| | 873 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 874 | sage: a = A._ntl_() |
|---|
| | 875 | sage: a.G_BKZ_QP(); a |
|---|
| | 876 | 2 |
|---|
| | 877 | [ |
|---|
| | 878 | [0 0 0 0 0] |
|---|
| | 879 | [0 0 0 0 0] |
|---|
| | 880 | [0 0 0 0 0] |
|---|
| | 881 | [0 1 2 3 4] |
|---|
| | 882 | [5 3 1 -1 -3] |
|---|
| | 883 | ] |
|---|
| | 884 | |
|---|
| | 885 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 886 | sage: r = a.G_BKZ_QP(U=U); U |
|---|
| | 887 | [ |
|---|
| | 888 | [0 1 0 0 0] |
|---|
| | 889 | [1 0 0 0 0] |
|---|
| | 890 | [0 0 1 0 0] |
|---|
| | 891 | [0 0 0 1 0] |
|---|
| | 892 | [0 0 0 0 1] |
|---|
| | 893 | ] |
|---|
| | 894 | """ |
|---|
| | 895 | if U is None: |
|---|
| | 896 | _sig_on |
|---|
| | 897 | rank = mat_ZZ_G_BKZ_QP(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 898 | _sig_off |
|---|
| | 899 | return rank |
|---|
| | 900 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 901 | _sig_on |
|---|
| | 902 | rank = mat_ZZ_G_BKZ_QP_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 903 | _sig_off |
|---|
| | 904 | return rank |
|---|
| | 905 | else: |
|---|
| | 906 | raise TypeError, "parameter U has wrong type." |
|---|
| | 907 | |
|---|
| | 908 | def G_BKZ_QP1(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 909 | r""" |
|---|
| | 910 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 911 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 912 | describe here only the differences in the calling syntax. |
|---|
| | 913 | |
|---|
| | 914 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 915 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 916 | but the running time increases exponentially with BlockSize. |
|---|
| | 917 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 918 | |
|---|
| | 919 | * The optional parameter "prune" can be set to any positive |
|---|
| | 920 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 921 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 922 | running time, and hence allow much bigger block size, but the |
|---|
| | 923 | quality of the reduction is of course not as good in general. |
|---|
| | 924 | Higher values of prune mean better quality, and slower running |
|---|
| | 925 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 926 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 927 | |
|---|
| | 928 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 929 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 930 | of the block reduction algorithm. This seems adequate for |
|---|
| | 931 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 932 | precision uniformly throughout. |
|---|
| | 933 | |
|---|
| | 934 | INPUT: |
|---|
| | 935 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 936 | delta -- reduction parameter (default: 0.99) |
|---|
| | 937 | BlockSize -- see above (default: 10) |
|---|
| | 938 | prune -- see above (default: 0) |
|---|
| | 939 | verbose -- print verbose output (default: False) |
|---|
| | 940 | |
|---|
| | 941 | EXAMPLE: |
|---|
| | 942 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 943 | sage: a = A._ntl_() |
|---|
| | 944 | sage: a.G_BKZ_QP1(); a |
|---|
| | 945 | 2 |
|---|
| | 946 | [ |
|---|
| | 947 | [0 0 0 0 0] |
|---|
| | 948 | [0 0 0 0 0] |
|---|
| | 949 | [0 0 0 0 0] |
|---|
| | 950 | [0 1 2 3 4] |
|---|
| | 951 | [5 3 1 -1 -3] |
|---|
| | 952 | ] |
|---|
| | 953 | |
|---|
| | 954 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 955 | sage: r = a.G_BKZ_QP1(U=U); U |
|---|
| | 956 | [ |
|---|
| | 957 | [0 1 0 0 0] |
|---|
| | 958 | [1 0 0 0 0] |
|---|
| | 959 | [0 0 1 0 0] |
|---|
| | 960 | [0 0 0 1 0] |
|---|
| | 961 | [0 0 0 0 1] |
|---|
| | 962 | ] |
|---|
| | 963 | """ |
|---|
| | 964 | if U is None: |
|---|
| | 965 | _sig_on |
|---|
| | 966 | rank = mat_ZZ_G_BKZ_QP1(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 967 | _sig_off |
|---|
| | 968 | return rank |
|---|
| | 969 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 970 | _sig_on |
|---|
| | 971 | rank = mat_ZZ_G_BKZ_QP1_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 972 | _sig_off |
|---|
| | 973 | return rank |
|---|
| | 974 | else: |
|---|
| | 975 | raise TypeError, "parameter U has wrong type." |
|---|
| | 976 | |
|---|
| | 977 | def G_BKZ_XD(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 978 | r""" |
|---|
| | 979 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 980 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 981 | describe here only the differences in the calling syntax. |
|---|
| | 982 | |
|---|
| | 983 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 984 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 985 | but the running time increases exponentially with BlockSize. |
|---|
| | 986 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 987 | |
|---|
| | 988 | * The optional parameter "prune" can be set to any positive |
|---|
| | 989 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 990 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 991 | running time, and hence allow much bigger block size, but the |
|---|
| | 992 | quality of the reduction is of course not as good in general. |
|---|
| | 993 | Higher values of prune mean better quality, and slower running |
|---|
| | 994 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 995 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 996 | |
|---|
| | 997 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 998 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 999 | of the block reduction algorithm. This seems adequate for |
|---|
| | 1000 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 1001 | precision uniformly throughout. |
|---|
| | 1002 | |
|---|
| | 1003 | INPUT: |
|---|
| | 1004 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 1005 | delta -- reduction parameter (default: 0.99) |
|---|
| | 1006 | BlockSize -- see above (default: 10) |
|---|
| | 1007 | prune -- see above (default: 0) |
|---|
| | 1008 | verbose -- print verbose output (default: False) |
|---|
| | 1009 | |
|---|
| | 1010 | EXAMPLE: |
|---|
| | 1011 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 1012 | sage: a = A._ntl_() |
|---|
| | 1013 | sage: a.G_BKZ_XD(); a |
|---|
| | 1014 | 2 |
|---|
| | 1015 | [ |
|---|
| | 1016 | [0 0 0 0 0] |
|---|
| | 1017 | [0 0 0 0 0] |
|---|
| | 1018 | [0 0 0 0 0] |
|---|
| | 1019 | [0 1 2 3 4] |
|---|
| | 1020 | [5 3 1 -1 -3] |
|---|
| | 1021 | ] |
|---|
| | 1022 | |
|---|
| | 1023 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 1024 | sage: r = a.G_BKZ_XD(U=U); U |
|---|
| | 1025 | [ |
|---|
| | 1026 | [0 1 0 0 0] |
|---|
| | 1027 | [1 0 0 0 0] |
|---|
| | 1028 | [0 0 1 0 0] |
|---|
| | 1029 | [0 0 0 1 0] |
|---|
| | 1030 | [0 0 0 0 1] |
|---|
| | 1031 | ] |
|---|
| | 1032 | """ |
|---|
| | 1033 | if U is None: |
|---|
| | 1034 | _sig_on |
|---|
| | 1035 | rank = mat_ZZ_G_BKZ_XD(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 1036 | _sig_off |
|---|
| | 1037 | return rank |
|---|
| | 1038 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 1039 | _sig_on |
|---|
| | 1040 | rank = mat_ZZ_G_BKZ_XD_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 1041 | _sig_off |
|---|
| | 1042 | return rank |
|---|
| | 1043 | else: |
|---|
| | 1044 | raise TypeError, "parameter U has wrong type." |
|---|
| | 1045 | |
|---|
| | 1046 | def G_BKZ_RR(self, U=None, delta=0.99, BlockSize=10, prune=0, verbose=False): |
|---|
| | 1047 | r""" |
|---|
| | 1048 | All BKZ methods are equivalent to the LLL routines, |
|---|
| | 1049 | except that Block Korkin-Zolotarev reduction is applied. We |
|---|
| | 1050 | describe here only the differences in the calling syntax. |
|---|
| | 1051 | |
|---|
| | 1052 | * The optional parameter "BlockSize" specifies the size of the |
|---|
| | 1053 | blocks in the reduction. High values yield shorter vectors, |
|---|
| | 1054 | but the running time increases exponentially with BlockSize. |
|---|
| | 1055 | BlockSize should be between 2 and the number of rows of B. |
|---|
| | 1056 | |
|---|
| | 1057 | * The optional parameter "prune" can be set to any positive |
|---|
| | 1058 | number to invoke the Volume Heuristic from [Schnorr and |
|---|
| | 1059 | Horner, Eurocrypt '95]. This can significantly reduce the |
|---|
| | 1060 | running time, and hence allow much bigger block size, but the |
|---|
| | 1061 | quality of the reduction is of course not as good in general. |
|---|
| | 1062 | Higher values of prune mean better quality, and slower running |
|---|
| | 1063 | time. When prune == 0, pruning is disabled. Recommended |
|---|
| | 1064 | usage: for BlockSize >= 30, set 10 <= prune <= 15. |
|---|
| | 1065 | |
|---|
| | 1066 | * The QP1 variant uses quad_float precision to compute |
|---|
| | 1067 | Gram-Schmidt, but uses double precision in the search phase |
|---|
| | 1068 | of the block reduction algorithm. This seems adequate for |
|---|
| | 1069 | most purposes, and is faster than QP, which uses quad_float |
|---|
| | 1070 | precision uniformly throughout. |
|---|
| | 1071 | |
|---|
| | 1072 | INPUT: |
|---|
| | 1073 | U -- optional permutation matrix (see LLL, default: None) |
|---|
| | 1074 | delta -- reduction parameter (default: 0.99) |
|---|
| | 1075 | BlockSize -- see above (default: 10) |
|---|
| | 1076 | prune -- see above (default: 0) |
|---|
| | 1077 | verbose -- print verbose output (default: False) |
|---|
| | 1078 | |
|---|
| | 1079 | EXAMPLE: |
|---|
| | 1080 | sage: A = Matrix(ZZ,5,5,range(25)) |
|---|
| | 1081 | sage: a = A._ntl_() |
|---|
| | 1082 | sage: a.G_BKZ_RR(); a |
|---|
| | 1083 | 2 |
|---|
| | 1084 | [ |
|---|
| | 1085 | [0 0 0 0 0] |
|---|
| | 1086 | [0 0 0 0 0] |
|---|
| | 1087 | [0 0 0 0 0] |
|---|
| | 1088 | [0 1 2 3 4] |
|---|
| | 1089 | [5 3 1 -1 -3] |
|---|
| | 1090 | ] |
|---|
| | 1091 | |
|---|
| | 1092 | sage: U = ntl.mat_ZZ(2,2) # note that the dimension doesn't matter |
|---|
| | 1093 | sage: r = a.G_BKZ_RR(U=U); U |
|---|
| | 1094 | [ |
|---|
| | 1095 | [0 1 0 0 0] |
|---|
| | 1096 | [1 0 0 0 0] |
|---|
| | 1097 | [0 0 1 0 0] |
|---|
| | 1098 | [0 0 0 1 0] |
|---|
| | 1099 | [0 0 0 0 1] |
|---|
| | 1100 | ] |
|---|
| | 1101 | """ |
|---|
| | 1102 | if U is None: |
|---|
| | 1103 | _sig_on |
|---|
| | 1104 | rank = mat_ZZ_G_BKZ_RR(self.x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 1105 | _sig_off |
|---|
| | 1106 | return rank |
|---|
| | 1107 | elif PY_TYPE_CHECK(U, ntl_mat_ZZ): |
|---|
| | 1108 | _sig_on |
|---|
| | 1109 | rank = mat_ZZ_G_BKZ_RR_U(self.x, (<ntl_mat_ZZ>U).x, float(delta), int(BlockSize), int(prune), 0, int(verbose)); |
|---|
| | 1110 | _sig_off |
|---|
| | 1111 | return rank |
|---|
| | 1112 | else: |
|---|
| | 1113 | raise TypeError, "parameter U has wrong type." |
|---|
| | 1114 | |
|---|