|
@@ -1,3 +1,7 @@
|
|
1
|
+import java.io.File;
|
|
2
|
+import java.io.FileNotFoundException;
|
|
3
|
+import java.util.Scanner;
|
|
4
|
+
|
1
|
5
|
import static java.lang.Character.isLowerCase;
|
2
|
6
|
import static java.lang.Character.isUpperCase;
|
3
|
7
|
import static java.lang.Character.toLowerCase;
|
|
@@ -13,7 +17,7 @@ public class ROT13 {
|
13
|
17
|
}
|
14
|
18
|
|
15
|
19
|
|
16
|
|
- public String crypt(String text) throws UnsupportedOperationException {
|
|
20
|
+ public static String crypt(String text) throws UnsupportedOperationException {
|
17
|
21
|
StringBuilder sb = new StringBuilder();
|
18
|
22
|
char [] chars = text.toCharArray();
|
19
|
23
|
for (int i = 0; i <chars.length ; i++) {
|
|
@@ -32,7 +36,7 @@ public class ROT13 {
|
32
|
36
|
return sb.toString();
|
33
|
37
|
}
|
34
|
38
|
|
35
|
|
- public String encrypt(String text) {
|
|
39
|
+ public static String encrypt(String text) {
|
36
|
40
|
return crypt(text);
|
37
|
41
|
}
|
38
|
42
|
|
|
@@ -41,8 +45,28 @@ public class ROT13 {
|
41
|
45
|
}
|
42
|
46
|
|
43
|
47
|
public static String rotate(String s, Character c) {
|
|
48
|
+ //this method will rotate the given String
|
|
49
|
+ //by the character placement
|
|
50
|
+ String sub = s.substring(0,s.indexOf(c));
|
|
51
|
+ String sub1 = s.substring(s.indexOf(c));
|
|
52
|
+ //then concat the two substrings.
|
|
53
|
+ return sub1.concat(sub);
|
|
54
|
+ }
|
|
55
|
+ public static String textFile(String filename){
|
|
56
|
+ StringBuilder sb = new StringBuilder();
|
44
|
57
|
|
45
|
|
- return "";
|
|
58
|
+ File file = new File(filename);
|
|
59
|
+ try(Scanner sc = new Scanner(file)) {
|
|
60
|
+ while(sc.hasNextLine()){
|
|
61
|
+ String line = sc.nextLine();
|
|
62
|
+ String xored = encrypt(line);
|
|
63
|
+ sb.append(xored+"\n");
|
|
64
|
+ }
|
|
65
|
+ sb.deleteCharAt(sb.length()-1);
|
|
66
|
+ } catch (FileNotFoundException e){
|
|
67
|
+ e.printStackTrace();
|
|
68
|
+ }
|
|
69
|
+ return sb.toString();
|
46
|
70
|
}
|
47
|
71
|
|
48
|
72
|
}
|