set1/src/fixed-xor.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/*
void fixed_xor_stream(uint8_t *key, size_t key_len)
{
//
}
*/
void fixed_xor(const uint8_t *data, const size_t data_len,
const uint8_t *key, const size_t key_len)
{
uint8_t c;
size_t i, k;
for (i = 0; i < data_len; i = i + key_len) {
for (k = 0; k < key_len && i+k < data_len; ++k) {
c = data[i+k] ^ key[k];
putchar(c);
}
}
}
int main()
{
uint8_t data[] = "\x1c\x01\x11\x00\x1f\x01\x01\x00\x06\x1a\x02\x4b\x53"
"\x53\x50\x09\x18\x1c\x00\x00\x00\x00\x00\x00\x00";
uint8_t key[] = "\x68\x69\x74\x20\x74\x68\x65\x20\x62\x75\x6c\x6c\x27"
"\x73\x20\x65\x79\x65";
fixed_xor(data, sizeof(data)-1, key, sizeof(key)-1);
return EXIT_SUCCESS;
}
|