SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
secure_permutation.hpp
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
30 #ifndef SECURE_PERMUTATION_IMPLEMENTATION_GUARD
31 #define SECURE_PERMUTATION_IMPLEMENTATION_GUARD
32 
33 namespace SeComLib {
34 namespace Core {
40  template <typename T_DataType>
41  void SecurePermutation::Permute (T_DataType &vector) const {
42  if (this->vectorSize != vector.size()) {
43  throw std::runtime_error("The input vector doesn't have the expected size.");
44  }
45 
46  for (PermutationVector::const_iterator permutation = permutations.begin(); permutation != permutations.end(); ++permutation) {
47  std::swap(vector[permutation->first], vector[permutation->second]);
48  }
49  }
50 
56  template <typename T_DataType>
57  void SecurePermutation::InvertPermutation (T_DataType &vector) const {
58  if (this->vectorSize != vector.size()) {
59  throw std::runtime_error("The input vector doesn't have the expected size.");
60  }
61 
62  for (PermutationVector::const_reverse_iterator permutation = permutations.rbegin(); permutation != permutations.rend(); ++permutation) {
63  std::swap(vector[permutation->first], vector[permutation->second]);
64  }
65  }
66 
67 }//namespace Core
68 }//namespace SeComLib
69 
70 #endif//SECURE_PERMUTATION_IMPLEMENTATION_GUARD
void InvertPermutation(T_DataType &vector) const
Applies the permutations in reverse to the input verctor.
PermutationVector permutations
The vector of permutations.
void Permute(T_DataType &vector) const
Applies the permutations to the input vector.
const size_t vectorSize
The size of the vectors that can be permuted.