-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaeser.java
More file actions
29 lines (26 loc) · 855 Bytes
/
Copy pathcaeser.java
File metadata and controls
29 lines (26 loc) · 855 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
import java.util.Scanner;
public class ayy {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
System.out.println("How big do you want the Caesar shift cipher to be?");
double CIPHER= scan.nextInt();
System.out.print("Now type whatever you want to encrypted and let the computer do the magic."
+ "\n" + "Make sure it's lowercaps only:");
scan.nextLine();
String sentence= scan.nextLine();
char sentenceChar[]= sentence.toCharArray();
for(int i=0;i<sentence.length();i++){
sentenceChar[i] += CIPHER;
if (sentenceChar[i]>=97+ CIPHER && sentenceChar[i]<= 122+ CIPHER){
if (sentenceChar[i]> 122){
sentenceChar[i]=(char)(sentenceChar[i]-26);
}
System.out.print((char)sentenceChar[i]);
}
else{
System.out.print((char)(sentenceChar[i]-CIPHER));
}
}
scan.close();
}
}