6 n__entropy_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_entropy.h

Randomness/entropy metrics for byte samples (token-randomness analysis). More...

Structures

Name
struct N_ENTROPY_POS
per-position statistics across a set of equal-length samples
struct N_ENTROPY_BIT
per-bit statistics across a set of equal-length samples

Detailed Description

Randomness/entropy metrics for byte samples (token-randomness analysis).

Author: Castagnier Mickael

Version: 1.0

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __NILOREA_ENTROPY_HEADER
#define __NILOREA_ENTROPY_HEADER

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>


double n_entropy_shannon(const unsigned char* data, size_t len);

double n_entropy_monobit(const unsigned char* data, size_t len);

double n_entropy_chi_square(const unsigned char* data, size_t len);

double n_entropy_chi_square_p(double chi, size_t df);

typedef struct N_ENTROPY_POS {
    size_t distinct;   
    double shannon;    
    double chi_square; 
    double p_value;    
} N_ENTROPY_POS;

typedef struct N_ENTROPY_BIT {
    size_t ones;     
    double fraction; 
    double z;        
    double p_value;  
} N_ENTROPY_BIT;

size_t n_entropy_positions(const unsigned char* const* samples, size_t count, size_t sample_len, N_ENTROPY_POS* out, size_t max_out);

size_t n_entropy_bits(const unsigned char* const* samples, size_t count, size_t sample_len, N_ENTROPY_BIT* out, size_t max_out);

double n_entropy_runs_p(const unsigned char* data, size_t len);

size_t n_entropy_longest_run(const unsigned char* data, size_t len);


#ifdef __cplusplus
}
#endif

/* #ifndef __NILOREA_ENTROPY_HEADER */
#endif