-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleEncryption.java
More file actions
51 lines (29 loc) · 819 Bytes
/
SimpleEncryption.java
File metadata and controls
51 lines (29 loc) · 819 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package basics;
/* following is a simple encryption class of input string or int and it will be rotated */
import java.io.*;
public class rotate13 {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for(;;) {
System.out.print("> ");
String line = in.readLine();
if(( line == null) || line.equals("quit"))
break;
StringBuffer buf = new StringBuffer(line);
for(int i = 0; i < buf.length(); i++)
buf.setCharAt(i, rot13(buf.charAt(i)));
System.out.println(buf);
}
}
public static char rot13(char c) {
if((c >= 'A') && (c <= 'Z')) {
c += 13;
if (c > 'Z') c -= 26;
}
if ((c >= 'a') && (c <= 'z')) {
c += 13;
if (c > 'z') c-= 26;
}
return c;
}
}