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