Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8605b9

Browse files
authored
Efficiency
Just two small things that in case the number was very big could be helpful.
1 parent ffd4521 commit f8605b9

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ciphers/Caesar.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class Caesar {
2424
public static String encode(String message, int shift) {
2525
String encoded = "";
2626

27-
while (shift >= 26) { // 26 = number of latin letters
28-
shift -= 26;
27+
if (shift >= 26) { // 26 = number of latin letters
28+
shift %= 26;
2929
}
3030

3131
final int length = message.length();
@@ -62,8 +62,8 @@ public static String encode(String message, int shift) {
6262
public static String decode(String encryptedMessage, int shift) {
6363
String decoded = "";
6464

65-
while (shift >= 26) { // 26 = number of latin letters
66-
shift -= 26;
65+
if (shift >= 26) { // 26 = number of latin letters
66+
shift %= 26;
6767
}
6868

6969
final int length = encryptedMessage.length();

0 commit comments

Comments
 (0)