- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCipher.java
More file actions
Latest commit
45 lines (39 loc) · 1.18 KB
/
Copy pathCipher.java
File metadata and controls
45 lines (39 loc) · 1.18 KB
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
37
38
39
40
41
42
43
44
45
publicclassCipher {
publicstaticvoidmain(String[] args) {
Stringstr = "";
Stringenc = encrypt(str);
System.out.println(str + " " + enc + " " + decrypt(enc));
}
publicstaticStringencrypt(Stringtext) {
Stringresult = "";
for (inti = 0; i < text.length(); i++) {
charc = text.charAt(i);
if (c >= 'a' && c <= 'z') {
if (c == 'z') c = 'a';
elsec = (char) (c + 1);
}
elseif (c >= 'A' && c <= 'Z') {
if (c == 'Z') c = 'A';
elsec = (char) (c + 1);
}
result += c;
}
returnresult;
}
publicstaticStringdecrypt(Stringtext) {
Stringresult = "";
for (inti = 0; i < text.length(); i++) {
charc = text.charAt(i);
if (c >= 'a' && c <= 'z') {
if (c == 'a') c = 'z';
elsec = (char) (c - 1);
}
elseif (c >= 'A' && c <= 'Z') {
if (c == 'A') c = 'Z';
elsec = (char) (c - 1);
}
result += c;
}
returnresult;
}
}