File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
main/java/com/thealgorithms/others
test/java/com/thealgorithms/others Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change 33import java .math .BigInteger ;
44import java .util .Random ;
55
6- // The algorithm is referred from
6+ // The algorithm is referred from
77// https://www.geeksforgeeks.org/shors-factorization-algorithm/
88public class ShorAlgorithm {
99 // trying to find the order of exponent given the base and the number
@@ -37,15 +37,21 @@ public BigInteger[] shorAlgorithm(BigInteger number) {
3737 }
3838
3939 int result = exponent (base , number );
40- if (result % 2 != 0 ) return null ;
40+ if (result % 2 != 0 ) {
41+ return null ;
42+ }
4143
4244 BigInteger congruentResult = base .modPow (BigInteger .valueOf (result / 2 ), number );
43- if (congruentResult .equals (number .subtract (BigInteger .ONE ))) return null ;
45+ if (congruentResult .equals (number .subtract (BigInteger .ONE ))) {
46+ return null ;
47+ }
4448
4549 BigInteger p = congruentResult .add (BigInteger .ONE ).gcd (number );
4650 BigInteger q = congruentResult .subtract (BigInteger .ONE ).gcd (number );
4751
48- if (!p .equals (BigInteger .ONE ) && !q .equals (BigInteger .ONE )) return new BigInteger [] {p , q };
52+ if (!p .equals (BigInteger .ONE ) && !q .equals (BigInteger .ONE )) {
53+ return new BigInteger [] {p , q };
54+ }
4955 return null ;
5056 }
5157}
Original file line number Diff line number Diff line change 22
33import java .math .BigInteger ;
44import org .junit .jupiter .api .Test ;
5- import static org .junit .jupiter .api .Assertions .*;
5+ import static org .junit .jupiter .api .Assertions .assertEquals ;
6+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
7+ import static org .junit .jupiter .api .Assertions .assertNull ;
68
79public class ShorAlgorithmTest {
810
You can’t perform that action at this time.
0 commit comments