-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewEncrypt.java
More file actions
58 lines (39 loc) · 1.18 KB
/
NewEncrypt.java
File metadata and controls
58 lines (39 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;
public class NewEncrypt {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("/home/erik/ExternalProjects/crypt/source.txt"));
String sourceTxt = "";
try {
StringBuilder builder = new StringBuilder();
String line = br.readLine();
while (line != null) {
builder.append(line);
builder.append(System.lineSeparator());
line = br.readLine();
}
sourceTxt = builder.toString();
} finally {
br.close();
}
String encSourceTxt = "";
String encSourceTxtAll = "";
int lengthNow = sourceTxt.length();
System.out.println(sourceTxt);
while (lengthNow > 1) {
Random random = new Random();
int generatedNumber = random.nextInt(lengthNow);
encSourceTxt = sourceTxt.substring(0, generatedNumber);
sourceTxt = sourceTxt.substring(generatedNumber);
System.out.println(sourceTxt);
lengthNow = sourceTxt.length();
encSourceTxtAll += encSourceTxt;
}
}
private int getRandomInt(int length) {
Random random = new Random();
return random.nextInt(length);
}
}