Created
December 18, 2021 17:01
-
-
Save aadipoddar/279da3a8d73e15a0b897ebd7d9b88768 to your computer and use it in GitHub Desktop.
Encrypt Sentence with Caesar Cipher method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*Enter a Sentence and Encrypt it with Caesar Cipher method (13 characters shift) | |
*Hello! How are you? | |
*Uryyb! Ubj ner lbh? | |
*/ | |
import java.util.Scanner; | |
class Caesar_Cipher_Encryption | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Enter the sentence"); | |
String sentence = sc.nextLine(); | |
for(int i = 0; i < sentence.length(); i++) | |
{ | |
char ch = sentence.charAt(i); | |
if(ch >= 'a' && ch <= 'z') | |
{ | |
ch = (char)(ch + 13); | |
if(ch > 'z') | |
{ | |
ch = (char)(ch - 26); | |
} | |
} | |
else if(ch >= 'A' && ch <= 'Z') | |
{ | |
ch = (char)(ch + 13); | |
if(ch > 'Z') | |
{ | |
ch = (char)(ch - 26); | |
} | |
} | |
System.out.print(ch); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment