forked from shweta-laha/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaesar_Cipher.java
More file actions
31 lines (30 loc) · 804 Bytes
/
Copy pathCaesar_Cipher.java
File metadata and controls
31 lines (30 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.*;
class Caesar_Cipher
{
public static void main()
{
Scanner sc=new Scanner(System.in);
String str,str1="";
int i,l,a;
char ch;
System.out.println("Enter a sentence");
str=sc.nextLine();
l=str.length();
if(l>3&&l<100)
{
for(i=0;i<l;i++)
{
ch=str.charAt(i);
a=(int)ch;
if((a>=97&&a<=109)||(a>=65&&a<=77))
a+=13;
else if((a>=110&&a<=122)||(a>=78&&a<=90))
a-=13;
str1=str1+(char)a;
}
System.out.println("the cipher text:\n"+str1);
}
else
System.out.println("Invalid Length");
}
}