int main(int argc, char * argv[]) { char x[M], y[M], z[M]; int i; if(argc != 3) { fprintf(stderr, "Usage: %s binarynum1 binarynum2\n",argv[0]); exit(EXIT_FAILURE); } for(i='2';i<='9';i++) if(strchr(argv[1],i) != NULL) { puts("binary number only contain 0 and 1 !"); exit(EXIT_FAILURE); } for(i='2';i<='9';i++) if(strchr(argv[2],i) != NULL) { puts("binary number only contain 0 and 1 !"); exit(EXIT_FAILURE); } printf(" x = %s\n", extend(x,argv[1])); printf(" y = %s\n", extend(y,argv[2])); printf(" ~x = %s\n", reverse(z,x)); printf(" ~y = %s\n", reverse(z,y)); printf(" x & y = %s\n", and(z,x,y)); printf(" x | y = %s\n", or(z,x,y)); printf(" x ^ y = %s\n", exclusive_or(z,x,y)); return 0; }
void decoder_read_payload(struct decoder *decoder, uint8_t *payload_in) { uint8_t *payload = (uint8_t *) calloc(decoder->symbol_size, sizeof(uint8_t)); uint8_t vector; memcpy(payload, payload_in, decoder->symbol_size); vector = payload_in[decoder->symbol_size]; /* get the most significant bit of the vector */ int32_t msb = msb32(vector); /* the decoder state should be initialized to be 0 */ while (msb >= 0 && decoder->state[msb]) { vector ^= decoder->state[msb]; exclusive_or(payload, decoder->data[msb], decoder->symbol_size); msb = msb32(vector); } if (msb >= 0) { decoder->data[msb] = payload; decoder->state[msb] = vector; decoder->rank++; } else { free(payload); } decoder->count++; }
int main(int argc, char *argv[]) { uint32_t bit; uint32_t i; uint32_t nb_bits_samples = NB_BITS_SAMPLES; uint32_t nb_bytes_samples = nb_bits_samples / 8; uint32_t nb_bytes = 0; uint8_t samples[nb_bytes_samples]; signal(SIGINT, signal_handler); if(argc > 1 && strcmp(argv[1], "-d") == 0) daemonize(); create_fifo_and_wait("w", "Waiting for server to start...", "Server started : could start Random numbers generation."); qrand_setup(); while (keep_going) { for (i = 0; i < nb_bits_samples; i++) { bit = qrand(); nb_bytes = exclusive_or(bit, (uint8_t*)&samples); if(nb_bytes >= nb_bytes_samples) { send_numbers((uint8_t*)&samples, nb_bytes_samples); } usleep(SLEEP_INTERVAL); } } qrand_close(); return 0; }
inline byte Random::debias(byte input){ //do bias removal switch(_bias_removal){ case VON_NEUMANN: return von_neumann(input); case EXCLUSIVE_OR: return exclusive_or(input); case NO_BIAS_REMOVAL: return input; } }
void decoder_decode_block(struct decoder *decoder) { uint32_t mask; int32_t i, j; for (i = 1; i < decoder->symbols; i++) { mask = 0x1; for (j = 0; j < i; j++) { if (mask & decoder->state[i]) { decoder->state[i] &= (~mask); exclusive_or(decoder->data[i], decoder->data[j], decoder->symbol_size); } mask <<= 1; } } uint8_t *mem = decoder->block; for (i = decoder->symbols - 1; i >= 0; i--) { memcpy(mem, decoder->data[i], decoder->symbol_size); mem += decoder->symbol_size; } }