-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
145 lines (111 loc) · 4 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <cstring>
//template <typename T, std::size_t N>
void printm(const unsigned char*mass,size_t size) /*, unsigned int lenght_string*/
{
//печать массива
for(int i=0;i<size;i++) //добавить в функцию аркумент - кол-во символов в строке
{
printf("%02x ",mass[i]);
if(i==9)
std::cout << std::endl;
if(i>10 && i%10==9)
std::cout << std::endl;
}
//std::cout << std::endl;
}
int main() {
/*
* данные на вход
*/
//генерация массива
int mass_element = 100;
unsigned char *mass = new unsigned char[mass_element];
// char mass[100] = {0};
//srand(time(0));
for(int i=0;i<mass_element;i++)
{
mass[i] = rand()%100; //максимальное значение элемента sizeof<type data>???
}
//добавление паттернов повторений
/*int number_of_inclusion = 3; //количество повторений
int lenght_of_pattern = 5; //длинна патерна
unsigned char *test_pattern = new unsigned char[lenght_of_pattern];*/
//srand(time(0));
/*for(int i=0;i<lenght_of_pattern;i++)
{
test_pattern[i] = rand()%100;
}*/
//printm(test_pattern,lenght_of_pattern);
/* pattern[0] = 0xAA;
pattern[1] = 0xAA;
pattern[2] = 0xAA;
pattern[3] = 0xAA;
pattern[4] = 0xAA; */
//получение позиций включения
/*unsigned char *inclusion_index = new unsigned char[number_of_inclusion];
inclusion_index[0] = 10;
inclusion_index[1] = 40;
inclusion_index[2] = 70;*/
//размещение включений
/*memcpy(mass+inclusion_index[0],test_pattern,5);
memcpy(mass+inclusion_index[1],test_pattern,5);
memcpy(mass+inclusion_index[2],test_pattern,5);*/
mass[5] = 0x29;
mass[6] = 0x43;
mass[11] = 0x29;
mass[12] = 0x43;
mass[5] = 0xAA;
mass[6] = 0xBB;
mass[7] = 0xCC;
mass[87] = 0xAA;
mass[88] = 0xBB;
mass[89] = 0xCC;
//вывод созданного массива
printm(mass,mass_element);
/*
* поиск паттернов повторений
*/
//инициализация хранилища паттерна повторений
int lenght_of_pattern = 2; //длинна патерна
int number_of_found_pattern = 0;
unsigned char *work_pattern = new unsigned char[lenght_of_pattern];
#define DEBUG_PRINT false
#define DEBUG_PRINT_FIND_PUTTERN true
for(int try_find=0;try_find<6;try_find++)
{
for(int offset_mass_ptr=0;offset_mass_ptr<mass_element-lenght_of_pattern;offset_mass_ptr++)
{
memcpy(work_pattern,mass+offset_mass_ptr,lenght_of_pattern);
#if DEBUG_PRINT == 1
printf(">>>>>> START find pattern ");
printm(work_pattern,lenght_of_pattern);
#endif
for(int i=0;i<mass_element;i++)
{
if(!memcmp(mass+i,work_pattern,lenght_of_pattern))
{
number_of_found_pattern++;
#if DEBUG_PRINT_FIND_PUTTERN == 1
//if(number_of_found_pattern-offset_mass_ptr>1)
{
printf("...find pattern ");
printm(work_pattern,lenght_of_pattern);
printf("position %d\n",i);
}
#endif
}
}
number_of_found_pattern = 0;
}
delete work_pattern;
lenght_of_pattern++; //нужна проверка длинны
work_pattern = new unsigned char[lenght_of_pattern];
//memcpy(work_pattern,mass,lenght_of_pattern);
}
//printf(">>>>>> pattern not found!\n");
/*
*
*/
std::cout << "<<<<<< END PROGRAMM >>>>>>" << std::endl;
}