Nicholas Maidanos преди 6 години
родител
ревизия
75a214e1b4
променени са 2 файла, в които са добавени 17 реда и са изтрити 42 реда
  1. 3
    28
      Crypto/src/main/java/ROT13.java
  2. 14
    14
      sonnet18.enc

+ 3
- 28
Crypto/src/main/java/ROT13.java Целия файл

15
     private String alphbet = "abcdefghijklmnopqrstuvwxyz";
15
     private String alphbet = "abcdefghijklmnopqrstuvwxyz";
16
     private char[] alphChars = alphbet.toCharArray();
16
     private char[] alphChars = alphbet.toCharArray();
17
 
17
 
18
-
19
-
20
     ROT13(Character cs, Character cf) {
18
     ROT13(Character cs, Character cf) {
21
         rotateBy = numbersByCount(cs, cf);
19
         rotateBy = numbersByCount(cs, cf);
22
-        rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz").toCharArray();
20
+        rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz", cf).toCharArray();
23
     }
21
     }
24
 
22
 
25
     ROT13() {
23
     ROT13() {
26
         rotateBy = 13;
24
         rotateBy = 13;
27
-        rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz").toCharArray();
25
+        rotatedAlphbet = rotate("abcdefghijklmnopqrstuvwxyz", 'n').toCharArray();
28
     }
26
     }
29
 
27
 
30
     public static int numbersByCount(Character cs, Character cf){
28
     public static int numbersByCount(Character cs, Character cf){
48
     }
46
     }
49
 
47
 
50
     public static void main(String[] args){
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
         rot13.encryptFile("sonnet18.txt");
50
         rot13.encryptFile("sonnet18.txt");
54
         rot13.decryptFile("sonnet18.enc");
51
         rot13.decryptFile("sonnet18.enc");
55
     }
52
     }
57
     public String crypt(String text) throws UnsupportedOperationException {
54
     public String crypt(String text) throws UnsupportedOperationException {
58
         char[] cars = text.toCharArray();
55
         char[] cars = text.toCharArray();
59
         StringBuilder sb =  new StringBuilder();
56
         StringBuilder sb =  new StringBuilder();
60
-
61
         for(char car: cars){
57
         for(char car: cars){
62
             if(Character.isLetter(car)){
58
             if(Character.isLetter(car)){
63
                 sb.append(this.rotate(this.alphbet, car).toCharArray()[rotateBy]);
59
                 sb.append(this.rotate(this.alphbet, car).toCharArray()[rotateBy]);
65
                 sb.append(car);
61
                 sb.append(car);
66
             }
62
             }
67
         }
63
         }
68
-
69
         return sb.toString();
64
         return sb.toString();
70
-
71
     }
65
     }
72
 
66
 
73
     public String encrypt(String text) {
67
     public String encrypt(String text) {
77
     public String decrypt(String text) {
71
     public String decrypt(String text) {
78
         char[] cars = text.toCharArray();
72
         char[] cars = text.toCharArray();
79
         StringBuilder sb =  new StringBuilder();
73
         StringBuilder sb =  new StringBuilder();
80
-
81
         for(char car: cars){
74
         for(char car: cars){
82
             if(Character.isLetter(car)){
75
             if(Character.isLetter(car)){
83
                 sb.append(this.rotate(this.alphbet, car).toCharArray()[this.alphChars.length - rotateBy]);
76
                 sb.append(this.rotate(this.alphbet, car).toCharArray()[this.alphChars.length - rotateBy]);
85
                 sb.append(car);
78
                 sb.append(car);
86
             }
79
             }
87
         }
80
         }
88
-
89
         return sb.toString();
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
     public String rotate(String s, Character c) {
84
     public String rotate(String s, Character c) {

+ 14
- 14
sonnet18.enc Целия файл

1
-Etmxx U oaybmdq ftqq fa m egyyqd’e pmk?
2
-Ftag mdf yadq xahqxk mzp yadq fqybqdmfq:
3
-Dagst iuzpe pa etmwq ftq pmdxuzs ngpe ar Ymk,
4
-Mzp egyyqd’e xqmeq tmft mxx faa etadf m pmfq;
5
-Eayqfuyq faa taf ftq qkq ar tqmhqz etuzqe,
6
-Mzp arfqz ue tue saxp oaybxqjuaz puyy'p;
7
-Mzp qhqdk rmud rday rmud eayqfuyq pqoxuzqe,
8
-Nk otmzoq ad zmfgdq’e otmzsuzs oagdeq gzfduyy'p;
9
-Ngf ftk qfqdzmx egyyqd etmxx zaf rmpq,
10
-Zad xaeq baeeqeeuaz ar ftmf rmud ftag ai’ef;
11
-Zad etmxx pqmft ndms ftag imzpqd’ef uz tue etmpq,
12
-Itqz uz qfqdzmx xuzqe fa fuyq ftag sdai’ef:
13
-   Ea xazs me yqz omz ndqmftq ad qkqe omz eqq,
14
-   Ea xazs xuhqe ftue, mzp ftue suhqe xurq fa ftqq.
1
+Tibmm J dpnqbsf uiff up b tvnnfs’t ebz?
2
+Uipv bsu npsf mpwfmz boe npsf ufnqfsbuf:
3
+Spvhi xjoet ep tiblf uif ebsmjoh cvet pg Nbz,
4
+Boe tvnnfs’t mfbtf ibui bmm upp tipsu b ebuf;
5
+Tpnfujnf upp ipu uif fzf pg ifbwfo tijoft,
6
+Boe pgufo jt ijt hpme dpnqmfyjpo ejnn'e;
7
+Boe fwfsz gbjs gspn gbjs tpnfujnf efdmjoft,
8
+Cz dibodf ps obuvsf’t dibohjoh dpvstf vousjnn'e;
9
+Cvu uiz fufsobm tvnnfs tibmm opu gbef,
10
+Ops mptf qpttfttjpo pg uibu gbjs uipv px’tu;
11
+Ops tibmm efbui csbh uipv xboefs’tu jo ijt tibef,
12
+Xifo jo fufsobm mjoft up ujnf uipv hspx’tu:
13
+   Tp mpoh bt nfo dbo csfbuif ps fzft dbo tff,
14
+   Tp mpoh mjwft uijt, boe uijt hjwft mjgf up uiff.