|
@@ -15,16 +15,14 @@ public class ROT13 {
|
15
|
15
|
private String alphbet = "abcdefghijklmnopqrstuvwxyz";
|
16
|
16
|
private char[] alphChars = alphbet.toCharArray();
|
17
|
17
|
|
18
|
|
-
|
19
|
|
-
|
20
|
18
|
ROT13(Character cs, Character cf) {
|
21
|
19
|
rotateBy = numbersByCount(cs, cf);
|
22
|
|
- rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz").toCharArray();
|
|
20
|
+ rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz", cf).toCharArray();
|
23
|
21
|
}
|
24
|
22
|
|
25
|
23
|
ROT13() {
|
26
|
24
|
rotateBy = 13;
|
27
|
|
- rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz").toCharArray();
|
|
25
|
+ rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz", 'n').toCharArray();
|
28
|
26
|
}
|
29
|
27
|
|
30
|
28
|
public static int numbersByCount(Character cs, Character cf){
|
|
@@ -48,8 +46,7 @@ public class ROT13 {
|
48
|
46
|
}
|
49
|
47
|
|
50
|
48
|
public static void main(String[] args){
|
51
|
|
- ROT13 rot13 = new ROT13('a', 'm');
|
52
|
|
- System.out.println(rot13.rotateBy);
|
|
49
|
+ ROT13 rot13 = new ROT13('a', 'b');
|
53
|
50
|
rot13.encryptFile("sonnet18.txt");
|
54
|
51
|
rot13.decryptFile("sonnet18.enc");
|
55
|
52
|
}
|
|
@@ -57,7 +54,6 @@ public class ROT13 {
|
57
|
54
|
public String crypt(String text) throws UnsupportedOperationException {
|
58
|
55
|
char[] cars = text.toCharArray();
|
59
|
56
|
StringBuilder sb = new StringBuilder();
|
60
|
|
-
|
61
|
57
|
for(char car: cars){
|
62
|
58
|
if(Character.isLetter(car)){
|
63
|
59
|
sb.append(this.rotate(this.alphbet, car).toCharArray()[rotateBy]);
|
|
@@ -65,9 +61,7 @@ public class ROT13 {
|
65
|
61
|
sb.append(car);
|
66
|
62
|
}
|
67
|
63
|
}
|
68
|
|
-
|
69
|
64
|
return sb.toString();
|
70
|
|
-
|
71
|
65
|
}
|
72
|
66
|
|
73
|
67
|
public String encrypt(String text) {
|
|
@@ -77,7 +71,6 @@ public class ROT13 {
|
77
|
71
|
public String decrypt(String text) {
|
78
|
72
|
char[] cars = text.toCharArray();
|
79
|
73
|
StringBuilder sb = new StringBuilder();
|
80
|
|
-
|
81
|
74
|
for(char car: cars){
|
82
|
75
|
if(Character.isLetter(car)){
|
83
|
76
|
sb.append(this.rotate(this.alphbet, car).toCharArray()[this.alphChars.length - rotateBy]);
|
|
@@ -85,25 +78,7 @@ public class ROT13 {
|
85
|
78
|
sb.append(car);
|
86
|
79
|
}
|
87
|
80
|
}
|
88
|
|
-
|
89
|
81
|
return sb.toString();
|
90
|
|
-
|
91
|
|
- }
|
92
|
|
-
|
93
|
|
- public String rotate(String s) {
|
94
|
|
- char[] cars = s.toCharArray();
|
95
|
|
-
|
96
|
|
- int looper = rotateBy;
|
97
|
|
- char temp;
|
98
|
|
- while(looper != 0){
|
99
|
|
- temp = cars[0];
|
100
|
|
- for(int i = 0; i < cars.length -1; i++){
|
101
|
|
- cars[i] = cars[i +1];
|
102
|
|
- }
|
103
|
|
- cars[cars.length -1] = temp;
|
104
|
|
- looper--;
|
105
|
|
- }
|
106
|
|
- return new String(cars);
|
107
|
82
|
}
|
108
|
83
|
|
109
|
84
|
public String rotate(String s, Character c) {
|