Hello everyone, Thanks a lot for this lesson!! I updated the encryption part a little, because we have to consider the cases regarding uppercase letters and special characters. So, without to convert the plainText string in lowercase, this is the new encryption part (tested with success in HackerRank): public static String caesarCipher(String plainText, int shift) { String alphabet = "abcdefghijklmnopqrstuvwxyz"; String encryptedText = ""; for (int i = 0; i < plainText.length(); i++) { if (Character.isLetter(plainText.charAt(i))) { if (Character.isUpperCase(plainText.charAt(i))) { int charIndex = alphabet.indexOf(Character.toLowerCase(plainText.charAt(i))); int newIndex = (charIndex + shift) % 26; char encryptedChar = Character.toUpperCase(alphabet.charAt(newIndex)); encryptedText += encryptedChar; } else { int charIndex = alphabet.indexOf(plainText.charAt(i)); int newIndex = (charIndex + shift) % 26; char encryptedChar = alphabet.charAt(newIndex); encryptedText += encryptedChar; } } else { encryptedText += plainText.charAt(i); } } return encryptedText; } Hoping to be useful for everyone.
@periphx3 жыл бұрын
thank you very much !!! you helped me a lot thanks
@bayareamountainbiker Жыл бұрын
how do you keep the case of the letter and codify it as the same time?
@jeanwill692 жыл бұрын
Thank you very much.
@peternjenga72342 жыл бұрын
Hi I am using intelij IDEA to run the code and it is showing no values for the cipher text and decoded message. What can be the problem.
@dogaaykol92973 жыл бұрын
what would have happened if you input something with a space or a special characters thank you
@thecsrevelation3 жыл бұрын
Hi in this example. Spaces and special characters are not being handled. In this case, you will get an incorrect output. The code to handle other characters could be added.
@peterkomagum96383 жыл бұрын
Amazing
@thecsrevelation3 жыл бұрын
package caesarcrypto; import java.util.Scanner; public class CaesarCrypto { static String alphabet = "abcdefghijklmnopqrstuvwxyz"; public static String encoding(String pText, int Key){ pText = pText.toLowerCase(); String cText =""; for(int i = 0; i
@pavansandhu87632 жыл бұрын
my decoding doesn't work. It returns a single character multiple times.
@aarushi7403 жыл бұрын
Hi, i tried to run the same code on bluej and each time I enter a string and a key, it gives a string out of bounds exception, why is that happening?
@thecsrevelation3 жыл бұрын
package caesarcrypto; import java.util.Scanner; public class CaesarCrypto { static String alphabet = "abcdefghijklmnopqrstuvwxyz"; public static String encoding(String pText, int Key){ pText = pText.toLowerCase(); String cText =""; for(int i = 0; i
@sara-12MS3 жыл бұрын
When I write the email it disappears
@thecsrevelation3 жыл бұрын
package caesarcrypto; import java.util.Scanner; public class CaesarCrypto { static String alphabet = "abcdefghijklmnopqrstuvwxyz"; public static String encoding(String pText, int Key){ pText = pText.toLowerCase(); String cText =""; for(int i = 0; i
@sara-12MS3 жыл бұрын
@@thecsrevelation thanks
@sara-12MS3 жыл бұрын
Please the code Send my
@thecsrevelation3 жыл бұрын
Email?
@afrdthzna38512 жыл бұрын
@@thecsrevelation can yu please explain other ciphers too
@thecsrevelation2 жыл бұрын
@@afrdthzna3851 i have two more explained in this video kzbin.info/www/bejne/eneuk3WknLxrmdk
@allankibichiilimo16063 жыл бұрын
**********
@thecsrevelation3 жыл бұрын
package caesarcrypto; import java.util.Scanner; public class CaesarCrypto { static String alphabet = "abcdefghijklmnopqrstuvwxyz"; public static String encoding(String pText, int Key){ pText = pText.toLowerCase(); String cText =""; for(int i = 0; i