| 440 | } |
| 441 | |
| 442 | QCircuit constModAdd(QVec &qvec, int base, int module_Num, QVec &qvec1, QVec &qvec2) |
| 443 | { |
| 444 | base = base % module_Num; |
| 445 | QCircuit circuit, tmpcir, tmpcir1; |
| 446 | int tmpvalue = (1 << qvec.size()) + base - module_Num; |
| 447 | circuit << bind_nonnegative_data(tmpvalue, qvec1) |
| 448 | << isCarry(qvec, qvec1, qvec2[1], qvec2[0]) |
| 449 | << bind_nonnegative_data(tmpvalue, qvec1); |
| 450 | |
| 451 | tmpcir << bind_nonnegative_data(tmpvalue, qvec1) |
| 452 | << QAdder(qvec, qvec1, qvec2[1]) |
| 453 | << bind_nonnegative_data(tmpvalue, qvec1); |
| 454 | circuit << tmpcir.control(qvec2[0]) << X(qvec2[0]); |
| 455 | |
| 456 | tmpcir1 << bind_nonnegative_data(base, qvec1) |
| 457 | << QAdder(qvec, qvec1, qvec2[1]) |
| 458 | << bind_nonnegative_data(base, qvec1); |
| 459 | circuit << tmpcir1.control(qvec2[0]) << X(qvec2[0]); |
| 460 | |
| 461 | tmpvalue = (1 << qvec.size()) - base; |
| 462 | circuit << bind_nonnegative_data(tmpvalue, qvec1) |
| 463 | << isCarry(qvec, qvec1, qvec2[1], qvec2[0]) |
| 464 | << bind_nonnegative_data(tmpvalue, qvec1) |
| 465 | << X(qvec2[0]); |
| 466 | |
| 467 | return circuit; |
| 468 | } |
| 469 | |
| 470 | // Euclidean Algorithm to get the inverse element |
| 471 | int modReverse(int a, int b) |
no test coverage detected