-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomoracle.cpp
More file actions
30 lines (28 loc) · 909 Bytes
/
Copy pathrandomoracle.cpp
File metadata and controls
30 lines (28 loc) · 909 Bytes
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
#include "oracle.h"
#include <unordered_map>
RandomOracle::RandomOracle(std::size_t _n, std::size_t _m, int rand_seed) {
n = _n, m = _m;
my_rand = std::default_random_engine(rand_seed);
for (size_t i = 0; i < m; i++) {
secret_string.push_back(i);
}
std::shuffle(secret_string.begin(), secret_string.end(), my_rand);
secret_string.resize(n);
}
Response RandomOracle::query(const std::vector <int> &query_string) {
std::unordered_map <int, std::size_t> map;
int cows = 0, bulls = 0;
for (std::size_t i = 0; i < query_string.size(); i++) {
map[query_string[i]] = i;
}
for (std::size_t i = 0; i < secret_string.size(); i++) {
if (map.count(secret_string[i])) {
if (map[secret_string[i]] == i) {
bulls++;
} else {
cows++;
}
}
}
return Response(cows, bulls);
}