Skip to content

Commit b468f37

Browse files
committed
commit of the initial project
1 parent 3a25a86 commit b468f37

File tree

11 files changed

+671
-1
lines changed

11 files changed

+671
-1
lines changed

Comparator.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <iostream>
2+
#include "Comparator.hh"
3+
#include "md5.h" // source: http://www.zedwood.com/article/cpp-md5-function
4+
5+
Comparator::Comparator()
6+
{
7+
}
8+
9+
Comparator::~Comparator()
10+
{
11+
}
12+
13+
void Comparator::ShowMatches(std::vector<std::string> const& hashes,
14+
std::vector<std::string> const& words) const
15+
{
16+
for (std::vector<std::string>::const_iterator it = hashes.begin();
17+
it != hashes.end(); ++it)
18+
{
19+
bool found = false;
20+
for (std::vector<std::string>::const_iterator it2 = words.begin();
21+
it2 != words.end(); ++it2)
22+
{
23+
if ((*it).compare(md5(*it2)) == 0)
24+
{
25+
found = true;
26+
std::cout << "\"" << *it << "\" -> \"" << *it2 << "\"" << std::endl;
27+
break;
28+
}
29+
}
30+
if (!found)
31+
std::cout << "\"" << *it << "\" -> no match found" << std::endl;
32+
}
33+
}

Comparator.hh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef COMPARATOR_HH_
2+
# define COMPARATOR_HH_
3+
4+
#include <vector>
5+
6+
class Comparator
7+
{
8+
public:
9+
Comparator();
10+
~Comparator();
11+
12+
void ShowMatches(std::vector<std::string> const&,
13+
std::vector<std::string> const&) const;
14+
};
15+
16+
#endif

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#md5matcher @ 2016 Noël "biji" Do Van
2+
3+
CC = g++
4+
5+
RM = rm -f
6+
7+
NAME = md5matcher
8+
9+
SRCS = main.cpp \
10+
Parser.cpp \
11+
Comparator.cpp \
12+
13+
OBJS = $(SRCS:.cpp=.o)
14+
15+
SRCS2 = md5.c \
16+
17+
OBJS2 = $(SRCS2:.c=.o)
18+
19+
CXXFLAGS = -W -Wall -Wextra -Werror -O3
20+
21+
all: $(NAME)
22+
23+
$(NAME): $(OBJS) $(OBJS2)
24+
$(CC) -o $(NAME) $(OBJS) $(OBJS2)
25+
26+
clean:
27+
$(RM) $(OBJS) $(OBJS2)
28+
29+
fclean: clean
30+
$(RM) $(NAME)
31+
32+
re: fclean all
33+
34+
.PHONY: all clean fclean re

Parser.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include "Parser.hh"
4+
5+
Parser::Parser()
6+
{
7+
}
8+
9+
Parser::~Parser()
10+
{
11+
}
12+
13+
std::vector<std::string>& Parser::GetLines(std::string const& filename) const
14+
{
15+
std::ifstream ifs(filename.c_str());
16+
std::vector<std::string>* v = new std::vector<std::string>();
17+
std::string line;
18+
19+
if (ifs.is_open())
20+
while (std::getline(ifs, line))
21+
v->push_back(line);
22+
else
23+
std::cerr << "Error: opening file: " << filename << std::endl;
24+
return *v;
25+
}

Parser.hh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef PARSER_HH_
2+
# define PARSER_HH_
3+
4+
#include <vector>
5+
6+
class Parser
7+
{
8+
public:
9+
Parser();
10+
~Parser();
11+
12+
std::vector<std::string>& GetLines(std::string const&) const;
13+
};
14+
15+
#endif

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,38 @@
11
# md5matcher
2-
Program that will print matches between 2 files (list of hashes and dictionnary).
2+
3+
Simply get matches between 2 files:
4+
- A list of hash
5+
- A dictionnary
6+
7+
Written in C++ for performance usage.
8+
9+
### Usage
10+
11+
Compile it:
12+
13+
```sh
14+
git clone https://github.com/biji1/md5matcher.git
15+
cd md5matcher
16+
make
17+
```
18+
19+
Run it:
20+
21+
```sh
22+
./md5matcher example/hashes example/words
23+
```
24+
25+
Output:
26+
27+
```sh
28+
"c0af77cf8294ff93a5cdb2963ca9f038" -> "tree"
29+
"e6d96502596d7e7887b76646c5f615d9" -> "car"
30+
"7813258ef8c6b632dde8cc80f6bda62f" -> no match found
31+
"df53ca268240ca76670c8566ee54568a" -> "computer"
32+
"a1b8585122e1ad60623d6a74d3eb3b6a" -> "cake"
33+
time elapsed: 0 second(s)
34+
```
35+
36+
### About
37+
38+
No license. md5matcher @ 2016 Noel "biji" Do Van

example/hashes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
c0af77cf8294ff93a5cdb2963ca9f038
2+
e6d96502596d7e7887b76646c5f615d9
3+
7813258ef8c6b632dde8cc80f6bda62f
4+
df53ca268240ca76670c8566ee54568a
5+
a1b8585122e1ad60623d6a74d3eb3b6a

example/words

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
tree
2+
something_random
3+
car
4+
something_bla
5+
something_blabla
6+
computer
7+
something_blablabla
8+
cake
9+
something_morerandom

main.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <iostream>
2+
#include <ctime>
3+
#include "Parser.hh"
4+
#include "Comparator.hh"
5+
6+
int main(int ac, char** av)
7+
{
8+
// checking args
9+
if (ac != 3)
10+
{
11+
std::cerr << "Usage: " << av[0] << " <file1> <file2>" << std::endl;
12+
std::cerr << "<file1>: list of hashes" << std::endl;
13+
std::cerr << "<file2>: list of words" << std::endl;
14+
return -1;
15+
}
16+
17+
// getting datas
18+
Parser parser;
19+
std::string file1 = av[1], file2 = av[2];
20+
std::vector<std::string>& hashes = parser.GetLines(file1);
21+
std::vector<std::string>& words = parser.GetLines(file2);
22+
23+
// get matches with time
24+
Comparator comparator;
25+
clock_t begin, end;
26+
27+
begin = clock();
28+
comparator.ShowMatches(hashes, words);
29+
end = clock();
30+
31+
double elapsed = double(end - begin) / CLOCKS_PER_SEC;
32+
std::cout.precision(5);
33+
std::cout << "time elapsed: " << elapsed << " second(s)" << std::endl;
34+
35+
// cleaning
36+
hashes.clear();
37+
delete &hashes;
38+
words.clear();
39+
delete &words;
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)