-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsketch.cpp
66 lines (53 loc) · 1.67 KB
/
sketch.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
// sketch.cpp
//
// C++ code by Kevin Harmon and Leonid Reyzin
//
// Finds the PinSketch (BCH-based secure sketch) of an input set.
//
// See pinsketch.txt for detailed documentation
// This code and explanatory notes
// are hosted at http://www.cs.bu.edu/~reyzin/code/fuzzy.html
//
#include "pinsketch.h"
int main(int argc, char** argv)
{
long d; // minimum distance of the code;
// can handle set difference up to t=(d-1)/2 elements
// sketch is (d-1)/2 elements long
long m; // elements of the set and of the sketch are m-bit values
int len;// length of argv[1] if it exists
if (argc != 2 || (len=strlen(argv[1]))<5 || strcmp(&argv[1][len-4], ".set"))
{
cerr << "Usage: sketch A.set" << endl;
if (argc == 2)
cerr << "(file must be named `*.set`)" << endl;
return -1;
}
// Fix field and error-tolerance
ifstream infile(argv[1]);
if (!infile) {
cerr << "Could not open file for reading!\n";
return -1;
}
ReadSetParams(m, d, infile);
GF2X irrP;
BuildSparseIrred(irrP, m); // fix irreducible poly of deg m over GF(2)
GF2E::init(irrP); // fix field as GF(2^m)
// read in set
vec_GF2E set, ss;
ReadSet(set, infile, m);
infile.close();
// compute secure sketch of the set
BCHSyndromeCompute(ss, set, d);
// write the sketch to file with same name and .ss extension
strcpy(&argv[1][strlen(argv[1])-4], ".ss");
ofstream outfile (argv[1], ios::out | ios::trunc);
if (!outfile) {
cerr << "Could not open file for writing!\n";
return -1;
}
OutputSS(outfile, ss, d, GF2E::modulus());
outfile.close();
cout << "Secure sketch written to file `" << argv[1] << "`." << endl;
return 0;
}