Skip to content

Instantly share code, notes, and snippets.

@quydm
Created December 13, 2016 09:30
Show Gist options
  • Save quydm/cd2df1ba7213a7f598529e59f5ee843c to your computer and use it in GitHub Desktop.
Save quydm/cd2df1ba7213a7f598529e59f5ee843c to your computer and use it in GitHub Desktop.
XXTEA sample for C
#include <stdio.h>
#include <string.h>
#include "base64.h"
#include "xxtea.h"
int main(int argc, const char * argv[]) {
const char *key = "123456";
const char *str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit";
size_t len;
unsigned char *encrypt_data = xxtea_encrypt(str, strlen(str), key, &len);
char *base64_data = base64_encode(encrypt_data, len);
printf("encrypt_data: %s\n", base64_data);
unsigned char *decode_data = base64_decode(base64_data, &len);
char *decrypt_data = xxtea_decrypt(decode_data, len, key, &len);
printf("decrypt_data: %s\n", decrypt_data);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment