#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
typedef unsigned long int ENCRYTP_WORD; /* Should be 32-bit = 4 bytes */
#define Rc5_w 32 /* word size in bits */
#define Rc5_r 12 /* number of rounds */
#define Rc5_b 16 /* number of bytes in key */
#define Rc5_c 4 /* number words in key = ceil(8*Rc5_b/Rc5_w)*/
#define Rc5_t 26 /* size of table Rc5_S = 2*(Rc5_r+1) words */
ENCRYTP_WORD Rc5_S[Rc5_t]; /* expanded key table */
ENCRYTP_WORD Rc5_P = 0xb7e15163, Rc5_Q = 0x9e3779b9; /* magic constants */
/* Rotation operators. x must be unsigned, to get logical right shift*/
#define ROTL(x,y) (((x)<<(y&(Rc5_w-1))) | ((x)>>(Rc5_w-(y&(Rc5_w-1)))))
#define ROTR(x,y) (((x)>>(y&(Rc5_w-1))) | ((x)<<(Rc5_w-(y&(Rc5_w-1)))))
void RC5_ENCRYPT(ENCRYTP_WORD *pt, ENCRYTP_WORD *ct) /* 2 ENCRYTP_WORD input pt/output ct */
{
ENCRYTP_WORD i, A=pt[0]+Rc5_S[0], B=pt[1]+Rc5_S[1];
for (i=1; i<=Rc5_r; i++)
{
A = ROTL(A^B,B)+Rc5_S[2*i];
B = ROTL(B^A,A)+Rc5_S[2*i+1];
}
ct[0] = A; ct[1] = B;
}