Aleena Rose-Mathew 6 lat temu
rodzic
commit
061b68b710

+ 35
- 0
Crypto/src/FileEncryptTest.java Wyświetl plik

@@ -0,0 +1,35 @@
1
+import org.testng.annotations.Test;
2
+
3
+import java.io.FileNotFoundException;
4
+
5
+import static org.testng.Assert.assertEquals;
6
+import static org.testng.Assert.assertTrue;
7
+
8
+public class FileEncryptTest {
9
+
10
+    @Test
11
+    public void testFileEncrypt() throws FileNotFoundException {
12
+
13
+
14
+        String expected="Funyy V pbzcner gurr gb n fhzzre’f qnl?\n" +
15
+                "Gubh neg zber ybiryl naq zber grzcrengr:\n" +
16
+                "Ebhtu jvaqf qb funxr gur qneyvat ohqf bs Znl,\n" +
17
+                "Naq fhzzre’f yrnfr ungu nyy gbb fubeg n qngr;\n" +
18
+                "Fbzrgvzr gbb ubg gur rlr bs urnira fuvarf,\n" +
19
+                "Naq bsgra vf uvf tbyq pbzcyrkvba qvzz'q;\n" +
20
+                "Naq rirel snve sebz snve fbzrgvzr qrpyvarf,\n" +
21
+                "Ol punapr be angher’f punatvat pbhefr hagevzz'q;\n" +
22
+                "Ohg gul rgreany fhzzre funyy abg snqr,\n" +
23
+                "Abe ybfr cbffrffvba bs gung snve gubh bj’fg;\n" +
24
+                "Abe funyy qrngu oent gubh jnaqre’fg va uvf funqr,\n" +
25
+                "Jura va rgreany yvarf gb gvzr gubh tebj’fg:\n" +
26
+                "   Fb ybat nf zra pna oerngur be rlrf pna frr,\n" +
27
+                "   Fb ybat yvirf guvf, naq guvf tvirf yvsr gb gurr.";
28
+
29
+       String actual=ROT13.encrpttextfile();
30
+
31
+        assertEquals(actual, expected);
32
+
33
+    }
34
+
35
+}

+ 22
- 1
Crypto/src/ROT13.java Wyświetl plik

@@ -1,3 +1,6 @@
1
+import java.io.File;
2
+import java.io.FileNotFoundException;
3
+import java.util.Scanner;
1 4
 
2 5
 public class ROT13  {
3 6
 
@@ -8,10 +11,11 @@ public class ROT13  {
8 11
     }
9 12
 
10 13
     ROT13() {
14
+        this.diff = 13;
11 15
     }
12 16
 
13 17
 
14
-    public String crypt(String text) throws UnsupportedOperationException {
18
+    public  String crypt(String text) throws UnsupportedOperationException {
15 19
         String str="";
16 20
 
17 21
         for (int i=0; i<text.length(); i++)
@@ -48,5 +52,22 @@ public class ROT13  {
48 52
         Integer diff=(int)c-(int)'A';
49 53
         return string.substring(diff,string.length())+string.substring(0,diff);
50 54
     }
55
+    public static String encrpttextfile() throws FileNotFoundException {
56
+        File file=new File("sonnet18.txt");
57
+        Scanner sc=new Scanner(file);
58
+        StringBuilder br =new StringBuilder();
59
+        while(sc.hasNext())
60
+        {
61
+            ROT13 rot13=new ROT13();
62
+            String str=rot13.crypt(sc.nextLine());
63
+            br.append(str+'\n');
64
+        }
65
+        System.out.println(br);
66
+        return br.toString().trim();
67
+    }
68
+
69
+    public static void main(String[] args) throws FileNotFoundException {
70
+        encrpttextfile();
71
+    }
51 72
 
52 73
 }

+ 1
- 1
Crypto/src/ROT13Test.java Wyświetl plik

@@ -84,7 +84,7 @@ public class ROT13Test {
84 84
 
85 85
         // When
86 86
         String actual = cipher.crypt(cipher.crypt(Q1));
87
-        System.out.println(actual);
87
+        //System.out.println(actual);
88 88
         // Then
89 89
         assertTrue(actual.equals(Q1));
90 90
     }