ATLAS Offline Software
Loading...
Searching...
No Matches
createBlindingKeys.cxx File Reference
#include <iostream>
#include <iomanip>
#include <set>
#include <string>
#include <cstdlib>
#include <ctime>
#include "BPhysTools/SimpleEncrypter.h"
Include dependency graph for createBlindingKeys.cxx:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 25 of file createBlindingKeys.cxx.

25 {
26
27 // Enable check (-c flag)
28 bool doCheck(false);
29 int nChecks(1);
30 if ( argc > 1 ) {
31 std::string arg(argv[1]);
32 if ( arg == "-c" ) doCheck = true;
33 }
34 if ( argc > 2 ) {
35 nChecks = atoi(argv[2]);
36 }
37
38 // Helper object
40
41 // Create key pair
42 std::pair<std::string, std::string> keys = senc.genKeyPair();
43
44 std::cout << std::endl;
45 std::cout << "Blinding keys generated:" << std::endl;
46 std::cout << " Private key: " << keys.first << std::endl;
47 std::cout << " Public key: " << keys.second << std::endl;
48 std::cout << std::endl;
49
50 // check that encryption works
51 if ( doCheck ) {
52 srand(static_cast<unsigned>(time(0)));
53
54 std::cout << "Encryption test:" << std::endl;
55 int nOK(0);
56 for (int i=0; i<nChecks; ++i) {
57 float val = 10000.*
58 static_cast <float>(rand())/(static_cast <float> (RAND_MAX));
59 // float val = 5267.23;
60 float enc = senc.encrypt(val);
61 float dec = senc.decrypt(enc);
62 if ( dec == val ) ++nOK;
63 if ( i == 0 || dec != val ) {
64 std::cout << " Test # " << i << std::endl;
65 std::cout << " val = " << val << std::endl;
66 std::cout << " enc = " << enc << std::endl;
67 std::cout << " dec = " << dec << std::endl;
68 if ( dec == val ) {
69 std::cout << " => worked!" << std::endl;
70 } else {
71 std::cout << " => FAILED!" << std::endl;
72 }
73 } // if
74 } // for
75 std::cout << std::endl;
76 std::cout << "Summary:" << std::endl;
77 std::cout << " nChecks: " << std::setw(12) << nChecks << std::endl;
78 std::cout << " nOK : " << std::setw(12) << nOK << std::endl;
79 std::cout << " nFailed: " << std::setw(12) << nChecks - nOK << std::endl;
80 } // if
81
82 return 0;
83}
Provide simple asymmetric encryption for blinding of float values.
virtual ULLI_t encrypt(ULLI_t x)
Encrypt a positive integer value.
virtual ULLI_t decrypt(ULLI_t x)
Decrypt a positive integer value.
virtual std::pair< std::string, std::string > genKeyPair()
Generate private and public keys.
time(flags, cells_name, *args, **kw)
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...