-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecreateOriginalFile.cpp
More file actions
72 lines (63 loc) · 1.41 KB
/
RecreateOriginalFile.cpp
File metadata and controls
72 lines (63 loc) · 1.41 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// map<string, char> address2;
map<string, char> address3;
void readCompressedFile(ifstream &file, ofstream &newFile, int s)
{
string t = "";
char *n = new char[s];
char k;
int count = 0;
while (file.good())
{
file.read(n, s);
for (int i = 0; i < s; i++)
{
char ch = n[i];
count++;
// cout<<ch;
file.get(ch);
for (int i = 7; i > -1; i--)
{
k = ((ch >> i) & 1) ? '1' : '0';
t += k;
if (address3.count(t) > 0)
{
newFile << address3[t];
t = "";
}
}
}
}
// cout<<"Count is "<<count<<endl;
delete[] n;
}
void recreateHashmap(ifstream &file)
{
string k;
char r;
file.read(&r, 1);
char read_char;
while (true)
{
file.read(&read_char, 1);
if (read_char == r)
{
if (k.length() == 0)
{
break;
}
else
{
address3[k.substr(0, k.length() - 1)] = k[k.length() - 1];
k = "";
}
}
else
{
k += read_char;
}
}
for (map<string, char>::iterator i = address3.begin(); i != address3.end(); i++)
{
cout << i->first << ' ' << i->second << endl;
}
}