-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmd5reader.cpp
64 lines (55 loc) · 1.34 KB
/
md5reader.cpp
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
#include <iostream>
#include <fstream>
#include "md5.hpp"
class FileReader
{
private:
std::ifstream fin;
long long length=0;
public:
FileReader(std::string filename):fin(std::ifstream(filename.c_str(), std::ios::in|std::ios::binary))
{
if(!fin)
{
std::cerr<<"File : " << filename << " was not found."<<std::endl;;
std::terminate();
//throw std::exception();
}
}
block read_block()
{
block b = block(BLOCK_SIZE, words(WORDS_SIZE));
for(int i=0;i<BLOCK_SIZE;i++)
{
for(int j=0;j<WORDS_SIZE;j++)
{
for(int k=0;k<4;k++) //32bit / 8bit
{
char c;
if(!fin.eof())
{
fin.read((char*)&c,sizeof(char));
if(!fin.eof())
length+=8;
else
c=0;
}
else
{
c=0;
}
b[i][j]+=(word)(c)<<(k*8);
}
}
}
return b;
}
long long get_length()
{
return length;
}
bool is_readable()
{
return !fin.eof();
}
};