1
2
3
4
5
6
7 package civitas.util;
8
9 import java.math.BigInteger;
10
11 import io.github.magwas.konveyor.annotations.Glue;
12
13 @Glue
14 public class CivitasBigInteger extends CivitasBigintegerBase {
15
16 CivitasBigInteger(final BigInteger integer) {
17 super(integer);
18 }
19
20 public CivitasBigInteger add(final CivitasBigInteger x) {
21 if (x == ZERO) {
22 return this;
23 }
24 return new CivitasBigInteger(i.add(x.i));
25 }
26
27 public CivitasBigInteger mod(final CivitasBigInteger q) {
28 BigInteger m = this.i.mod(q.i);
29 if (this.i.equals(m)) {
30 return this;
31 }
32 return new CivitasBigInteger(m);
33 }
34
35 public CivitasBigInteger modAdd(final CivitasBigInteger x, final CivitasBigInteger p) {
36 if (x == ZERO) {
37 return this.mod(p);
38 }
39 return new CivitasBigInteger(i.add(x.i).mod(p.i));
40 }
41
42 public CivitasBigInteger modPow(final CivitasBigInteger x, final CivitasBigInteger p) {
43 return new CivitasBigInteger(this.i.modPow(x.i, p.i));
44 }
45
46 public CivitasBigInteger multiply(final CivitasBigInteger x) {
47 if (x == ONE) {
48 return this;
49 }
50 if (x == ZERO) {
51 return ZERO;
52 }
53 return new CivitasBigInteger(this.i.multiply(x.i));
54 }
55
56 public CivitasBigInteger modMultiply(final CivitasBigInteger x, final CivitasBigInteger p) {
57 if (x == ZERO) {
58 return ZERO;
59 }
60 if (x == ONE) {
61 return this.mod(p);
62 }
63 return new CivitasBigInteger(this.i.multiply(x.i).mod(p.i));
64 }
65
66 public CivitasBigInteger modDivide(final CivitasBigInteger x, final CivitasBigInteger p) {
67 if (x == ONE) {
68 return this.mod(p);
69 }
70 return new CivitasBigInteger(this.i.multiply(x.i.modInverse(p.i)).mod(p.i));
71 }
72
73 public CivitasBigInteger subtract(final CivitasBigInteger x) {
74 if (x == ZERO) {
75 return this;
76 }
77 return new CivitasBigInteger(this.i.subtract(x.i));
78 }
79
80 public CivitasBigInteger modSubtract(final CivitasBigInteger x, final CivitasBigInteger p) {
81 if (x == ZERO) {
82 return this.mod(p);
83 }
84 return new CivitasBigInteger(this.i.subtract(x.i).mod(p.i));
85 }
86 }