Explorar el Código

did i even change anything?

Abrahim Ladha %!s(int64=9) %!d(string=hace) años
padre
commit
2cf3e0699e

+ 30 - 66
testing/basic.cpp

@ -3,16 +3,16 @@
3 3
#include <gmp.h>
4 4
#include <math.h>
5 5
#include <iostream>
6
#include <map>
7 6
#include <vector>
8
#include <omp.h>
9
#include <fstream>
10 7
using namespace std;
8
/*
9
 * returns a vector of all bitstrings up to a
10
 * certain length
11
*/
11 12
vector<string> bitstring_generator(unsigned long n){
12 13
    vector<string> bitstrings(pow(2,n));
13 14
    bitstrings.push_back("0");
14 15
    bitstrings.push_back("1");
15
16 16
    for(int j = 1; j < n; j++){
17 17
        int x = bitstrings.size();
18 18
        for(int i = 0; i < x; i++){
@ -28,12 +28,12 @@ vector<string> bitstring_generator(unsigned long n){
28 28
            }
29 29
        }
30 30
    }
31
    for(int i = 0; i < bitstrings.size(); i++){
32
  //      cout << bitstrings[i] << endl;
33
    }
34 31
    return bitstrings;
35
36 32
}
33
/*
34
 * given some bitstring, it returns its
35
 * vector equivalent
36
 */
