Skip to content

Instantly share code, notes, and snippets.

@zhuzhuor
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhuzhuor/5c63c8716f9e51f9e088 to your computer and use it in GitHub Desktop.
Save zhuzhuor/5c63c8716f9e51f9e088 to your computer and use it in GitHub Desktop.
The block cipher SPECK128/128 written in one tweet
#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;
}
@zhuzhuor
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment