Skip to content

Commit d5f6dd4

Browse files
committed
rank calculation refactor
1 parent 32535f6 commit d5f6dd4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/main/java/CaesarShift.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public String encrypt(String msg){
1313
//loop through the character array
1414
for(Character character : upCasedArrs ){
1515
int index = ALPHABET.indexOf(character.toString());//get the character rank in the alphabet
16-
int encryptedCharIndex = (index+key)%26;//shift the character using the key and get the new characters rank in the alphabet
16+
int encryptedCharIndex = Math.floorMod((index+key),26);//shift the character using the key and get the new characters rank in the alphabet
1717
encryptedChars.add(ALPHABET.charAt(encryptedCharIndex));//get the character from the alphabet rank and add it to the char array
1818
encryptedMsg = encryptedChars.toString().replaceAll("\\[|\\]|\\s","").replaceAll(",","");//convert and cleanup the char array to a string
1919
}

0 commit comments

Comments
 (0)