|
@@ -1,6 +1,12 @@
|
|
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;
|
|
6
|
+
|
|
7
|
+import java.io.FileNotFoundException;
|
|
8
|
+import java.util.Scanner;
|
|
9
|
+import java.io.File;
|
4
|
10
|
import java.lang.StringBuilder;
|
5
|
11
|
import java.lang.String;
|
6
|
12
|
import java.lang.StringBuffer;
|
|
@@ -19,42 +25,26 @@ public class ROT13 {
|
19
|
25
|
|
20
|
26
|
public String crypt(String text) throws UnsupportedOperationException {
|
21
|
27
|
StringBuilder builder = new StringBuilder();
|
22
|
|
-
|
23
|
|
- for(int i = 0; i<text.length(); i++){
|
24
|
|
- char c = text.charAt(i);
|
|
28
|
+ char[] charText = text.toCharArray();
|
|
29
|
+ for(char i: charText){
|
|
30
|
+ char c = i;
|
25
|
31
|
if(c>='a' && c<='m' || c>='A' && c<='M') c+=13;
|
26
|
32
|
else if(c>='n' && c<='z' || c>='N' && c<='Z') c-=13;
|
27
|
33
|
builder.append(c);
|
28
|
34
|
}
|
29
|
|
- text = builder.toString();
|
30
|
35
|
|
31
|
|
- return text;
|
|
36
|
+
|
|
37
|
+ return builder.toString();
|
32
|
38
|
}
|
33
|
39
|
|
34
|
40
|
public String encrypt(String text) {
|
35
|
|
- for(int i = 0; i<text.length(); i++){
|
36
|
|
- char ch = text.charAt(i);
|
37
|
|
- if(ch>= 'A' && ch<='Z'){
|
38
|
|
- ch = (char)(ch+13);
|
39
|
|
- if (ch > 'Z') {
|
40
|
|
- ch = (char)(ch-26);
|
41
|
|
- }
|
42
|
|
- }
|
43
|
|
- else if(ch>= 'a' && ch<='z'){
|
44
|
|
- ch = (char)(ch+13);
|
45
|
|
- if(ch>'z'){
|
46
|
|
- ch = (char)(ch-26);
|
47
|
|
- }
|
48
|
|
- }
|
49
|
|
- cryptText = cryptText+ch;
|
50
|
|
- }
|
51
|
|
- text = cryptText;
|
52
|
|
- return text;
|
|
41
|
+
|
|
42
|
+ return crypt(text);
|
53
|
43
|
}
|
54
|
44
|
|
55
|
45
|
public String decrypt(String text) {
|
56
|
|
- encrypt(text);
|
57
|
|
- return text;
|
|
46
|
+
|
|
47
|
+ return crypt(text);
|
58
|
48
|
}
|
59
|
49
|
|
60
|
50
|
public static String rotate(String s, Character c) {
|
|
@@ -65,4 +55,18 @@ public class ROT13 {
|
65
|
55
|
|
66
|
56
|
}
|
67
|
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
|
+ }
|
68
|
72
|
}
|