-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHuffmanDecrypt.java
70 lines (60 loc) · 2.1 KB
/
HuffmanDecrypt.java
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
59
60
61
62
63
64
65
66
67
68
69
70
package huffman.decrypt;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class HuffmanDecrypt {
static List<Karakter> krt = new ArrayList<>();
public static String dosyaOku() throws IOException{
String[] satir;
FileReader fileReader = new FileReader("C:\\Users\\Betül Özsoy\\Desktop\\encrypted.txt");
String line;
String sifreli = null;
int bayrak = 1;
try (BufferedReader br = new BufferedReader(fileReader)) {
while ((line = br.readLine()) != null) {
Karakter temp = new Karakter();
if(line.equals("")){
bayrak = 0;
}
if(bayrak == 1){
satir = line.split("-");
temp.sembol = satir[0];
temp.temsil = satir[1];
krt.add(temp);
}
else {
sifreli = line;
}
}
}
return sifreli;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
String sifreli = dosyaOku();
/*System.out.println(sifreli);
for(int i=0 ; i<krt.size() ; i++){
System.out.println(krt.get(i).sembol + " -> " + krt.get(i).temsil);
}*/
String tampon = new String();
String cumle = new String();
boolean bayrak = false;
for(int i=0 ; i<sifreli.length() ; i++){
tampon+=sifreli.charAt(i);
for(int j=0 ; j<krt.size() ; j++){
if(tampon.equals(krt.get(j).temsil)){
cumle+=krt.get(j).sembol;
bayrak=true;
break;
}
}
if(bayrak){
tampon = "";
bayrak = false;
}
}
System.out.println(cumle);
}
}