Skip to content

Commit 8dcfd34

Browse files
author
jdvega
committed
remove explicit round indexes
1 parent 71532d9 commit 8dcfd34

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/main/java/com/idealista/fpe/algorithm/ff1/FF1Algorithm.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
class FF1Algorithm {
1616

17-
private static final int[] DECRYPT_ROUNDS = new int[]{9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
18-
private static final int[] ENCRYPT_ROUNDS = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
17+
private static final int NUMBER_OF_ROUNDS = 10;
1918

2019
private FF1Algorithm (){}
2120

@@ -29,7 +28,7 @@ static int[] encrypt(int[] plainText, Integer radix, byte[] tweak, PseudoRandomF
2928

3029
int[] left = target.left();
3130
int[] right = target.right();
32-
for (int round : ENCRYPT_ROUNDS) {
31+
for (int round=0; round<NUMBER_OF_ROUNDS; round++) {
3332
BigInteger roundNumeral = roundNumeral(num(right, radix), tweak, padding, pseudoRandomFunction, lengthOfLeftAfterEncoded, paddingToEnsureFeistelOutputIsBigger, round);
3433
int partialLength = round % 2 == 0 ? leftSideLength : rightSideLength;
3534
BigInteger partialNumeral = num(left, radix).add(roundNumeral).mod(BigInteger.valueOf(radix).pow(partialLength));
@@ -50,7 +49,7 @@ static int[] decrypt(int[] cipherText, Integer radix, byte[] tweak, PseudoRandom
5049

5150
int[] left = target.left();
5251
int[] right = target.right();
53-
for (int round : DECRYPT_ROUNDS) {
52+
for (int round=NUMBER_OF_ROUNDS-1; round>=0; round--) {
5453
BigInteger roundNumeral = roundNumeral(num(left, radix), tweak, padding, pseudoRandomFunction, lengthOfLeftAfterEncoded, paddingToEnsureFeistelOutputIsBigger, round);
5554
int partialLength = round % 2 == 0 ? leftSideLength : rightSideLength;
5655
BigInteger partialNumeral = num(right, radix).subtract(roundNumeral).mod(BigInteger.valueOf(radix).pow(partialLength));

0 commit comments

Comments
 (0)