37 37
vector<unsigned long> string_to_vector(string s){
38 38
     vector<unsigned long> Y(s.length());
39 39
    for(int i = 0; i < Y.size(); i++){
@ -41,6 +41,10 @@ vector<unsigned long> string_to_vector(string s){
41 41
    }
42 42
    return Y;
43 43
}
44
/*
45
 * filters a vector of bitstrings to only use those
46
 * of a certain length
47
 */
44 48
vector<string> bitstrings_of_length(vector<string> strings, int n){
45 49
     vector<string> bitstrings;
46 50
    for(int i = 0; i < strings.size(); i++){
@ -49,19 +53,29 @@ vector<string> bitstrings_of_length(vector<string> strings, int n){
49 53
    }
50 54
    return bitstrings;
51 55
}
56
/*
57
 * computes sum of a vector of ulongs
58
 */
52 59
unsigned long vector_sum(vector<unsigned long> v){
53 60
    unsigned long sum;
54 61
    for(int i = 0; i < v.size(); i++)
55 62
        sum += v[i];
56 63
    return sum;
57 64
}
65
/*
66
 * computes sum of a vector of doubles
67
 */
58 68
double vector_sumd(vector<double> v){
59 69
    double sum;
60 70
    for(int i = 0; i < v.size(); i++)
61 71
        sum += v[i];
62 72
    return sum;
63 73
}
74
/*
75
 * given two vectors, returns their hamming distance
76
 */
64 77
unsigned long basic_scheme(vector<unsigned long> X, vector<unsigned long> Y){
78
    //tiny error check
65 79
    if(X.size() != Y.size()){
66 80
        cout << "vector sizes do not match" << endl;
67 81
        cout << X.size()  << "\t" << Y.size() << endl;
@ -73,79 +87,29 @@ unsigned long basic_scheme(vector<unsigned long> X, vector<unsigned long> Y){
73 87
    gmp_randstate_t rstate;
74 88
    gmp_randinit_mt(rstate);
75 89
    gmp_randseed_ui(rstate,seed);
76
77 90
    mpz_class temp, n;
78
    n = X.size() + 1;
91
    n = X.size() + 1; //could be bigger
92
    //make r a vector of uniformly randoms
79 93
    for(int i = 0; i < X.size(); i++){
80
        mpz_urandomm(temp.get_mpz_t(),rstate,n.get_mpz_t()); //m instead of b
94
        mpz_urandomm(temp.get_mpz_t(),rstate,n.get_mpz_t());
81 95
        r[i] = temp.get_ui();
82
        //r[i] = rand()% (X.size() + 1);
83
84 96
    }
97
    //compute their sum
85 98
    unsigned long R = vector_sum(r);
86
    //generate n random values in Zn+1 and compute R as their sum
87
88 99
    vector<unsigned long> t(X.size());
89 100
    vector<unsigned long> tuple(2);
90 101
    for(int i = 0; i < X.size(); i++){
91 102
        tuple[0] = (r[i] + X[i]) % domain;
92 103
        tuple[1] = (r[i] + (1 - X[i])) % domain;
93
94
        t[i] = tuple[Y[i]];
104
        t[i] = tuple[Y[i]]; //choosing
95 105
    }
106
    //comute their sum
96 107
    unsigned long T = vector_sum(t);
97
    //p2 computes T as sum of ti
108
    //subtract off the random values
98 109
    int total = T - R;
99
110
    //some modular issues
100 111
    while(total < 0){
101 112
        total += (X.size() + 1);
102 113
    }
103
    //total %= (X.size() + 1);
104
    //cout << T << "  " << R <<"  " << total << "  " << total
105
    //    %domain << "  " << domain << endl;
106 114
    return total;
107
    //p2 sends T to p1
108
    //p1 computes and outputs T - R
109 115
}
110
/*
111
int main(void){
112
    string x,y;
113
    cout << "give bitstring X" << endl;
114
    cin >> x;
115
    cout << "give bitstring Y" << endl;
116
    cin >> y;
117
    vector<unsigned long> X(x.length());
118
    vector<unsigned long> Y(y.length());
119
    for(int i = 0; i < X.size(); i++){
120
        X[i] = x[i] - '0';
121
        Y[i] = y[i] - '0';
122
    }
123
124
//double start  = omp_get_wtime();
125
    //basic_scheme(X,Y);
126
    //double end = omp_get_wtime();
127
128
    ofstream out;
129
    out.open("output.txt");
130
    for(int m = 2; m < pow(2,31); m++){
131
    vector<string> btis = bitstrings_of_length(bitstring_generator(m),m);
132
    vector<double> times;
133
    for(int i = 0; i < btis.size(); i++){
134
        for(int j = 0; j < btis.size(); j++){
135
            double start = omp_get_wtime();
136
            int temp = basic_scheme(string_to_vector(btis[i]),string_to_vector(btis[j]));
137
            double end = omp_get_wtime();
138
            times.push_back(end-start);
139
        }
140
    }
141
    out << m << "," << (vector_sumd(times)/(double)times.size()) << endl;
142
    }
143
    out.close();
144
    //cout << end - start << endl;
145
146
147
    //for(int i = 0; i < btis.size(); i++){
148
    //    cout << btis[i] << endl;
149
    //}
150
151
 }*/

+ 0 - 4
testing/basic.h

@ -1,7 +1,5 @@
1 1
#ifndef BASIC_H
2 2
#define BASIC_H
3
4
5 3
#include <string>
6 4
#include <gmpxx.h>
7 5
#include <gmp.h>
@ -12,12 +10,10 @@
12 10
#include <omp.h>
13 11
#include <fstream>
14 12
using namespace std;
15
16 13
vector<string> bitstring_generator(unsigned long n);
17 14
vector<unsigned long> string_to_vector(string s);
18 15
vector<string> bitstrings_of_length(vector<string> strings, int n);
19 16
unsigned long vector_sum(vector<unsigned long> v);
20 17
double vector_sumd(vector<double> v);
21 18
unsigned long basic_scheme(vector<unsigned long> X, vector<unsigned long> Y);
22
23 19
#endif

testing/graph1.png → testing/extra/graph1.png


testing/graphing/.~lock.n_vs_setsize_vs_time.csv# → testing/extra/graphing/.~lock.n_vs_setsize_vs_time.csv#


testing/graphing/g1.png → testing/extra/graphing/g1.png


testing/graphing/g2.png → testing/extra/graphing/g2.png


testing/graphing/g3.png → testing/extra/graphing/g3.png


testing/graphing/line.p → testing/extra/graphing/line.p


testing/graphing/n_vs_setsize_vs_time.csv → testing/extra/graphing/n_vs_setsize_vs_time.csv


testing/graphing/totalset → testing/extra/graphing/totalset


testing/hd_vs_time.cpp → testing/extra/hd_vs_time.cpp


testing/hd_vs_time_10.txt → testing/extra/hd_vs_time_10.txt


testing/inputn-complete.txt → testing/extra/inputn-complete.txt


testing/inputn1.txt → testing/extra/inputn1.txt


testing/notes → testing/extra/notes


testing/output.csv → testing/extra/output.csv


testing/output1.csv → testing/extra/output1.csv


testing/output1.txt → testing/extra/output1.txt


testing/thing.out → testing/extra/thing.out


+ 10 - 10
testing/inputn.txt

@ -1,19 +1,19 @@
1
11111
1
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
2 2
----
3
11111
3
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
4 4
----
5
11111
5
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
6 6
----
7
11111
7
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
8 8
----
9
11111
9
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
10 10
----
11
11111
11
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
12 12
----
13
11111
13
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
14 14
----
15
11111
15
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
16 16
----
17
11111
17
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
18 18
----
19
11111
19
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

+ 5 - 40
testing/main.cpp

@ -8,49 +8,15 @@
8 8
#include <fstream>
9 9
#include "basic.h"
10 10
using namespace std;
11
/*int main(void){
12
13
    ifstream in1("input1.txt");
14
    ifstream in2("input2.txt");
15
    ofstream out1("output1.txt");
16
17
    vector<string> input1;
18
    vector<string> input2;
19
20
    string test;
21
    while(getline(in1,test)){
22
        input1.push_back(test);
23
    }
24
    string test2;
25
    while(getline(in2,test2)){
26
        input2.push_back(test2);
27
    }
28
    vector<string> output1;
29
    for(int i = 0; i < input1.size(); i++){
30
        for(int j = 0; j < input2.size();j++){
31
            vector<unsigned long> temp1 = string_to_vector(input1[i]);
32
            vector<unsigned long> temp2 = string_to_vector(input2[j]);
33
34
            if(basic_scheme(string_to_vector(input1[i]),string_to_vector(input2[j])) == 0){
35
                output1.push_back(input2[j]);
36
            }
37
38
        }
39
    }
40
    for(int k = 0; k < output1.size();k++){
41
        out1 << output1[k] << endl;
42
    }
43
}
44
*/
45 11
int main(void){
46
    int n = 10;
47
    ifstream in("inputn.txt");
48
    ofstream out("output.txt");
12
    int n = 10; //how many parties?
13
    ifstream in("inputn.txt"); //input file
14
    ofstream out("output.txt"); //output file
49 15
    vector<vector<string>> input(n);
50 16
    string line;
51 17
    int i = 0;
52 18
    while(getline(in,line)){
53
        if(line == "----"){
19
        if(line == "----"){ //our delimiter for sets
54 20
            i++;
55 21
        }
56 22
        else{
@ -78,7 +44,6 @@ int main(void){
78 44
        output.erase(output.begin(),output.end());
79 45
    }
80 46
    for(int k = 0; k < input[1].size(); k++){
81
        out << input[1][k] << endl;
47
        out << input[1][k] << endl; //second set
82 48
    }
83
84 49
}

+ 1 - 1
testing/output.txt

@ -1 +1 @@
1
11111
1
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

+ 3 - 19
testing/systems/elgamal_gmpxx.cpp

@ -5,15 +5,13 @@
5 5
#include <iostream>
6 6
#include <map>
7 7
using namespace std;
8
//using std::cout;
9
8
/*
9
 * zero knowledge proof for elgamal
10
 */
10 11
bool elgamal_ff(mpz_class q, mpz_class h, mpz_class g, mpz_class b1,
11 12
        mpz_class b2, mpz_class x1, mpz_class x2){
12
13 13
    map <string, mpz_class> buffer;
14
15 14
    mpz_class l, rand;
16
    //mpz_t a =
17 15
    mpz_ui_pow_ui(l.get_mpz_t(),2,199);
18 16
    unsigned long seed = (unsigned long)time(NULL);
19 17
    gmp_randstate_t rstate;
@ -62,18 +60,4 @@ bool elgamal_ff(mpz_class q, mpz_class h, mpz_class g, mpz_class b1,
62 60
    mpz_powm(temp4.get_mpz_t(),h.get_mpz_t(),r2.get_mpz_t(),q.get_mpz_t());
63 61
64 62
    return ((c == c1 + c2) && (t2 == temp5 * temp6) && (t1 == temp3 * temp4));
65
    //cout << "sum is" << l << endl;
66
    //gmp_printf("%Zd\n",l);
67
    return true;
68
}
69
int main(void){
70
    mpz_class l, x;//, y;
71
    x = "2";
72
    unsigned long y = 199;
73
    //l = ipow(x,y);
74
    mpz_pow_ui(l.get_mpz_t(),x.get_mpz_t(),y);
75
    cout << l << endl;
76
    //gmp_printf("%Zd\n",l.get_mpz_t());
77
    //cout << l << endl;
78
79 63
}

+ 3 - 0
testing/systems/paillier.cpp

@ -1,3 +1,6 @@
1
/*
2
 * UNFINISHED WORK
3
 */
1 4
#include <gmpxx.h>
2 5
#include <gmp.h>
3 6
#include <string>