Skip to content

Commit 77b2d1e

Browse files
committed
Fix code formatting
1 parent 6d30942 commit 77b2d1e

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

src/main/java/com/thealgorithms/ciphers/RailFenceCipher.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212

13-
public class RailFenceCipher {
13+
public class RailFenceCipher {
1414

1515
// Encrypts the input string using the rail fence cipher method with the given number of rails.
1616
public String encrypt(String str, int rails) {
@@ -26,7 +26,7 @@ public String encrypt(String str, int rails) {
2626
char[][] strRail = new char[rails][str.length()];
2727

2828
// Initialize all positions in the rail matrix with a placeholder character ('\n').
29-
for (int i = 0; i < rails; i++){
29+
for (int i = 0; i < rails; i++) {
3030
Arrays.fill(strRail[i], '\n');
3131
}
3232

@@ -49,7 +49,6 @@ else if (row == rails - 1) {
4949
// Place the character in the current position of the rail matrix.
5050
strRail[row][col] = str.charAt(i);
5151
col++; // Move to the next column.
52-
5352
// Move to the next row based on the direction.
5453
if (down) {
5554
row++;
@@ -79,7 +78,6 @@ public String decrypt(String str, int rails) {
7978
if (rails == 1 || rails >= str.length()) {
8079
return str;
8180
}
82-
8381
// Boolean flag to determine if the movement is downward or upward in the rail matrix.
8482
boolean down = true;
8583

@@ -91,12 +89,10 @@ public String decrypt(String str, int rails) {
9189

9290
// Mark the pattern on the rail matrix using '*'.
9391
while (col < str.length()) {
94-
9592
// Change direction to down when at the first row.
9693
if (row == 0) {
9794
down = true;
9895
}
99-
10096
// Change direction to up when at the last row.
10197
else if (row == rails - 1) {
10298
down = false;
@@ -105,12 +101,10 @@ else if (row == rails - 1) {
105101
// Mark the current position in the rail matrix.
106102
strRail[row][col] = '*';
107103
col++; // Move to the next column.
108-
109104
// Move to the next row based on the direction.
110105
if (down) {
111106
row++;
112-
}
113-
else {
107+
} else {
114108
row--;
115109
}
116110
}
@@ -142,12 +136,10 @@ else if (row == rails - 1) {
142136
// Append the character from the rail matrix to the decrypted string.
143137
decryptedString.append(strRail[row][col]);
144138
col++; // Move to the next column.
145-
146139
// Move to the next row based on the direction.
147140
if (down) {
148141
row++;
149-
}
150-
else {
142+
} else {
151143
row--;
152144
}
153145
}

0 commit comments

Comments
 (0)