mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 12:11:28 +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) {
|
public static String encode(String message, int shift) {
|
||||||
String encoded = "";
|
String encoded = "";
|
||||||
|
|
||||||
while (shift >= 26) { // 26 = number of latin letters
|
if (shift >= 26) { // 26 = number of latin letters
|
||||||
shift -= 26;
|
shift %= 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int length = message.length();
|
final int length = message.length();
|
||||||
@ -62,8 +62,8 @@ public class Caesar {
|
|||||||
public static String decode(String encryptedMessage, int shift) {
|
public static String decode(String encryptedMessage, int shift) {
|
||||||
String decoded = "";
|
String decoded = "";
|
||||||
|
|
||||||
while (shift >= 26) { // 26 = number of latin letters
|
if (shift >= 26) { // 26 = number of latin letters
|
||||||
shift -= 26;
|
shift %= 26;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int length = encryptedMessage.length();
|
final int length = encryptedMessage.length();
|
||||||
|
Reference in New Issue
Block a user