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