#include <stdio.h> #include <stdlib.h> #include <time.h> static const int XTEA_KEY_SIZE = 17; /* bytes */ static const int XTEA_KEY_RANGE = 58; /* ASCII letters*/ static char xtea_key[XTEA_KEY_SIZE]; void gen_xtea_key(void) { int i; srand(time(NULL)); for (i = 0; i < XTEA_KEY_SIZE; i++) { if (i < XTEA_KEY_SIZE - 1) { xtea_key[i] = rand() % XTEA_KEY_RANGE + 'A'; } else { printf("xtea_key[i] = 0;\n"); xtea_key[i] = 0; } printf("c = %c, d = %u\n", xtea_key[i], xtea_key[i]); } } int main() { gen_xtea_key(); printf("key = %s\n", xtea_key); return 0; }
Standard input is empty
c = [, d = 91 c = N, d = 78 c = N, d = 78 c = r, d = 114 c = H, d = 72 c = K, d = 75 c = J, d = 74 c = ^, d = 94 c = h, d = 104 c = C, d = 67 c = l, d = 108 c = q, d = 113 c = V, d = 86 c = ^, d = 94 c = r, d = 114 c = e, d = 101 xtea_key[i] = 0; c = , d = 0 key = [NNrHKJ^hClqV^re