ATLAS Offline Software
createBlindingKeys.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
14 // system includes:
15 #include <iostream>
16 #include <iomanip>
17 #include <set>
18 #include <string>
19 #include <cstdlib>
20 #include <ctime>
21 
22 // Local include(s):
24 
25 int main(int argc, char* argv[]) {
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 }
xAOD::SimpleEncrypter::encrypt
virtual ULLI_t encrypt(ULLI_t x)
Encrypt a positive integer value.
Definition: SimpleEncrypter.cxx:120
xAOD::SimpleEncrypter::genKeyPair
virtual std::pair< std::string, std::string > genKeyPair()
Generate private and public keys.
Definition: SimpleEncrypter.cxx:60
SimpleEncrypter.h
Provide simple asymmetric encryption for blinding of float values.
xAOD::SimpleEncrypter
Provide simple asymmetric encryption for blinding of float values.
Definition: SimpleEncrypter.h:36
LArG4FSStartPointFilter.rand
rand
Definition: LArG4FSStartPointFilter.py:80
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
main
int main(int argc, char *argv[])
Definition: createBlindingKeys.cxx:25
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
xAOD::SimpleEncrypter::decrypt
virtual ULLI_t decrypt(ULLI_t x)
Decrypt a positive integer value.
Definition: SimpleEncrypter.cxx:132
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
CxxUtils::atoi
int atoi(std::string_view str)
Helper functions to unpack numbers decoded in string into integers and doubles The strings are requir...
Definition: Control/CxxUtils/Root/StringUtils.cxx:85
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:798