-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeistel.cpp
More file actions
45 lines (34 loc) · 700 Bytes
/
Copy pathfeistel.cpp
File metadata and controls
45 lines (34 loc) · 700 Bytes
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
#include <iostream>
#include <stdint.h>
using namespace std;
uint8_t non_linear(uint8_t x) {
return (((x << 7) ^ (x >> 2) ) + (x & 93) - (x & 19) + 123) & 0xff;
}
void fn_round(uint8_t *p) {
uint8_t l = p[0];
uint8_t r = p[1];
uint8_t new_l = r;
uint8_t new_r = l ^ non_linear(r);
p[0] = new_l;
p[1] = new_r;
}
void fn_deround(uint8_t *p) {
uint8_t l = p[0];
uint8_t r = p[1];
uint8_t old_r = l;
uint8_t old_l = r ^ non_linear(l);
p[0] = old_l;
p[1] = old_r;
}
int main() {
for(uint16_t i = 0; i <= 0xff; i++) {
uint16_t n = i;
uint8_t *p = (uint8_t*) &n;
cout << n << " -> ";
fn_round(p);
cout << n << " -> ";
fn_deround(p);
cout << n << endl;
}
return 0;
}