mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Efficiency
Just two small things that in case the number was very big could be helpful.
This commit is contained in:
@@ -24,8 +24,8 @@ public class Caesar {
|
||||
public static String encode(String message, int shift) {
|
||||
String encoded = "";
|
||||
|
||||
while (shift >= 26) { // 26 = number of latin letters
|
||||
shift -= 26;
|
||||
if (shift >= 26) { // 26 = number of latin letters
|
||||
shift %= 26;
|
||||
}
|
||||
|
||||
final int length = message.length();
|
||||
@@ -62,8 +62,8 @@ public class Caesar {
|
||||
public static String decode(String encryptedMessage, int shift) {
|
||||
String decoded = "";
|
||||
|
||||
while (shift >= 26) { // 26 = number of latin letters
|
||||
shift -= 26;
|
||||
if (shift >= 26) { // 26 = number of latin letters
|
||||
shift %= 26;
|
||||
}
|
||||
|
||||
final int length = encryptedMessage.length();
|
||||
|
||||
Reference in New Issue
Block a user