-
Notifications
You must be signed in to change notification settings - Fork 0
/
permutation.c
68 lines (55 loc) · 1.51 KB
/
permutation.c
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
67
68
/*
Michael Kochell
*/
#include "permutation.h"
/*
used to permutate a 64-bit number, outputs a 64-bit number
*/
unsigned long long performLongToLongPermutation(unsigned long long input, const int* pattern, const int patternSize)
{
int index;
unsigned long long currentBit, result = 0;
// iterate over chosen permutation template
for(index=0; index<patternSize; index++)
{
// extract target bit from input
currentBit = (input >> pattern[index]) & 0x1;
// accumulate result
result = result | (currentBit << (index));
}
return result;
}
/*
used to permutate a 32-bit number, outputs a 64-bit number
*/
unsigned long long performIntToLongPermutation(unsigned int input, const int* pattern, const int patternSize)
{
int index;
unsigned long long currentBit, result = 0;
// iterate over chosen permutation template
for(index=0; index<patternSize; index++)
{
// extract target bit from input
currentBit = (input >> pattern[index]) & 0x1;
// accumulate result
result = result | (currentBit << (index));
}
return result;
}
/*
used to permutate a 32-bit number, outputs a 32-bit number
*/
unsigned int performIntToIntPermutation(unsigned int input, const int* pattern, const int patternSize)
{
int index;
unsigned int currentBit, result = 0;
// iterate over chosen permutation template
for(index=0; index<patternSize; index++)
{
// extract target bit from input
currentBit = (input >> pattern[index]) & 0x1;
// accumulate result
result = result | (currentBit << (index));
}
return result;
}