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