- Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCaesarCipher.java
36 lines (30 loc) · 1004 Bytes
/
CaesarCipher.java
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
32
33
34
35
36
importjava.util.*;
importjava.io.*;
classMain {
publicstaticStringCaesarCipher(Stringstr, intnum) {
// code goes here
intcode, newCode;
Stringresult = "", newChar;
for (inti = 0; i < str.length(); i++) {
code = (int) str.charAt(i);
newCode = code + num;
if (code >= 65 && code <= 90) {
if (newCode > 90) newCode = 64 + (newCode - 90);
}
elseif (code >= 97 && code <= 122) {
if (newCode > 122) newCode = 96 + (newCode - 122);
}
else {
newCode = code;
}
newChar = String.valueOf((char) newCode);
result += newChar;
}
returnresult;
}
publicstaticvoidmain (String[] args) {
// keep this function call here
Scanners = newScanner(System.in);
System.out.print(CaesarCipher(s.nextLine()));
}
}