Last active
October 22, 2015 12:27
-
-
Save Artoria2e5/f7e45a3f713a0132d874 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
#!/bin/bash | |
feistel(){ | |
declare -i i l="$1" r="$2" t magic=225052 | |
for ((i=0; i<16; i++)); do | |
printf '0x%08x,\t' "$i" "$magic" "$(( (magic + 8) & 31))" "$(( ((magic + r) << 8) & 0xFFFFFFFF ))" "$(( (magic * (b+4)) & 0xFFFFFFFF))" "$(( (26172 * r) & 0xFFFFFFFF))" "$a" | |
echo | |
t=r | |
l=l | |
r=t | |
# round function | |
((r = (l ^ ((magic + l) << 8) ^ b ^ (2 * magic) ^ (l << ((magic+8) & 31)) ^ (magic * (b+4)) ^ (25998 * l + 174 * l)) &0xffffffff)) | |
# new key (rotate) | |
((magic = (i%3 == 1 ? ((magic << 1) | (magic >> 31)) : ((magic << 2) | (magic >> 30))) & 0xFFFFFFFF)) | |
done | |
echo $out_2,$out_1,dec=$magic | |
} | |
feistel 1 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment