Skip to content
This repository was archived by the owner on Apr 6, 2025. It is now read-only.

Commit 00a03b9

Browse files
committed
fix: RailFenceCipher has some glitch with null character
1 parent fc15307 commit 00a03b9

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

EncryptionAlgorithms/src/algorithms/RailFenceCipher.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,9 @@ public String encrypt() {
144144
}
145145
debug("Khởi tạo chuỗi cùng độ sâu\n" + temp);
146146

147-
indexString = 0;
148147
for (int i = 0; i < row; i++) {
149148
for (int j = 0; j < col; j++) {
150-
if (indexString == originString.length())
151-
break;
152-
indexString++;
153-
str += tableEnc[j][i];
149+
str += ((int)tableEnc[j][i]) <= 0 ? "" : tableEnc[j][i];
154150
}
155151
}
156152

@@ -180,13 +176,9 @@ public String decrypt() {
180176
}
181177
debug("Khởi tạo chuỗi cùng độ sâu\n" + temp);
182178

183-
indexString = 0;
184179
for (int i = 0; i < col; i++) {
185180
for (int j = 0; j < row; j++) {
186-
if (indexString == originString.length())
187-
break;
188-
indexString++;
189-
str += tableEnc[i][j];
181+
str += ((int)tableEnc[i][j]) <= 0 ? "" : tableEnc[i][j];
190182
}
191183
}
192184

0 commit comments

Comments
 (0)