Last active
August 29, 2015 14:15
-
-
Save zhuzhuor/5c63c8716f9e51f9e088 to your computer and use it in GitHub Desktop.
The block cipher SPECK128/128 written in one tweet
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
#include <stdio.h> | |
typedef unsigned long long u64; | |
#define R(x,y,k)x=x>>8|x<<56,x+=y,x^=k,y=y<<3|y>>61,y^=x | |
void SPECK(u64 *T,u64 *K){ | |
for(int i=0;i<32;){ | |
R(T[1],*T,*K); | |
R(K[1],*K,i++); | |
}} | |
int main() { | |
u64 key[2] = {0x0706050403020100, 0x0f0e0d0c0b0a0908}; | |
u64 text[2] = {0x7469206564616d20, 0x6c61766975716520}; | |
SPECK(text, key); | |
printf("%llx %llx\n", text[1], text[0]); | |
if (text[1] != 0xa65d985179783265 || text[0] != 0x7860fedf5c570d18) { | |
printf("The code is wrong!\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original tweet is at https://twitter.com/zhuzhuor/status/566054090128773120