Created
April 21, 2018 07:37
-
-
Save brv00/6f8f1756fb387405496007f1791043e6 to your computer and use it in GitHub Desktop.
This file contains 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
;; ファイステルネットワーク (JScheme) | |
(define-method (swap (x Long)) | |
(+ (>>> x 32) (<< x 32))) | |
(define-method (round (plain Long) f subkey) | |
(^ plain (<< (f (& plain Integer.MAX_VALUE$) subkey) 32))) | |
(define-method (feistel (plain Long) f subkeys) | |
(let lp ((p (round plain f (car subkeys))) (subkeys (cdr subkeys))) | |
(if (null? subkeys) p | |
(lp (round (swap p) f (car subkeys)) (cdr subkeys))))) | |
; (feistel 24L (lambda (p k) (^ (>> p 10) k)) '(66 77 88)) | |
; => 111669149781L | |
; (feistel 111669149781L (lambda (p k) (^ (>> p 10) k)) '(88 77 66)) | |
; => 24L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment