Crypto: Caesar Cipher explained | Java implementation

preview_player
Показать описание
This video explains the Caesar Cipher (cryptosystem) and walks through the process of implementing it in Java.

One of the simplest examples of a substitution cipher is the Caesar cipher, which is said to have been used by Julius Caesar to communicate with his army. Caesar is considered to be one of the first persons to have ever employed encryption for the sake of securing messages. Caesar decided that shifting each letter in the message would be his standard algorithm, and so he informed all of his generals of his decision, and was then able to send them secured messages.
Рекомендации по теме
Комментарии
Автор

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 {
if {
int charIndex =
int newIndex = (charIndex + shift) % 26;
char encryptedChar =
encryptedText += encryptedChar;
} else {
int charIndex =
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.

ernestobcoa
Автор

how do you keep the case of the letter and codify it as the same time?

bayareamountainbiker
Автор

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.

peternjenga
Автор

thank you very much !!! you helped me a lot thanks

xtremefn
Автор

my decoding doesn't work. It returns a single character multiple times.

pavansandhu
Автор

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?

aarushi
Автор

what would have happened if you input something with a space or a special characters
thank you

dogaaykol
visit shbcf.ru