We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Caesar Cipher
- Discussions
Caesar Cipher
Caesar Cipher
Sort by
recency
|
1276 Discussions
|
Please Login in order to post a comment
Question about case six, from the way I understand the problem when K > 28 than K is K%28 because 28 does not shift the letter thus say in case 6 the shit should be to 3 and not to 9 and yet somehow with K of 87 the positive test should somehow shift the letters by 9? What am I not getting?
Kotlin solution fun caesarCipher(s: String, k: Int): String { // Write your code here val ACode = 'A'.code val ZCode = 'Z'.code val aCode = 'a'.code val zCode = 'z'.code val shift = k.mod(ZCode-ACode+1) val newS = mutableListOf() val charA = s.toCharArray() for (i in 0..charA.size-1){ var symCode = charA[i].code if( symCode>= ACode && symCode <= ZCode){ symCode += shift if( symCode > ZCode) symCode = ACode - (ZCode - symCode + 1) } if( symCode>= aCode && symCode <= zCode){ symCode += shift if( symCode > zCode) symCode = aCode - (zCode - symCode + 1) } newS.add( symCode.toChar()) } return String(newS.toCharArray()) }
Here is my c++ solution, you can watch the explanation here : https://youtu.be/KApgpiqqX20
Here is my Python solution!