Created
February 17, 2017 12:10
-
-
Save niamtokik/423f7b69c4645fed40374ccbbf52f24e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// feistel network test | |
// currently doesn't work as expected. | |
// the idea is to use variable return | |
// function to make branchment instead | |
// of traditional datastructure. | |
package main | |
import "fmt" | |
func f(k int64, r int64) int64 { | |
ret := (r ^ k << 1) | |
fmt.Printf("f: %0.2x\n", ret) | |
return ret | |
} | |
func block(k int64, l int64, r int64) (int64, int64) { | |
fmt.Printf("%0.2x %0.2x %0.2x\n", k, l, r) | |
lret := r | |
rret := f(k, r) ^ l | |
fmt.Printf("%0.2x %0.2x %0.2x\n", k, lret, rret) | |
return lret, rret | |
} | |
func test() { | |
var i int64 | |
var l int64 | |
var r int64 | |
l = 12 | |
r = 13 | |
for i = 0; i < 24; i++ { | |
l, r = block(i, l, r) | |
} | |
fmt.Printf("__ %0.2x %0.2x\n", l, r) | |
ll := l | |
rr := r | |
fmt.Println() | |
for i = 23; i >= 0; i-- { | |
ll, rr = block(i, ll, rr) | |
} | |
fmt.Printf("__ %0.2x %0.2x\n", ll, rr) | |
} | |
func main() { | |
test() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment