|
@@ -1,32 +1,78 @@
|
1
|
|
-import static java.lang.Character.isLowerCase;
|
2
|
|
-import static java.lang.Character.isUpperCase;
|
3
|
|
-import static java.lang.Character.toLowerCase;
|
|
1
|
+import java.io.File;
|
|
2
|
+import java.io.FileNotFoundException;
|
|
3
|
+import java.io.FileWriter;
|
|
4
|
+import java.io.IOException;
|
|
5
|
+import java.util.Collections;
|
|
6
|
+import java.util.Scanner;
|
4
|
7
|
|
5
|
8
|
public class ROT13 {
|
6
|
9
|
|
|
10
|
+ private int shift;
|
|
11
|
+
|
7
|
12
|
ROT13(Character cs, Character cf) {
|
|
13
|
+ this.shift = cs-cf;
|
8
|
14
|
}
|
9
|
15
|
|
10
|
16
|
ROT13() {
|
|
17
|
+ shift = 13;
|
11
|
18
|
}
|
12
|
19
|
|
13
|
20
|
|
14
|
21
|
public String crypt(String text) throws UnsupportedOperationException {
|
15
|
22
|
|
16
|
|
- return "";
|
|
23
|
+ StringBuilder build = new StringBuilder();
|
|
24
|
+ char[] arr = text.toCharArray();
|
|
25
|
+ for (char a: arr) {
|
|
26
|
+ char c = a;
|
|
27
|
+ if((c >= 'a' && c<= 'm') || (c >= 'A' && c<= 'M')){
|
|
28
|
+ c += 13;
|
|
29
|
+ }
|
|
30
|
+ else if((c >= 'n' && c <= 'z') || (c>= 'N' && c <= 'Z')){
|
|
31
|
+ c-= 13;
|
|
32
|
+ }
|
|
33
|
+ build.append(c);
|
|
34
|
+ }
|
|
35
|
+ return build.toString();
|
17
|
36
|
}
|
18
|
37
|
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
19
|
41
|
public String encrypt(String text) {
|
20
|
|
- return text;
|
|
42
|
+ return crypt(text);
|
21
|
43
|
}
|
22
|
44
|
|
23
|
45
|
public String decrypt(String text) {
|
24
|
|
- return text;
|
|
46
|
+ return crypt(text);
|
25
|
47
|
}
|
26
|
48
|
|
27
|
49
|
public static String rotate(String s, Character c) {
|
|
50
|
+ String rotate = s.substring(s.indexOf(c));
|
|
51
|
+ String rotateNext = s.substring(0,s.indexOf(c));
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+ return rotate.concat(rotateNext);
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ public String encrptFile(String filename) throws FileNotFoundException{
|
|
58
|
+ StringBuilder build = new StringBuilder();
|
|
59
|
+
|
|
60
|
+ File f = new File(filename);
|
|
61
|
+ try(Scanner scan = new Scanner(f)){
|
|
62
|
+ while(scan.hasNextLine()){
|
|
63
|
+
|
|
64
|
+ String line = scan.nextLine();
|
|
65
|
+ String rot13 = this.encrypt(line);
|
|
66
|
+ build.append(rot13+ "\n");
|
|
67
|
+ }
|
|
68
|
+ }
|
|
69
|
+ catch (FileNotFoundException e){
|
|
70
|
+ e.printStackTrace();
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+
|
28
|
74
|
|
29
|
|
- return "";
|
|
75
|
+ return build.toString();
|
30
|
76
|
}
|
31
|
77
|
|
32
|
78
|
}
|