|
@@ -1,3 +1,8 @@
|
|
1
|
+import java.io.File;
|
|
2
|
+import java.io.IOException;
|
|
3
|
+import java.io.PrintWriter;
|
|
4
|
+import java.util.Scanner;
|
|
5
|
+
|
1
|
6
|
public class ROT13 {
|
2
|
7
|
|
3
|
8
|
private int shift;
|
|
@@ -22,7 +27,6 @@ public class ROT13 {
|
22
|
27
|
else if (Character.isUpperCase((text.charAt(i))))
|
23
|
28
|
encrypted.append((char) ('A' + ( (text.charAt(i) - 'A') + shift) %26));
|
24
|
29
|
else encrypted.append(text.charAt(i));
|
25
|
|
- System.out.println(encrypted);
|
26
|
30
|
}
|
27
|
31
|
return encrypted.toString();
|
28
|
32
|
}
|
|
@@ -46,4 +50,38 @@ public class ROT13 {
|
46
|
50
|
return beginning + end;
|
47
|
51
|
}
|
48
|
52
|
|
|
53
|
+ public String encryptFile(String readFile, String writeFile) {
|
|
54
|
+ File file = new File(readFile);
|
|
55
|
+ String encrypted = null;
|
|
56
|
+ try(Scanner scanner = new Scanner(file)){
|
|
57
|
+
|
|
58
|
+ String result = fileString(readFile);
|
|
59
|
+ encrypted = encrypt(result);
|
|
60
|
+
|
|
61
|
+ PrintWriter writer = new PrintWriter(writeFile, "UTF-8");
|
|
62
|
+ writer.print(encrypted);
|
|
63
|
+ writer.close();
|
|
64
|
+
|
|
65
|
+ }catch(IOException e){
|
|
66
|
+ e.printStackTrace();
|
|
67
|
+ }
|
|
68
|
+ return encrypted;
|
|
69
|
+ }
|
|
70
|
+ public String fileString (String fileName) {
|
|
71
|
+ File file = new File(fileName);
|
|
72
|
+ StringBuilder result = new StringBuilder("");
|
|
73
|
+ try(Scanner scanner = new Scanner(file)){
|
|
74
|
+ while(scanner.hasNextLine()){
|
|
75
|
+ String line = scanner.nextLine();
|
|
76
|
+ result.append(line).append("\n");
|
|
77
|
+ }
|
|
78
|
+ scanner.close();
|
|
79
|
+ return result.toString();
|
|
80
|
+ }
|
|
81
|
+ catch(IOException e){
|
|
82
|
+ e.printStackTrace();
|
|
83
|
+ return null;
|
|
84
|
+ }
|
|
85
|
+ }
|
|
86
|
+
|
49
|
87
|
}
|