├── docs ├── .nojekyll ├── objects.inv ├── source │ ├── _assets │ │ ├── theme.conf │ │ ├── layout.html │ │ ├── static │ │ │ └── file.svg │ │ ├── searchbox.html │ │ └── about.html │ ├── _static │ │ ├── lorenz_anim.gif │ │ ├── control-theory.jpeg │ │ ├── dynamical-system.jpeg │ │ ├── machine-diagram.jpeg │ │ ├── ncg-speed-benchmark.png │ │ ├── ncg-distribution-rankit.png │ │ └── libchaos.svg │ ├── conf.py │ ├── installation.rst │ ├── index.rst │ ├── generators.rst │ └── quickstart.rst ├── _static │ ├── up.png │ ├── down.png │ ├── file.png │ ├── plus.png │ ├── comment.png │ ├── minus.png │ ├── ajax-loader.gif │ ├── down-pressed.png │ ├── lorenz_anim.gif │ ├── up-pressed.png │ ├── comment-bright.png │ ├── comment-close.png │ ├── control-theory.jpeg │ ├── dynamical-system.jpeg │ ├── machine-diagram.jpeg │ ├── ncg-speed-benchmark.png │ ├── ncg-distribution-rankit.png │ ├── file.svg │ ├── opensearch.xml │ ├── libchaos.svg │ ├── pygments.css │ ├── doctools.js │ └── underscore.js ├── paper │ ├── document.pdf │ ├── figures │ │ ├── control-theory.jpeg │ │ ├── machine-diagram.jpeg │ │ ├── dynamical-system.jpeg │ │ ├── ncg-speed-benchmark.pdf │ │ ├── ncg-distribution-normal.pdf │ │ └── ncg-distribution-rankit.pdf │ └── bibliography.bib ├── _images │ ├── ncg-speed-benchmark.png │ └── ncg-distribution-rankit.png ├── _sources │ ├── installation.rst.txt │ ├── index.rst.txt │ ├── generators.rst.txt │ └── quickstart.rst.txt ├── genindex.html ├── search.html ├── searchindex.js ├── installation.html ├── Makefile └── index.html ├── .agignore ├── api └── .gitignore ├── .clang-format ├── cmake ├── benchmark_header.cc ├── googletest_header.cc └── cmake_uninstall.cmake.in ├── install.sh ├── .gitmodules ├── examples ├── truely_random.cc ├── interface_prng.cc ├── interface_chaos_machine.cc ├── long_period_urandom.cc ├── normal_dist_diagram.cc ├── file_checksum.cc ├── tests_testu01.cc ├── tests_library.cc ├── graph.R └── benchmark_graph.cc ├── .gitignore ├── .editorconfig ├── CHANGELOG.md ├── include ├── chaos │ ├── types.hh │ ├── generators │ │ ├── xorshift.hh │ │ ├── linear.hh │ │ ├── xorshf96.hh │ │ ├── kiss.hh │ │ ├── abyssinian.hh │ │ └── xoroshiro.hh │ ├── prng.hh │ ├── truely.hh │ ├── engines │ │ ├── empty.hh │ │ ├── ncg.hh │ │ └── xorring.hh │ ├── seed.hh │ ├── machine.hh │ ├── macros.hh │ └── analysis.hh └── chaos.h ├── src ├── engines │ ├── empty.cc │ ├── ncg.cc │ └── xorring.cc ├── chaosdeep.cpp ├── _sandbox.cpp ├── analysis.cc └── _testu01.cpp ├── ALGORITHMS ├── .travis.yml ├── tests ├── t_prng.cc ├── t_machine.cc ├── b_engines.cc ├── t_mixins.cc └── b_generators.cc ├── LICENSE └── CMakeLists.txt /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.agignore: -------------------------------------------------------------------------------- 1 | deps/* 2 | -------------------------------------------------------------------------------- /api/.gitignore: -------------------------------------------------------------------------------- 1 | !.gitignore 2 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: LLVM 2 | UseTab: ForIndentation 3 | TabWidth: 2 4 | -------------------------------------------------------------------------------- /docs/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/objects.inv -------------------------------------------------------------------------------- /docs/source/_assets/theme.conf: -------------------------------------------------------------------------------- 1 | [theme] 2 | inherit = basic 3 | stylesheet = master.css 4 | -------------------------------------------------------------------------------- /cmake/benchmark_header.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark/benchmark.h" 2 | BENCHMARK_MAIN(); // BUG FIX!!! 3 | -------------------------------------------------------------------------------- /docs/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/up.png -------------------------------------------------------------------------------- /docs/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/down.png -------------------------------------------------------------------------------- /docs/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/file.png -------------------------------------------------------------------------------- /docs/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/plus.png -------------------------------------------------------------------------------- /docs/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/comment.png -------------------------------------------------------------------------------- /docs/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/minus.png -------------------------------------------------------------------------------- /docs/paper/document.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/document.pdf -------------------------------------------------------------------------------- /docs/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/ajax-loader.gif -------------------------------------------------------------------------------- /docs/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/down-pressed.png -------------------------------------------------------------------------------- /docs/_static/lorenz_anim.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/lorenz_anim.gif -------------------------------------------------------------------------------- /docs/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/up-pressed.png -------------------------------------------------------------------------------- /docs/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/comment-bright.png -------------------------------------------------------------------------------- /docs/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/comment-close.png -------------------------------------------------------------------------------- /docs/_static/control-theory.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/control-theory.jpeg -------------------------------------------------------------------------------- /docs/_static/dynamical-system.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/dynamical-system.jpeg -------------------------------------------------------------------------------- /docs/_static/machine-diagram.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/machine-diagram.jpeg -------------------------------------------------------------------------------- /docs/_images/ncg-speed-benchmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_images/ncg-speed-benchmark.png -------------------------------------------------------------------------------- /docs/_static/ncg-speed-benchmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/ncg-speed-benchmark.png -------------------------------------------------------------------------------- /docs/source/_static/lorenz_anim.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/source/_static/lorenz_anim.gif -------------------------------------------------------------------------------- /docs/paper/figures/control-theory.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/figures/control-theory.jpeg -------------------------------------------------------------------------------- /docs/paper/figures/machine-diagram.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/figures/machine-diagram.jpeg -------------------------------------------------------------------------------- /docs/source/_static/control-theory.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/source/_static/control-theory.jpeg -------------------------------------------------------------------------------- /docs/_images/ncg-distribution-rankit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_images/ncg-distribution-rankit.png -------------------------------------------------------------------------------- /docs/_static/ncg-distribution-rankit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/_static/ncg-distribution-rankit.png -------------------------------------------------------------------------------- /docs/paper/figures/dynamical-system.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/figures/dynamical-system.jpeg -------------------------------------------------------------------------------- /docs/source/_static/dynamical-system.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/source/_static/dynamical-system.jpeg -------------------------------------------------------------------------------- /docs/source/_static/machine-diagram.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/source/_static/machine-diagram.jpeg -------------------------------------------------------------------------------- /docs/paper/figures/ncg-speed-benchmark.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/figures/ncg-speed-benchmark.pdf -------------------------------------------------------------------------------- /docs/source/_assets/layout.html: -------------------------------------------------------------------------------- 1 | {%- extends "basic/layout.html" %} 2 | {%- block relbar1 %}{% endblock %} 3 | {%- block relbar2 %}{% endblock %} 4 | -------------------------------------------------------------------------------- /docs/source/_static/ncg-speed-benchmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/source/_static/ncg-speed-benchmark.png -------------------------------------------------------------------------------- /docs/paper/figures/ncg-distribution-normal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/figures/ncg-distribution-normal.pdf -------------------------------------------------------------------------------- /docs/paper/figures/ncg-distribution-rankit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/paper/figures/ncg-distribution-rankit.pdf -------------------------------------------------------------------------------- /docs/source/_static/ncg-distribution-rankit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/maciejczyzewski/libchaos/HEAD/docs/source/_static/ncg-distribution-rankit.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | rm -rf CMakeCache.txt CMakeFiles 3 | mkdir -p build && cd build && cmake -DLIBCHAOS_ENABLE_TESTING=OFF .. \ 4 | && make && make install 5 | -------------------------------------------------------------------------------- /cmake/googletest_header.cc: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | int main(int argc, char **argv) { 3 | ::testing::InitGoogleTest(&argc, argv); 4 | return RUN_ALL_TESTS(); 5 | } 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "deps/benchmark"] 2 | path = deps/benchmark 3 | url = https://github.com/google/benchmark.git 4 | [submodule "deps/googletest"] 5 | path = deps/googletest 6 | url = https://github.com/google/googletest.git 7 | -------------------------------------------------------------------------------- /examples/truely_random.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | chaos::truely gen; 4 | 5 | int main(void) { 6 | for (size_t i = 0; i < 30; i += 3) 7 | printf("%p\t%p\t\%p\n", gen(), gen(), gen()); 8 | } 9 | -------------------------------------------------------------------------------- /docs/_static/file.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /docs/source/_assets/static/file.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # API 4 | api/js/ 5 | 6 | # Cmake build system 7 | CMakeCache.txt 8 | CMakeFiles/ 9 | build/ 10 | 11 | # Sphinx documentation 12 | docs/.doctrees/ 13 | docs/.buildinfo 14 | docs/build/ 15 | 16 | # Teax build environment 17 | .teax 18 | -------------------------------------------------------------------------------- /examples/interface_prng.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | CHAOS_PRNG_XOROSHIRO128PLUS prng; 4 | 5 | int main(void) { 6 | uint64_t a = 0x84242f96eca9c41d, b = 0xa3c65b8776f96855, c; 7 | 8 | // SEED 9 | prng.seed(a); 10 | prng << b; 11 | 12 | // NEXT 13 | prng.next(); 14 | c << prng; 15 | prng(); 16 | } 17 | -------------------------------------------------------------------------------- /examples/interface_chaos_machine.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | CHAOS_MACHINE_XORRING64 machine; 4 | 5 | int main(void) { 6 | uint64_t a = 0x84242f96eca9c41d, b = 0xa3c65b8776f96855, c; 7 | 8 | // PUSH 9 | machine.push(a); 10 | machine << b; 11 | 12 | // PULL 13 | machine.pull(); 14 | c << machine; 15 | machine(); 16 | } 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | ; Check http://editorconfig.org/ for more informations 2 | ; Top-most EditorConfig file 3 | root = true 4 | 5 | ; tab indentation 6 | [*] 7 | indent_style = tab 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | ; 4-column space indentation 12 | [*.md] 13 | indent_style = space 14 | indent_size = 4 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Release 0.0.1 (in development) 2 | ================================================================================ 3 | 4 | * Added Google Test and Google Benchmark (changes in .gitmodules). 5 | * Sphinx documentation initialized. First two sections: Installation, Quickstart 6 | * Git repository initialized. CMake skeleton and built environment. 7 | -------------------------------------------------------------------------------- /include/chaos/types.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_TYPES_HH 2 | #define CHAOS_TYPES_HH 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace chaos { //::chaos //////////////////////////////////////////////////// 9 | 10 | // future 11 | 12 | } //::chaos //////////////////////////////////////////////////////////////////// 13 | 14 | #endif // CHAOS_TYPES_HH 15 | -------------------------------------------------------------------------------- /examples/long_period_urandom.cc: -------------------------------------------------------------------------------- 1 | #include // library header 2 | #include 3 | 4 | // initialize chaos machine (64-bit version) 5 | CHAOS_MACHINE_XORRING64 machine; 6 | 7 | int main(void) { 8 | machine.set_space(100000); // 2^6400000 period length 9 | machine << 0x8a5cd789635d2dff; // initialize with seed 10 | while (true) 11 | putc_unlocked(machine.pull(), stdout); 12 | } 13 | -------------------------------------------------------------------------------- /docs/_static/opensearch.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | libchaos 4 | Search libchaos 0.0.1-dev documentation 5 | utf-8 6 | 8 | libchaos 0.0.1-dev documentation 9 | 10 | -------------------------------------------------------------------------------- /examples/normal_dist_diagram.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | CHAOS_MACHINE_NCG gen; 10 | 11 | int main(void) { 12 | std::normal_distribution<> d(5, 2); 13 | std::map hist; 14 | 15 | for (int n = 0; n < 5 * 10000; ++n) 16 | ++hist[std::round(d(gen))]; 17 | 18 | for (auto p : hist) 19 | std::cout << std::fixed << std::setprecision(1) << std::setw(2) << p.first 20 | << ' ' << std::string(p.second / 200, '*') << '\n'; 21 | } 22 | -------------------------------------------------------------------------------- /docs/source/_assets/searchbox.html: -------------------------------------------------------------------------------- 1 | {%- if pagename != "search" and builder != "singlehtml" %} 2 | 11 | 12 | {%- endif %} 13 | -------------------------------------------------------------------------------- /src/engines/empty.cc: -------------------------------------------------------------------------------- 1 | #include "chaos/engines/empty.hh" 2 | 3 | namespace chaos { //::chaos //////////////////////////////////////////////////// 4 | namespace engines { //::chaos::engines ///////////////////////////////////////// 5 | 6 | void empty::push(uint8_t block) { 7 | // what to do with 8-bit block in machine? 8 | (void)block; 9 | } 10 | 11 | uint8_t empty::pull(void) { 12 | // how-to pull 8-bit block from machine? 13 | return 0x0; 14 | } 15 | 16 | void empty::__reset(void) { 17 | // what should be cleared? 18 | } 19 | 20 | } //::chaos::engines /////////////////////////////////////////////////////////// 21 | } //::chaos //////////////////////////////////////////////////////////////////// 22 | -------------------------------------------------------------------------------- /src/chaosdeep.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | using namespace std; 9 | 10 | CHAOS_MACHINE_NCG mc; 11 | 12 | uint32_t checksum(std::ifstream &file) { 13 | CHAOS_MACHINE_NCG::size_push word; 14 | mc.reset(); 15 | while (file.read(reinterpret_cast(&word), sizeof(word))) 16 | mc.push(word); 17 | mc.push(word); 18 | } 19 | 20 | int main(int argc, char **argv) { 21 | mc.set_space(2); 22 | mc.set_time(1); 23 | 24 | ifstream file(argv[1]); 25 | checksum(file); // FIXME: just for testing... 26 | 27 | for (size_t i = 0; i < 32; i++) 28 | printf("%p\t%p\t%p\t%p\n", mc.pull(), mc.pull(), mc.pull(), mc.pull()); 29 | } 30 | -------------------------------------------------------------------------------- /docs/_static/libchaos.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/source/_static/libchaos.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /include/chaos.h: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_H 2 | #define CHAOS_H 3 | 4 | // modules 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | // adapters 11 | #include 12 | #include 13 | #include 14 | 15 | // engines 16 | #include 17 | #include 18 | #include 19 | 20 | // generators 21 | #include 22 | #include 23 | #include // FIXME: move to mixins 24 | #include 25 | #include // FIXME: move to mixins 26 | #include 27 | 28 | #endif // CHAOS_H 29 | -------------------------------------------------------------------------------- /ALGORITHMS: -------------------------------------------------------------------------------- 1 | ## CMs 2 | 3 | [XXX] Naive Czyzewski Generator (NCG) 4 | [XXX] Xorring32 / Xorring64 5 | [ ] Xorspace 6 | [ ] Lolxor 7 | 8 | ## PRNGs 9 | 10 | [XXX] Abyssinian 11 | [ ] Blum Blum Shub (BBS) 12 | [ ] Wichmann-Hill 13 | [ ] Complementary-multiply-with-carry 14 | [ ] Inversive congruential generator 15 | [ ] ISAAC 16 | [ ] Lagged Fibonacci generator 17 | [XXX] Linear congruential generator 18 | [ ] Linear feedback shift register 19 | [ ] Maximal periodic reciprocals 20 | [ ] Mersenne twister 21 | [ ] Multiply-with-carry 22 | [ ] Naor-Reingold Pseudorandom Function (NRPF) 23 | [ ] Park-Miller random number generator 24 | [ ] RC4 PRGA 25 | [ ] Well Equidistributed Long-period Linear (WELL) 26 | [XXX] Xorshift 27 | [XXX] Xoroshiro (plus & star) 28 | [XXX] KISS 29 | [ ] Rule 30 30 | [XXX] Xorshf96 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: cpp 4 | compiler: 5 | - g++ 6 | #- clang++ 7 | cache: 8 | apt: true 9 | addons: 10 | apt: 11 | sources: 12 | - ubuntu-toolchain-r-test 13 | # - llvm-toolchain-precise-3.8 14 | packages: 15 | - g++-4.8 16 | - gcc-4.8 17 | # - g++-6 18 | # - gcc-6 19 | # - clang-3.8 20 | # - valgrind 21 | before_install: 22 | - if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi 23 | #- if [ "$CXX" = "g++" ]; then export CXX="g++-6" CC="gcc-6"; fi 24 | #- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.8" CC="clang-3.8"; fi 25 | #install: 26 | # - ./travis.sh 27 | script: 28 | - dpkg-architecture; lscpu; env | sort 29 | - mkdir -p build && cd "$_" && cmake -DLIBCHAOS_ENABLE_TESTING=ON \ 30 | -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} .. && make 31 | - ./bchaos; ./tchaos 32 | -------------------------------------------------------------------------------- /docs/source/_assets/about.html: -------------------------------------------------------------------------------- 1 |

{{ _('About Libchaos') }}

2 | 3 |

An advanced library for randomization, hashing and statistical analysis.

4 | 5 |

#libchaos on freenode.net

6 | 7 |

release

8 | 9 |

{{ _('Useful Links') }}

10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # == BASICS ==================================================================== 4 | 5 | project = u'libchaos' 6 | release = u'0.0.1-dev' 7 | author = u'Maciej A. Czyzewski' 8 | 9 | # == SPHINX ==================================================================== 10 | 11 | extensions = ['sphinx.ext.todo','sphinx.ext.mathjax','sphinx.ext.githubpages'] 12 | templates_path = ['_templates'] 13 | source_suffix = '.rst' 14 | master_doc = 'index' 15 | copyright = u'2016, Libchaos Authors' 16 | version = release 17 | language = None 18 | exclude_patterns = [] 19 | pygments_style = 'friendly' 20 | todo_include_todos = True 21 | html_theme = "_assets" 22 | html_theme_path = ["."] 23 | html_sidebars = {'index':['about.html', 'sourcelink.html', 'searchbox.html'],'search':['about.html'],'**':['localtoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']} 24 | html_logo = 'libchaos.svg' 25 | html_static_path = ['_static'] 26 | html_use_smartypants = True 27 | html_use_opensearch = 'True' 28 | htmlhelp_basename = 'libchaosdoc' 29 | -------------------------------------------------------------------------------- /tests/t_prng.cc: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | /// prng /////////////////////////////////////////////////////////////////////// 9 | 10 | TEST(PRNG, T__CHAOS_PRNG__AdapterInitialization) { 11 | CHAOS_PRNG_KISS gen_1; 12 | 13 | for (size_t i = 0; i < 1000; i++) 14 | gen_1.next(); 15 | gen_1 << 0x112233; 16 | for (size_t i = 0; i < 1000; i++) 17 | gen_1.next(); 18 | 19 | CHAOS_PRNG_KISS gen_2; 20 | 21 | for (size_t i = 0; i < 1000; i++) 22 | gen_2.next(); 23 | gen_2 << 0x112233; 24 | for (size_t i = 0; i < 1000; i++) 25 | gen_2.next(); 26 | 27 | EXPECT_EQ(gen_1.next(), gen_2.next()); 28 | } 29 | 30 | TEST(PRNG, T__CHAOS_PRNG__AdapterAPI) { 31 | CHAOS_PRNG_KISS gen_1; 32 | CHAOS_PRNG_KISS gen_2; 33 | CHAOS_PRNG_KISS gen_3; 34 | CHAOS_PRNG_KISS gen_4; 35 | 36 | EXPECT_EQ(gen_1(), gen_2.next()); 37 | 38 | uint32_t tmp; 39 | gen_3 >> tmp; 40 | 41 | EXPECT_EQ(tmp, gen_4.next()); 42 | 43 | gen_1 << 0x11; 44 | gen_2.seed(0x11); 45 | 46 | EXPECT_EQ(gen_1(), gen_2()); 47 | } 48 | -------------------------------------------------------------------------------- /cmake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 3 | endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | string(REGEX REPLACE "\n" ";" files "${files}") 7 | foreach(file ${files}) 8 | message(STATUS "Uninstalling $ENV{DESTDIR}${file}") 9 | if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 10 | exec_program( 11 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 12 | OUTPUT_VARIABLE rm_out 13 | RETURN_VALUE rm_retval 14 | ) 15 | if(NOT "${rm_retval}" STREQUAL 0) 16 | message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") 17 | endif(NOT "${rm_retval}" STREQUAL 0) 18 | else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 19 | message(STATUS "File $ENV{DESTDIR}${file} does not exist.") 20 | endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") 21 | endforeach(file) 22 | -------------------------------------------------------------------------------- /include/chaos/generators/xorshift.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_GENERATORS_XORSHIFT_HH 2 | #define CHAOS_GENERATORS_XORSHIFT_HH 3 | 4 | #include "chaos/types.hh" 5 | 6 | namespace chaos { //::chaos //////////////////////////////////////////////////// 7 | namespace generators { //::chaos::generators /////////////////////////////////// 8 | 9 | template class xorshift { 10 | protected: 11 | utype _a, _b, _c, s; 12 | 13 | public: 14 | // metadata 15 | CHAOS_META_DEFINE("xorshift", "George Marsaglia"); 16 | 17 | // typename 18 | typedef utype size_seed; 19 | typedef utype size_next; 20 | 21 | explicit xorshift() : _a(a), _b(b), _c(c), s(2463534242) {} 22 | 23 | void seed(utype seed) { s = seed; } 24 | 25 | inline utype next() { 26 | s ^= (s << a); 27 | s ^= (s >> b); 28 | return (s ^= (s << c)); 29 | } 30 | }; 31 | 32 | } //::chaos::generators //////////////////////////////////////////////////////// 33 | } //::chaos //////////////////////////////////////////////////////////////////// 34 | 35 | // CHAOS_GENERATOR_REGISTER(XORSHIFT, chaos::generators::xorshift); 36 | 37 | #endif // CHAOS_GENERATORS_XORSHIFT_HH 38 | -------------------------------------------------------------------------------- /include/chaos/generators/linear.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_GENERATORS_LINEAR_HH 2 | #define CHAOS_GENERATORS_LINEAR_HH 3 | 4 | #include "chaos/types.hh" 5 | 6 | namespace chaos { //::chaos //////////////////////////////////////////////////// 7 | namespace generators { //::chaos::generators /////////////////////////////////// 8 | 9 | // http://courses.cse.tamu.edu/csce680/walker/lfsr_table.pdf 10 | 11 | template class lcg { 12 | protected: 13 | utype _a, _c, _m, s; 14 | 15 | public: 16 | // metadata 17 | CHAOS_META_DEFINE("LCG (Linear Congruential Generator)", "???"); 18 | 19 | // typename 20 | typedef utype size_seed; 21 | typedef utype size_next; 22 | 23 | explicit lcg() : _a(a), _c(c), _m(m), s(2147483648) {} 24 | 25 | void seed(utype seed) { s = seed; } 26 | 27 | inline utype next() { return (s = (_a * s + _c) % _m); } 28 | }; 29 | 30 | } //::chaos::generators //////////////////////////////////////////////////////// 31 | } //::chaos //////////////////////////////////////////////////////////////////// 32 | 33 | // CHAOS_GENERATOR_REGISTER(LCG, chaos::generators::lcg); 34 | 35 | #endif // CHAOS_GENERATORS_LINEAR_HH 36 | -------------------------------------------------------------------------------- /src/_sandbox.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int main() { 12 | std::random_device rd; 13 | 14 | CHAOS_MACHINE_NCG gen; 15 | CHAOS_PRNG_KISS prng; 16 | 17 | prng << 0x55; 18 | printf("\n"); 19 | 20 | chaos::truely x(100); 21 | 22 | for (size_t i = 0; i < 5000; i++) 23 | printf(">> %p\n", x()); 24 | 25 | printf("SEED: %p\n", rd()); 26 | 27 | gen << 0x44; 28 | gen.push(0x55); 29 | 30 | uint32_t a = 0x66; 31 | 32 | gen << a << 0x55; 33 | gen.push(a); 34 | 35 | uint32_t b, c; 36 | gen >> b >> c; 37 | 38 | printf("--> %p\n", b); 39 | printf("--> %p\n", c); 40 | printf("--> %p\n", gen()); 41 | printf("--> %p\n", gen.pull()); 42 | 43 | std::normal_distribution<> d(5, 2); 44 | 45 | std::map hist; 46 | 47 | for (int n = 0; n < 100000; ++n) 48 | ++hist[std::round(d(x))]; 49 | 50 | for (auto p : hist) 51 | std::cout << std::fixed << std::setprecision(1) << std::setw(2) << p.first 52 | << ' ' << std::string(p.second / 200, '*') << '\n'; 53 | } 54 | -------------------------------------------------------------------------------- /examples/file_checksum.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | CHAOS_MACHINE_XORRING64 gen; 9 | 10 | void READ(const char *filename) { 11 | std::ifstream ifs(filename); 12 | std::vector vec; 13 | 14 | vec.assign((std::istreambuf_iterator(ifs)), 15 | (std::istreambuf_iterator())); 16 | 17 | for (auto block : vec) 18 | gen.push(block); 19 | } 20 | 21 | int main(int argc, char *argv[]) { 22 | if (argc < 2) { 23 | printf("%s [filename]\n", argv[0]); 24 | return 1; 25 | } 26 | 27 | gen.set_time(4); 28 | gen.set_space(1000); // signed with secret key 29 | gen.set_key({0x84242f96eca9c41d, 0xa3c65b8776f96855, 0x5b34a39f070b5837, 30 | 0x4489affce4f31a1e, 0x2ffeeb0a48316f40, 0xdc2d9891fe68c022, 31 | 0x3659132bb12fea70, 0xaac17d8efa43cab8, 0xc4cb815590989b13, 32 | 0x5ee975283d71c93b, 0x691548c86c1bd540, 0x7910c41d10a1e6a5, 33 | 0x0b5fc64563b3e2a8, 0x047f7684e9fc949d, 0xb99181f2d8f685ca}); 34 | 35 | READ(argv[1]); 36 | 37 | for (size_t i = 0; i < 5 * 3; i += 3) 38 | printf("%p\t%p\t%p\n", gen.pull(), gen.pull(), gen.pull()); 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /include/chaos/prng.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_PRNG_HH 2 | #define CHAOS_PRNG_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "chaos/types.hh" 11 | 12 | namespace chaos { //::chaos //////////////////////////////////////////////////// 13 | 14 | template class prng : public virtual generator { 15 | public: 16 | // API 17 | constexpr static typename generator::size_next max(void) { 18 | return std::numeric_limits::max(); 19 | } 20 | constexpr static typename generator::size_next min(void) { 21 | return std::numeric_limits::lowest(); 22 | } 23 | friend prng &operator<<(prng &instance, // FIXME: with multi-blocks 24 | const typename generator::size_seed &block) { 25 | instance.seed(block); 26 | return instance; 27 | } 28 | friend prng &operator>>(prng &instance, 29 | typename generator::size_next &block) { 30 | block = instance.next(); 31 | return instance; 32 | } 33 | inline typename generator::size_next operator()(void) noexcept { 34 | return this->next(); 35 | } 36 | }; 37 | 38 | } //::chaos //////////////////////////////////////////////////////////////////// 39 | 40 | #endif // CHAOS_PRNG_HH 41 | -------------------------------------------------------------------------------- /include/chaos/generators/xorshf96.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_GENERATORS_XORSHF96_HH 2 | #define CHAOS_GENERATORS_XORSHF96_HH 3 | 4 | #include "chaos/types.hh" 5 | 6 | namespace chaos { //::chaos //////////////////////////////////////////////////// 7 | namespace generators { //::chaos::generators /////////////////////////////////// 8 | 9 | class xorshf96 { 10 | protected: 11 | static const uint32_t _x = 123456789, _y = 362436069, _z = 521288629; 12 | 13 | uint32_t x = _x, y = _y, z = _z; 14 | 15 | public: 16 | // metadata 17 | CHAOS_META_DEFINE("xorshf96", "George Marsaglia"); 18 | 19 | // typename 20 | typedef uint32_t size_seed; 21 | typedef uint32_t size_next; 22 | 23 | void seed(uint32_t seed_1, uint32_t seed_2, uint32_t seed_3) { 24 | x = seed_1; 25 | y = seed_2; 26 | z = seed_3; 27 | } 28 | 29 | void seed(uint32_t seed) { this->seed(seed - 1, seed + 1, seed * seed - 1); } 30 | 31 | inline uint32_t next(void) { 32 | uint32_t t; 33 | 34 | x ^= x << 16; 35 | x ^= x >> 5; 36 | x ^= x << 1; 37 | 38 | t = x; 39 | x = y; 40 | y = z; 41 | 42 | return z = t ^ x ^ y; 43 | } 44 | }; 45 | 46 | } //::chaos::generators //////////////////////////////////////////////////////// 47 | } //::chaos //////////////////////////////////////////////////////////////////// 48 | 49 | CHAOS_GENERATOR_REGISTER(XORSHF96, chaos::generators::xorshf96); 50 | 51 | #endif // CHAOS_GENERATORS_XORSHF96_HH 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Libchaos Authors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those 25 | of the authors and should not be interpreted as representing official policies, 26 | either expressed or implied, of the FreeBSD Project. 27 | -------------------------------------------------------------------------------- /include/chaos/generators/kiss.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_GENERATORS_KISS_HH 2 | #define CHAOS_GENERATORS_KISS_HH 3 | 4 | #include "chaos/types.hh" 5 | 6 | namespace chaos { //::chaos //////////////////////////////////////////////////// 7 | namespace generators { //::chaos::generators /////////////////////////////////// 8 | 9 | #define znew (z = 36969 * (z & 65535) + (z >> 16)) 10 | #define wnew (w = 18000 * (w & 65535) + (w >> 16)) 11 | #define MWC ((znew << 16) + wnew) 12 | #define SHR3 (jsr ^= (jsr << 17), jsr ^= (jsr >> 13), jsr ^= (jsr << 5)) 13 | #define CONG (jcong = 69069 * jcong + 1234567) 14 | #define KISS ((MWC ^ CONG) + SHR3) 15 | 16 | class kiss { 17 | protected: 18 | uint32_t w = 0x46500000, z = 0x90690000; 19 | uint32_t jsr = 16807, jcong = 48271; 20 | 21 | public: 22 | // metadata 23 | CHAOS_META_DEFINE("KISS (Keep It Simple Stupid)", "G. Marsaglia and A. Zaman"); 24 | 25 | // typename 26 | typedef uint32_t size_seed; 27 | typedef uint32_t size_next; 28 | 29 | void seed(uint32_t x, uint32_t y) { 30 | w = 0x46500000; 31 | z = 0x90690000; 32 | jsr = x; 33 | jcong = y; 34 | } 35 | 36 | void seed(uint32_t seed) { this->seed(seed, seed); } 37 | 38 | inline uint32_t next(void) { return KISS; } 39 | }; 40 | 41 | #undef znew 42 | #undef wnew 43 | #undef MWC 44 | #undef SHR3 45 | #undef CONG 46 | #undef KISS 47 | 48 | } //::chaos::generators //////////////////////////////////////////////////////// 49 | } //::chaos //////////////////////////////////////////////////////////////////// 50 | 51 | CHAOS_GENERATOR_REGISTER(KISS, chaos::generators::kiss); 52 | 53 | #endif // CHAOS_GENERATORS_KISS_HH 54 | -------------------------------------------------------------------------------- /docs/source/installation.rst: -------------------------------------------------------------------------------- 1 | .. _installation: 2 | 3 | Installation 4 | ============ 5 | 6 | Library needs C++ compiler that supports C++11. You will need *g++ 4.7* or newer to get started, so be sure to have an up-to-date compiler. 7 | 8 | .. todo:: 9 | Add this library to `Homebrew `_. Then simply ``$ brew install libchaos`` to install this package on OS X. This is future idea, when library will have stable version. 10 | 11 | Basic Installation 12 | ------------------ 13 | 14 | .. code-block:: console 15 | 16 | $ git clone git@github.com:maciejczyzewski/libchaos.git 17 | $ cd libchaos && ./install.sh 18 | 19 | Manual Installation 20 | ------------------- 21 | 22 | We welcome patches. If you plan to contribute a patch, you need to build libchaos and its own tests, which has further requirements: 23 | 24 | - `Google Test `_ and `Google Benchmark `_ (automatically downloaded as submodule) 25 | - `CMake `_ in version *2.8.7* (library uses `C++11 `_) 26 | 27 | .. code-block:: console 28 | 29 | $ git clone --recursive git@github.com:maciejczyzewski/libchaos.git 30 | $ mkdir libchaos/build && cd "$_" 31 | $ cmake -DLIBCHAOS_ENABLE_TESTING=ON .. 32 | $ make && make install 33 | 34 | Uninstalling Library 35 | -------------------- 36 | 37 | CMake creates a file called ``install_manifest.txt`` when executing the install target. This contains a list of all installed files. 38 | 39 | .. code-block:: console 40 | 41 | $ make uninstall # where is install_manifest.txt 42 | -------------------------------------------------------------------------------- /docs/_sources/installation.rst.txt: -------------------------------------------------------------------------------- 1 | .. _installation: 2 | 3 | Installation 4 | ============ 5 | 6 | Library needs C++ compiler that supports C++11. You will need *g++ 4.7* or newer to get started, so be sure to have an up-to-date compiler. 7 | 8 | .. todo:: 9 | Add this library to `Homebrew `_. Then simply ``$ brew install libchaos`` to install this package on OS X. This is future idea, when library will have stable version. 10 | 11 | Basic Installation 12 | ------------------ 13 | 14 | .. code-block:: console 15 | 16 | $ git clone git@github.com:maciejczyzewski/libchaos.git 17 | $ cd libchaos && ./install.sh 18 | 19 | Manual Installation 20 | ------------------- 21 | 22 | We welcome patches. If you plan to contribute a patch, you need to build libchaos and its own tests, which has further requirements: 23 | 24 | - `Google Test `_ and `Google Benchmark `_ (automatically downloaded as submodule) 25 | - `CMake `_ in version *2.8.7* (library uses `C++11 `_) 26 | 27 | .. code-block:: console 28 | 29 | $ git clone --recursive git@github.com:maciejczyzewski/libchaos.git 30 | $ mkdir libchaos/build && cd "$_" 31 | $ cmake -DLIBCHAOS_ENABLE_TESTING=ON .. 32 | $ make && make install 33 | 34 | Uninstalling Library 35 | -------------------- 36 | 37 | CMake creates a file called ``install_manifest.txt`` when executing the install target. This contains a list of all installed files. 38 | 39 | .. code-block:: console 40 | 41 | $ make uninstall # where is install_manifest.txt 42 | -------------------------------------------------------------------------------- /include/chaos/truely.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_TRUELY_HH 2 | #define CHAOS_TRUELY_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "chaos/types.hh" 11 | 12 | namespace chaos { //::chaos //////////////////////////////////////////////////// 13 | 14 | template class truely { 15 | private: 16 | // modules 17 | machine local_cm; 18 | device local_rd; 19 | 20 | // reseeding 21 | size_t current_checkpoint; 22 | size_t current_position; 23 | 24 | // settings 25 | size_t skip_blocks; 26 | 27 | public: 28 | // mechanism 29 | truely(size_t skip = 1000) { 30 | this->skip_blocks = skip; 31 | this->local_cm.push(this->local_rd()); 32 | // generate checkpoint 33 | this->reseed(); 34 | } 35 | inline void reseed(void) { 36 | if (this->current_position == this->current_checkpoint) { 37 | this->local_cm.push(this->local_rd()); 38 | // save new checkpoint 39 | this->current_checkpoint = 40 | (this->local_cm.pull() % this->skip_blocks) + 1; 41 | this->current_position = this->local_cm.pull() % this->current_checkpoint; 42 | } 43 | } 44 | 45 | // API 46 | constexpr static typename machine::size_pull max(void) { 47 | return std::numeric_limits::max(); 48 | } 49 | constexpr static typename machine::size_pull min(void) { 50 | return std::numeric_limits::lowest(); 51 | } 52 | inline typename machine::size_pull operator()(void) noexcept { 53 | this->reseed(); 54 | this->current_position++; 55 | // generate number 56 | return this->local_cm.pull(); 57 | } 58 | }; 59 | 60 | } //::chaos //////////////////////////////////////////////////////////////////// 61 | 62 | #endif // CHAOS_TRUELY_HH 63 | -------------------------------------------------------------------------------- /examples/tests_testu01.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" { 5 | #include "bbattery.h" 6 | #include "smarsa.h" 7 | #include "unif01.h" 8 | #include "util.h" 9 | } 10 | 11 | // Chaos Machines 12 | 13 | CHAOS_MACHINE_NCG x_0; 14 | CHAOS_MACHINE_XORRING64 x_1; 15 | 16 | // Pseudo-Random Number Generators 17 | 18 | chaos::generators::xorshift x_2; 19 | CHAOS_PRNG_ABYSSINIAN x_3; 20 | chaos::generators::lcg x_4; 21 | CHAOS_PRNG_KISS x_5; 22 | 23 | // Adapters (double is universal in this case) 24 | 25 | double UNIF01_NEXT_ADAPTER0() { return CHAOS_DOUBLE_U32(x_0.pull()); } 26 | double UNIF01_NEXT_ADAPTER1() { return CHAOS_DOUBLE_U64(x_1.pull()); } 27 | double UNIF01_NEXT_ADAPTER2() { return CHAOS_DOUBLE_U32(x_2.next()); } 28 | double UNIF01_NEXT_ADAPTER3() { return CHAOS_DOUBLE_U32(x_3.next()); } 29 | double UNIF01_NEXT_ADAPTER4() { return CHAOS_DOUBLE_U32(x_4.next()); } 30 | double UNIF01_NEXT_ADAPTER5() { return CHAOS_DOUBLE_U32(x_5.next()); } 31 | 32 | int main(void) { 33 | unif01_Gen *gen; 34 | gen = unif01_CreateExternGen01(CHAOS_META_NAME(CHAOS_MACHINE_XORRING64), 35 | UNIF01_NEXT_ADAPTER1); 36 | 37 | // smarsa_BirthdaySpacings(gen, NULL, 1, 1000, 0, 10000, 2, 1); 38 | // smarsa_BirthdaySpacings(gen, NULL, 1, 10000, 0, 1000000, 2, 1); 39 | 40 | // smarsa_BirthdaySpacings(gen, NULL, 3, 200000, 14, 256, 8, 1); 41 | // smarsa_BirthdaySpacings(gen, NULL, 3, 20000000, 14, 256, 8, 1); 42 | 43 | // bbattery_BlockAlphabit(gen, 1024 * 1024, 0, 8); 44 | // bbattery_Alphabit(gen, 1024 * 1024, 0, 8); 45 | 46 | // bbattery_FIPS_140_2(gen); 47 | // bbattery_Rabbit(gen, 10000000); 48 | bbattery_pseudoDIEHARD(gen); 49 | 50 | // bbattery_SmallCrush(gen); 51 | // bbattery_Crush(gen); 52 | // bbattery_BigCrush(gen); 53 | 54 | unif01_DeleteExternGenBits(gen); 55 | } 56 | -------------------------------------------------------------------------------- /include/chaos/engines/empty.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_ENGINES_EMPTY_HH 2 | #define CHAOS_ENGINES_EMPTY_HH 3 | 4 | #include 5 | #include 6 | 7 | #include "chaos/machine.hh" 8 | #include "chaos/macros.hh" 9 | #include "chaos/types.hh" 10 | 11 | namespace chaos { //::chaos //////////////////////////////////////////////////// 12 | namespace engines { //::chaos::engines ///////////////////////////////////////// 13 | 14 | class empty { 15 | public: 16 | // metadata 17 | CHAOS_META_DEFINE("Empty (Blank Template)", "Libchaos Authors"); 18 | 19 | // typename 20 | typedef uint8_t size_cell; 21 | typedef uint8_t size_push; 22 | typedef uint8_t size_pull; 23 | 24 | // interface 25 | void push(size_push); 26 | size_pull pull(void); 27 | 28 | // cleaning 29 | void __reset(void); 30 | 31 | // defaults 32 | const size_t __default_space = 4, __default_time = 2; 33 | const std::vector __default_key = {0x11, 0x22, 0x33, 0x44}; 34 | 35 | protected: 36 | // costs 37 | size_t __cost_space = 0, __cost_time = 0; 38 | 39 | // methods 40 | virtual void __set_key(std::vector value, size_t begin = 0) { 41 | // set starting variable 42 | std::copy(value.begin(), value.end(), this->buffer.begin() + begin); 43 | } 44 | virtual void __set_space(size_t value) { 45 | // set new space parameter 46 | this->__cost_space = value; 47 | // resize machine spaces if needed 48 | this->buffer.resize(this->__cost_space); 49 | } 50 | virtual void __set_time(size_t value) { 51 | // set new time parameter 52 | this->__cost_time = value; 53 | } 54 | 55 | private: 56 | // variables 57 | std::vector buffer; 58 | }; 59 | 60 | } //::chaos::engines /////////////////////////////////////////////////////////// 61 | } //::chaos //////////////////////////////////////////////////////////////////// 62 | 63 | CHAOS_ENGINE_REGISTER(EMPTY, chaos::engines::empty); 64 | 65 | #endif // CHAOS_ENGINES_EMPTY_HH 66 | -------------------------------------------------------------------------------- /src/analysis.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "chaos/analysis.hh" 8 | #include "chaos/macros.hh" 9 | #include "chaos/types.hh" 10 | 11 | namespace chaos { //::chaos //////////////////////////////////////////////////// 12 | 13 | double arithmetic_average(AP adapter) { 14 | int64_t a = 1000000 / 2; 15 | double s = 0; 16 | 17 | for (int64_t i = 0; i < a; i++) 18 | s += adapter(); 19 | 20 | double var = s / a; 21 | 22 | double min_exp = 0.5 - 0.005; 23 | double max_exp = 0.5 + 0.005; 24 | 25 | double p_value = ((100 * (var - min_exp)) / (max_exp - min_exp)) / 100; 26 | 27 | return p_value; 28 | } 29 | 30 | double dirichlet_probe(AP adapter) { 31 | int64_t a = 10000000 / 2; 32 | int64_t b = 10; 33 | 34 | std::vector s(b, 0); 35 | 36 | for (int64_t i = 0; i < a; i++) 37 | s[(int64_t)(adapter() * b)]++; 38 | 39 | int64_t min_e = *std::min_element(s.begin(), s.end()); 40 | int64_t max_e = *std::max_element(s.begin(), s.end()); 41 | 42 | double var = max_e - min_e; 43 | double exp = 2500; 44 | 45 | return var / exp; 46 | } 47 | 48 | double pi_calculus(AP adapter) { 49 | int64_t points = 100000 / 2; 50 | 51 | int64_t circle_area = 0; 52 | int64_t square_area = 0; 53 | 54 | for (int64_t i = 0; i < points; i++) { 55 | double x = adapter(); 56 | double y = adapter(); 57 | 58 | if ((x * x + y * y < 1) == 1) 59 | circle_area++; 60 | 61 | square_area++; 62 | } 63 | 64 | double min_exp = 3.1415 - 0.002; 65 | double max_exp = 3.1415 + 0.002; 66 | 67 | double var = 4.0 * circle_area / square_area; 68 | 69 | /* 70 | [min,max] --> [a,b] 71 | 72 | (b-a)(x - min) 73 | f(x) = -------------- + a 74 | max - min 75 | */ 76 | 77 | double p_value = ((100 * (var - min_exp)) / (max_exp - min_exp)) / 100; 78 | 79 | return p_value; 80 | } 81 | 82 | } //::chaos //////////////////////////////////////////////////////////////////// 83 | -------------------------------------------------------------------------------- /examples/tests_library.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // Chaos Machines 5 | 6 | CHAOS_MACHINE_NCG x_0; 7 | CHAOS_MACHINE_XORRING64 x_1; 8 | 9 | // Pseudo-Random Number Generators 10 | 11 | chaos::generators::xorshift x_2; 12 | CHAOS_PRNG_ABYSSINIAN x_3; 13 | chaos::generators::lcg x_4; 14 | CHAOS_PRNG_KISS x_5; 15 | 16 | // Adapters (double is universal in this case) 17 | 18 | double UNIF01_NEXT_ADAPTER0() { return CHAOS_DOUBLE_U32(x_0.pull()); } 19 | double UNIF01_NEXT_ADAPTER1() { return CHAOS_DOUBLE_U64(x_1.pull()); } 20 | double UNIF01_NEXT_ADAPTER2() { return CHAOS_DOUBLE_U32(x_2.next()); } 21 | double UNIF01_NEXT_ADAPTER3() { return CHAOS_DOUBLE_U32(x_3.next()); } 22 | double UNIF01_NEXT_ADAPTER4() { return CHAOS_DOUBLE_U32(x_4.next()); } 23 | double UNIF01_NEXT_ADAPTER5() { return CHAOS_DOUBLE_U32(x_5.next()); } 24 | 25 | int main(void) { 26 | std::cout << "=== XORRING ===================================================" 27 | << std::endl; 28 | chaos::analysis gen1(UNIF01_NEXT_ADAPTER1); 29 | gen1.raport(); 30 | std::cout << "=== XORSHIFT ==================================================" 31 | << std::endl; 32 | chaos::analysis gen2(UNIF01_NEXT_ADAPTER2); 33 | gen2.raport(); 34 | std::cout << "=== ABYSSINIAN ================================================" 35 | << std::endl; 36 | chaos::analysis gen3(UNIF01_NEXT_ADAPTER3); 37 | gen3.raport(); 38 | std::cout << "=== KISS ======================================================" 39 | << std::endl; 40 | chaos::analysis gen5(UNIF01_NEXT_ADAPTER5); 41 | gen5.raport(); 42 | std::cout << "=== LCG =======================================================" 43 | << std::endl; 44 | chaos::analysis gen4(UNIF01_NEXT_ADAPTER4); 45 | gen4.raport(); 46 | std::cout << "=== NCG =======================================================" 47 | << std::endl; 48 | chaos::analysis gen0(UNIF01_NEXT_ADAPTER0); 49 | gen0.raport(); 50 | } 51 | -------------------------------------------------------------------------------- /include/chaos/generators/abyssinian.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_GENERATORS_ABYSSINIAN_HH 2 | #define CHAOS_GENERATORS_ABYSSINIAN_HH 3 | 4 | #include "chaos/types.hh" 5 | 6 | namespace chaos { //::chaos //////////////////////////////////////////////////// 7 | namespace generators { //::chaos::generators /////////////////////////////////// 8 | 9 | // @1: typical next/round for abyssinian 10 | #define R(x, y) \ 11 | { \ 12 | x = (uint64_t)0xfffd21a7 * (uint32_t)x + (uint32_t)(x >> 32); \ 13 | y = (uint64_t)0xfffd1361 * (uint32_t)y + (uint32_t)(y >> 32); \ 14 | } 15 | 16 | class abyssinian { 17 | protected: 18 | static const uint64_t C1 = 0xff51afd7ed558ccdULL; 19 | static const uint64_t C2 = 0xc4ceb9fe1a85ec53ULL; 20 | 21 | uint64_t _x = C1, _y = C2; 22 | 23 | public: 24 | // metadata 25 | CHAOS_META_DEFINE("abyssinian", "???"); 26 | 27 | // typename 28 | typedef uint32_t size_seed; 29 | typedef uint32_t size_next; 30 | 31 | void seed(uint32_t x, uint32_t y) { 32 | x += y; 33 | y += x; 34 | 35 | uint64_t seed_x = 0x9368e53c2f6af274ULL ^ x; 36 | uint64_t seed_y = 0x586dcd208f7cd3fdULL ^ y; 37 | 38 | seed_x *= C1; 39 | seed_x ^= seed_x >> 33; 40 | seed_x *= C2; 41 | seed_x ^= seed_x >> 33; 42 | 43 | seed_y *= C1; 44 | seed_y ^= seed_y >> 33; 45 | seed_y *= C2; 46 | seed_y ^= seed_y >> 33; 47 | 48 | _x = seed_x; 49 | _y = seed_y; 50 | 51 | R(_x, _y); 52 | } 53 | 54 | void seed(uint32_t seed) { this->seed(seed, seed); } 55 | 56 | inline uint32_t next() { 57 | R(_x, _y); 58 | return CHAOS_RO_L32((uint32_t)_x, 7) + (uint32_t)_y; 59 | } 60 | }; 61 | 62 | #undef R // @1 63 | 64 | } //::chaos::generators //////////////////////////////////////////////////////// 65 | } //::chaos //////////////////////////////////////////////////////////////////// 66 | 67 | CHAOS_GENERATOR_REGISTER(ABYSSINIAN, chaos::generators::abyssinian); 68 | 69 | #endif // CHAOS_GENERATORS_ABYSSINIAN_HH 70 | -------------------------------------------------------------------------------- /include/chaos/engines/ncg.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_ENGINES_NCG_HH 2 | #define CHAOS_ENGINES_NCG_HH 3 | 4 | #include 5 | #include 6 | 7 | #include "chaos/machine.hh" 8 | #include "chaos/macros.hh" 9 | #include "chaos/types.hh" 10 | 11 | namespace chaos { //::chaos //////////////////////////////////////////////////// 12 | namespace engines { //::chaos::engines ///////////////////////////////////////// 13 | 14 | class ncg { 15 | public: 16 | // metadata 17 | CHAOS_META_DEFINE("NCG (Naive Czyzewski Generator)", "Maciej A. Czyzewski"); 18 | 19 | // typename 20 | typedef uint32_t size_cell; 21 | typedef uint32_t size_push; 22 | typedef uint32_t size_pull; 23 | 24 | // interface 25 | void push(size_push); 26 | size_pull pull(void); 27 | 28 | // cleaning 29 | void __reset(void); 30 | 31 | // defaults 32 | const size_t __default_space = 8, __default_time = 1; 33 | const std::vector __default_key = { 34 | 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 35 | 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501}; 36 | 37 | protected: 38 | // costs 39 | size_t __cost_space = 0, __cost_time = 0; 40 | 41 | // methods 42 | virtual void __set_key(std::vector value, size_t begin = 0) { 43 | // set starting variable 44 | for (std::vector::size_type i = begin, j = 0; j != value.size(); 45 | i++, j++) { 46 | // in NCG one hybrid system is build upon two cells in buffer 47 | this->buffer[i * 2] = value[j] >> 16; 48 | this->buffer[i * 2 + 1] = value[j] & 0xFFFF; 49 | } 50 | } 51 | virtual void __set_space(size_t value) { 52 | // set new space parameter 53 | this->__cost_space = value; 54 | // resize machine spaces if needed 55 | this->buffer.resize(this->__cost_space * 2); 56 | } 57 | virtual void __set_time(size_t value) { 58 | // set new time parameter 59 | this->__cost_time = value; 60 | } 61 | 62 | private: 63 | // spaces in algorithm 64 | std::vector buffer; 65 | uint16_t params[2] = {0}; 66 | // S - seed, I - increment 67 | uint32_t S, I; 68 | }; 69 | 70 | } //::chaos::engines /////////////////////////////////////////////////////////// 71 | } //::chaos //////////////////////////////////////////////////////////////////// 72 | 73 | CHAOS_ENGINE_REGISTER(NCG, chaos::engines::ncg); 74 | 75 | #endif // CHAOS_ENGINES_NCG_HH 76 | -------------------------------------------------------------------------------- /include/chaos/seed.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_SEED_HH 2 | #define CHAOS_SEED_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace chaos { //::chaos //////////////////////////////////////////////////// 12 | 13 | template 14 | std::vector triple_mask(std::vector buffer, 15 | std::vector key, 16 | std::vector mask) { 17 | std::vector seeded(mask.size()); 18 | if (buffer.size() == mask.size()) 19 | seeded = buffer; 20 | 21 | if (buffer.size() > mask.size()) 22 | buffer.resize(mask.size()), seeded = buffer; 23 | 24 | if (buffer.size() < mask.size()) { 25 | std::copy(buffer.begin(), buffer.end(), seeded.begin()); 26 | std::copy(mask.begin() + buffer.size(), mask.end(), 27 | seeded.begin() + buffer.size()); 28 | } 29 | 30 | if (key.size() != 0) { 31 | std::copy(key.begin(), key.end(), seeded.begin()); 32 | } 33 | 34 | return seeded; 35 | } 36 | 37 | template 38 | std::string password(std::string pass, std::string salt) { 39 | algorithm gen; 40 | 41 | std::vector key(salt.begin(), salt.end()); 42 | std::vector blc(pass.begin(), pass.end()); 43 | 44 | gen.set_key(key); 45 | gen.set_time(time); 46 | gen.set_space(space); 47 | 48 | for (auto block : blc) 49 | gen.push(block); 50 | 51 | std::ostringstream sign; 52 | sign << std::hex << std::uppercase << std::setfill('0'); 53 | std::vector vec(length, 0); 54 | 55 | std::generate(vec.begin(), vec.end(), [&gen] { return gen.pull(); }); 56 | 57 | for (int block : vec) 58 | sign << std::setw(2) << block; 59 | 60 | return (sign.str()).substr(0, length); 61 | } 62 | 63 | template 64 | std::vector keystream(std::vector key, size_t length) { 65 | std::vector vec(length, 0); 66 | 67 | // FIXME: make it as algorithm (below my draft -- M.A.C.) 68 | for (size_t i = 0; i < key.size(); i++) // @1 69 | key[i] = key[i] * 0x586dcd208f7cd3fdULL + 70 | key[key[i] % key.size()] * 0x9368e53c2f6af274ULL; 71 | vec[0] = key[0] + key[key.size() - 1]; // @2 72 | for (size_t i = 1; i < length; i++) // @3 73 | vec[i] = vec[i - 1] * 0x9368e53c2f6af274ULL + 74 | key[vec[i - 1] % key.size()] * 0x586dcd208f7cd3fdULL; 75 | 76 | return vec; 77 | } 78 | 79 | } //::chaos //////////////////////////////////////////////////////////////////// 80 | 81 | #endif // CHAOS_SEED_HH 82 | -------------------------------------------------------------------------------- /tests/t_machine.cc: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | /// machine //////////////////////////////////////////////////////////////////// 9 | 10 | TEST(MACHINE, T__CHAOS_MACHINE__AdapterInitialization) { 11 | CHAOS_MACHINE_XORRING64 gen_1; 12 | 13 | gen_1.set_time(4); 14 | gen_1.set_space(1000); 15 | gen_1.set_key({0x84242f96eca9c41d, 0xa3c65b8776f96855, 0x5b34a39f070b5837, 16 | 0x4489affce4f31a1e, 0x2ffeeb0a48316f40, 0xdc2d9891fe68c022, 17 | 0x3659132bb12fea70, 0xaac17d8efa43cab8, 0xc4cb815590989b13, 18 | 0x5ee975283d71c93b, 0x691548c86c1bd540, 0x7910c41d10a1e6a5, 19 | 0x0b5fc64563b3e2a8, 0x047f7684e9fc949d, 0xb99181f2d8f685ca}); 20 | gen_1 << 0x112233; 21 | 22 | CHAOS_MACHINE_XORRING64 gen_2; 23 | 24 | gen_2.set_time(4); 25 | gen_2.set_key({0x84242f96eca9c41d, 0xa3c65b8776f96855, 0x5b34a39f070b5837, 26 | 0x4489affce4f31a1e, 0x2ffeeb0a48316f40, 0xdc2d9891fe68c022, 27 | 0x3659132bb12fea70, 0xaac17d8efa43cab8, 0xc4cb815590989b13, 28 | 0x5ee975283d71c93b, 0x691548c86c1bd540, 0x7910c41d10a1e6a5, 29 | 0x0b5fc64563b3e2a8, 0x047f7684e9fc949d, 0xb99181f2d8f685ca}); 30 | gen_2.set_space(1000); 31 | gen_2 << 0x112233; 32 | 33 | EXPECT_EQ(gen_1.pull(), gen_2.pull()); 34 | } 35 | 36 | TEST(MACHINE, T__CHAOS_MACHINE__AdapterReset) { 37 | CHAOS_MACHINE_XORRING64 gen_1; 38 | 39 | gen_1.set_time(4); 40 | gen_1.set_space(1000); 41 | gen_1.set_key({0x84242f96eca9c41d, 0xa3c65b8776f96855, 0x5b34a39f070b5837, 42 | 0x4489affce4f31a1e, 0x2ffeeb0a48316f40, 0xdc2d9891fe68c022, 43 | 0x3659132bb12fea70, 0xaac17d8efa43cab8, 0xc4cb815590989b13, 44 | 0x5ee975283d71c93b, 0x691548c86c1bd540, 0x7910c41d10a1e6a5, 45 | 0x0b5fc64563b3e2a8, 0x047f7684e9fc949d, 0xb99181f2d8f685ca}); 46 | gen_1.set_space(10); 47 | gen_1 << 0x112233; 48 | 49 | for(size_t i = 0; i < 1000; i++) gen_1.pull(); 50 | uint64_t a = gen_1.pull(); 51 | gen_1.reset(); 52 | gen_1.set_space(100); 53 | 54 | EXPECT_NE(a, gen_1.pull()); 55 | 56 | gen_1.reset(); 57 | gen_1.set_space(10); 58 | gen_1 << 0x112233; 59 | for(size_t i = 0; i < 1000; i++) gen_1.pull(); 60 | 61 | EXPECT_EQ(a, gen_1.pull()); 62 | } 63 | 64 | TEST(MACHINE, T__CHAOS_MACHINE__AdapterAPI) { 65 | CHAOS_MACHINE_XORRING32 gen_1; 66 | CHAOS_MACHINE_XORRING32 gen_2; 67 | CHAOS_MACHINE_XORRING32 gen_3; 68 | CHAOS_MACHINE_XORRING32 gen_4; 69 | 70 | EXPECT_EQ(gen_1(), gen_2.pull()); 71 | 72 | uint32_t tmp; 73 | gen_3 >> tmp; 74 | 75 | EXPECT_EQ(tmp, gen_4.pull()); 76 | 77 | gen_1 << 0x11; 78 | gen_2.push(0x11); 79 | 80 | EXPECT_EQ(gen_1(), gen_2()); 81 | } 82 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | ========================================================= 2 | libchaos: randomization, hashing and statistical analysis 3 | ========================================================= 4 | 5 | .. |lorenz_3d| image:: _static/lorenz_3d.svg 6 | .. |lorenz_time| image:: _static/lorenz_time.svg 7 | 8 | Libchaos is a computing library written in C++ language to help with the development of software for scientific research. The library tries to be as general as possible, modern and easy-to-use. 9 | 10 | Project implements wide range of :ref:`chaos machines `, which presents the idea to create a universal scheme with modular design and customizable parameters, that can be applied where *randomness* and *sensitiveness* is needed. 11 | 12 | +---------------+---------------+ 13 | | |lorenz_3d| | |lorenz_time| | 14 | +---------------+---------------+ 15 | 16 | A summary of core features: 17 | 18 | .. Heuristic algorithms and data structures? (bloom filters?) 19 | .. Generating random/keys/data/testing? 20 | .. Pseudo-random number generators (the biggest list)? 21 | .. Implementation of design patterns (yarrow/pool)? 22 | .. JS/PYTHON bindings... 23 | 24 | .. container:: list-features 25 | 26 | - :ref:`Chaos machines ` 27 | 28 | - :ref:`Pseudo-random number generators ` 29 | 30 | - *Probability distributions* 31 | 32 | - *Randomness extractors* 33 | 34 | - *Statistical functions* 35 | 36 | - *Gnuplot utilities* 37 | 38 | --- 39 | 40 | **Getting Help** 41 | 42 | If you have questions about the library, please be sure to check out the `API documentation `_. If you still have questions, reach out to us on IRC or post a question on `StackOverflow `_ (with the ``libchaos`` tag). 43 | 44 | **Reporting Bugs** 45 | 46 | Please open a `GitHub Issue `_ and include as much information as possible. If possible, provide sample code that illustrates the problem you're seeing. If you're seeing a bug only on a specific repository, please provide a link to it if possible. 47 | 48 | *We ask that you not open a GitHub Issue for help, only for bug reports.* 49 | 50 | User's Guide 51 | ============ 52 | 53 | .. warning:: 54 | This project is at an early stage of development, every piece of hardware and software is in alpha version, if you are an adventurer this is a place for you! 55 | 56 | The list of core features is not ready. You need to dive into source code to find out what is working properly. If you have some ideas, feel free to contribute. 57 | 58 | This part of the documentation, which is mostly prose, begins with some background information about libchaos, then focuses on step-by-step instructions for working with libchaos. 59 | 60 | .. toctree:: 61 | :maxdepth: 2 62 | 63 | installation 64 | quickstart 65 | machines 66 | generators 67 | -------------------------------------------------------------------------------- /docs/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | ========================================================= 2 | libchaos: randomization, hashing and statistical analysis 3 | ========================================================= 4 | 5 | .. |lorenz_3d| image:: _static/lorenz_3d.svg 6 | .. |lorenz_time| image:: _static/lorenz_time.svg 7 | 8 | Libchaos is a computing library written in C++ language to help with the development of software for scientific research. The library tries to be as general as possible, modern and easy-to-use. 9 | 10 | Project implements wide range of :ref:`chaos machines `, which presents the idea to create a universal scheme with modular design and customizable parameters, that can be applied where *randomness* and *sensitiveness* is needed. 11 | 12 | +---------------+---------------+ 13 | | |lorenz_3d| | |lorenz_time| | 14 | +---------------+---------------+ 15 | 16 | A summary of core features: 17 | 18 | .. Heuristic algorithms and data structures? (bloom filters?) 19 | .. Generating random/keys/data/testing? 20 | .. Pseudo-random number generators (the biggest list)? 21 | .. Implementation of design patterns (yarrow/pool)? 22 | .. JS/PYTHON bindings... 23 | 24 | .. container:: list-features 25 | 26 | - :ref:`Chaos machines ` 27 | 28 | - :ref:`Pseudo-random number generators ` 29 | 30 | - *Probability distributions* 31 | 32 | - *Randomness extractors* 33 | 34 | - *Statistical functions* 35 | 36 | - *Gnuplot utilities* 37 | 38 | --- 39 | 40 | **Getting Help** 41 | 42 | If you have questions about the library, please be sure to check out the `API documentation `_. If you still have questions, reach out to us on IRC or post a question on `StackOverflow `_ (with the ``libchaos`` tag). 43 | 44 | **Reporting Bugs** 45 | 46 | Please open a `GitHub Issue `_ and include as much information as possible. If possible, provide sample code that illustrates the problem you're seeing. If you're seeing a bug only on a specific repository, please provide a link to it if possible. 47 | 48 | *We ask that you not open a GitHub Issue for help, only for bug reports.* 49 | 50 | User's Guide 51 | ============ 52 | 53 | .. warning:: 54 | This project is at an early stage of development, every piece of hardware and software is in alpha version, if you are an adventurer this is a place for you! 55 | 56 | The list of core features is not ready. You need to dive into source code to find out what is working properly. If you have some ideas, feel free to contribute. 57 | 58 | This part of the documentation, which is mostly prose, begins with some background information about libchaos, then focuses on step-by-step instructions for working with libchaos. 59 | 60 | .. toctree:: 61 | :maxdepth: 2 62 | 63 | installation 64 | quickstart 65 | machines 66 | generators 67 | -------------------------------------------------------------------------------- /include/chaos/generators/xoroshiro.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_GENERATORS_XOROSHIRO_HH 2 | #define CHAOS_GENERATORS_XOROSHIRO_HH 3 | 4 | #include 5 | 6 | #include "chaos/types.hh" 7 | 8 | namespace chaos { //::chaos //////////////////////////////////////////////////// 9 | namespace generators { //::chaos::generators /////////////////////////////////// 10 | 11 | // @1: default memory alloc. 12 | #define M(x, y, z) \ 13 | { std::memcpy(&x, &y, z * sizeof(uint64_t)); } 14 | 15 | class xoroshiro128plus { 16 | protected: 17 | uint64_t s[2], c[2] = {0x8a5cd789635d2dff, 0x121fd2155c472f96}; 18 | 19 | public: 20 | // metadata 21 | CHAOS_META_DEFINE("xoroshiro128+", "David Blackman and Sebastiano Vigna"); 22 | 23 | // typename 24 | typedef uint64_t size_seed; 25 | typedef uint64_t size_next; 26 | 27 | explicit xoroshiro128plus(void) { M(s, c, 2); }; 28 | 29 | void seed(uint64_t seed) { 30 | M(s, c, 2); 31 | s[0] = seed; 32 | } 33 | 34 | inline uint64_t next(void) { 35 | uint64_t s1 = s[0]; 36 | const uint64_t s0 = s[1]; 37 | const uint64_t result = s0 + s1; 38 | s[0] = s0; 39 | s1 ^= s1 << 23; // a 40 | s[1] = s1 ^ s0 ^ (s1 >> 18) ^ (s0 >> 5); // b, c 41 | return result; 42 | } 43 | }; 44 | 45 | //////////////////////////////////////////////////////////////////////////////// 46 | 47 | class xoroshiro1024star { 48 | protected: 49 | uint64_t s[16], 50 | c[16] = {0x84242f96eca9c41d, 0xa3c65b8776f96855, 0x5b34a39f070b5837, 51 | 0x4489affce4f31a1e, 0x2ffeeb0a48316f40, 0xdc2d9891fe68c022, 52 | 0x3659132bb12fea70, 0xaac17d8efa43cab8, 0xc4cb815590989b13, 53 | 0x5ee975283d71c93b, 0x691548c86c1bd540, 0x7910c41d10a1e6a5, 54 | 0x0b5fc64563b3e2a8, 0x047f7684e9fc949d, 0xb99181f2d8f685ca, 55 | 0x284600e3f30e38c3}; 56 | uint32_t p = 0; 57 | 58 | public: 59 | // metadata 60 | CHAOS_META_DEFINE("xoroshiro1024*", "David Blackman and Sebastiano Vigna"); 61 | 62 | // typename 63 | typedef uint64_t size_seed; 64 | typedef uint64_t size_next; 65 | 66 | explicit xoroshiro1024star(void) { M(s, c, 16); }; 67 | 68 | void seed(uint64_t seed) { 69 | M(s, c, 16); 70 | s[p = 0] = seed; 71 | } 72 | 73 | inline uint64_t next(void) { 74 | const uint64_t s0 = s[p]; 75 | uint64_t s1 = s[p = (p + 1) & 15]; 76 | s1 ^= s1 << 31; // a 77 | s[p] = s1 ^ s0 ^ (s1 >> 11) ^ (s0 >> 30); // b,c 78 | return s[p] * UINT64_C(1181783497276652981); 79 | } 80 | }; 81 | 82 | #undef M // @1 83 | 84 | } //::chaos::generators //////////////////////////////////////////////////////// 85 | } //::chaos //////////////////////////////////////////////////////////////////// 86 | 87 | CHAOS_GENERATOR_REGISTER(XOROSHIRO128PLUS, chaos::generators::xoroshiro128plus); 88 | CHAOS_GENERATOR_REGISTER(XOROSHIRO1024STAR, 89 | chaos::generators::xoroshiro1024star); 90 | 91 | #endif // CHAOS_GENERATORS_XOROSHIRO_HH 92 | -------------------------------------------------------------------------------- /src/_testu01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern "C" { 6 | #include "bbattery.h" 7 | #include "smarsa.h" 8 | #include "unif01.h" 9 | #include "util.h" 10 | } 11 | 12 | CHAOS_MACHINE_NCG x_0; 13 | CHAOS_MACHINE_XORRING64 x_5; 14 | 15 | chaos::generators::xorshift x_1; 16 | CHAOS_PRNG_ABYSSINIAN x_2; 17 | chaos::generators::lcg x_4; 18 | CHAOS_PRNG_KISS x_3; 19 | 20 | //////////////////////////////////////////////////////////////////////////////// 21 | 22 | double UNIF01_NEXT_ADAPTER0() { return CHAOS_DOUBLE_U32(x_0.pull()); } 23 | double UNIF01_NEXT_ADAPTER1() { return CHAOS_DOUBLE_U32(x_1.next()); } 24 | double UNIF01_NEXT_ADAPTER2() { return CHAOS_DOUBLE_U32(x_2.next()); } 25 | double UNIF01_NEXT_ADAPTER3() { return CHAOS_DOUBLE_U32(x_3.next()); } 26 | double UNIF01_NEXT_ADAPTER4() { return CHAOS_DOUBLE_U32(x_4.next()); } 27 | double UNIF01_NEXT_ADAPTER5() { return CHAOS_DOUBLE_U64(x_5.pull()); } 28 | 29 | int main() { 30 | unif01_Gen *gen; 31 | gen = unif01_CreateExternGen01(CHAOS_META_NAME(CHAOS_MACHINE_XORRING64), 32 | UNIF01_NEXT_ADAPTER5); 33 | 34 | ////////////////////////////////////////////////////////////////////////////// 35 | /* 36 | std::cout << "=== XORRING ===================================================" 37 | << std::endl; 38 | chaos::analysis gen5(UNIF01_NEXT_ADAPTER5); 39 | gen5.raport(); 40 | std::cout << "=== XORSHIFT ==================================================" 41 | << std::endl; 42 | chaos::analysis gen1(UNIF01_NEXT_ADAPTER1); 43 | gen1.raport(); 44 | std::cout << "=== ABYSSINIAN ================================================" 45 | << std::endl; 46 | chaos::analysis gen2(UNIF01_NEXT_ADAPTER2); 47 | gen2.raport(); 48 | std::cout << "=== KISS ======================================================" 49 | << std::endl; 50 | chaos::analysis gen3(UNIF01_NEXT_ADAPTER3); 51 | gen3.raport(); 52 | std::cout << "=== LCG =======================================================" 53 | << std::endl; 54 | chaos::analysis gen4(UNIF01_NEXT_ADAPTER4); 55 | gen4.raport(); 56 | std::cout << "=== NCG =======================================================" 57 | << std::endl; 58 | chaos::analysis gen0(UNIF01_NEXT_ADAPTER0); 59 | gen0.raport(); 60 | */ 61 | ////////////////////////////////////////////////////////////////////////////// 62 | 63 | // smarsa_BirthdaySpacings(gen, NULL, 1, 1000, 0, 10000, 2, 1); 64 | // smarsa_BirthdaySpacings(gen, NULL, 1, 10000, 0, 1000000, 2, 1); 65 | 66 | // smarsa_BirthdaySpacings(gen, NULL, 3, 200000, 14, 256, 8, 1); 67 | // smarsa_BirthdaySpacings(gen, NULL, 3, 20000000, 14, 256, 8, 1); 68 | 69 | // bbattery_BlockAlphabit(gen, 1024 * 1024, 0, 8); 70 | // bbattery_Alphabit(gen, 1024 * 1024, 0, 8); 71 | 72 | // bbattery_FIPS_140_2(gen); 73 | // bbattery_Rabbit(gen, 10000000); 74 | bbattery_pseudoDIEHARD(gen); 75 | 76 | // bbattery_SmallCrush(gen); 77 | // bbattery_Crush(gen); 78 | // bbattery_BigCrush(gen); 79 | 80 | ////////////////////////////////////////////////////////////////////////////// 81 | 82 | unif01_DeleteExternGenBits(gen); 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /src/engines/ncg.cc: -------------------------------------------------------------------------------- 1 | /* NCG written in 2015 by Maciej A. Czyzewski 2 | To the extent possible under law, the author has dedicated all copyright 3 | and related and neighboring rights to this software to the public domain 4 | worldwide. This software is distributed without any warranty. 5 | See . */ 6 | 7 | #include "chaos/engines/ncg.hh" 8 | 9 | namespace chaos { //::chaos //////////////////////////////////////////////////// 10 | namespace engines { //::chaos::engines ///////////////////////////////////////// 11 | 12 | // @1: abbreviation for getting values from the tape 13 | #define M(i) ((i) % (this->__cost_space * 2)) 14 | 15 | // @2: bits rotation formula (with untypical shift) 16 | #define R(n, r) \ 17 | ((uint32_t)((uint32_t)(n) << (r)) | (uint32_t)((uint32_t)(n) >> (16 - (r)))) 18 | 19 | void ncg::push(uint32_t block) { 20 | // preparation 21 | const uint32_t S0 = block + 1, S1 = block - 1; 22 | S = block, I = block * 0x3C6EF35F; 23 | 24 | for (size_t i = 0; i < this->__cost_space * 2; i += 2) { 25 | // reinforcement & finalization [@1] 26 | const uint16_t b0 = 27 | buffer[M(i + 0)] ^ (((I * S0) ^ S) >> 16) ^ ((I * S1) ^ S); 28 | buffer[M(i + 0)] = b0, 29 | I ^= ((buffer[M(I - 1)] + b0) << 16) ^ (buffer[M(I + 1)] - b0); 30 | 31 | // reinforcement & finalization [@2] 32 | const uint16_t b1 = 33 | buffer[M(i + 1)] ^ (((I * S0) ^ S) >> 16) ^ ((I * S1) ^ S); 34 | buffer[M(i + 1)] = b1, 35 | I ^= ((buffer[M(I - 1)] + b1) << 16) ^ (buffer[M(I + 1)] - b1); 36 | } 37 | } 38 | 39 | uint32_t ncg::pull(void) { 40 | // variables 41 | const uint16_t a = buffer[M(I + 0)], b = buffer[M(I + 1)]; 42 | 43 | // initialization 44 | uint32_t X = (a + I) * (b - S); 45 | 46 | // chaos 47 | const uint16_t Y = 48 | (buffer[M(X - b)] << (a % 9)) ^ (buffer[M(X + a)] >> (b % 9)); 49 | 50 | // rounds 51 | for (size_t i = 0; i < this->__cost_time * 2; i += 2) { 52 | const uint16_t b0 = buffer[M(I + i - 2)], b1 = buffer[M(I + i + 2)]; 53 | 54 | // absorption 55 | params[0] ^= b0, params[1] ^= b1; 56 | 57 | // mixing + modification 58 | params[0] ^= (params[1] ^= R(Y, params[0] % 17)); 59 | buffer[M(I + i - 2)] = b0 - (params[1] += (X & params[0])); 60 | params[1] += (params[0] += R(X, params[1] % 17)); 61 | buffer[M(I + i + 2)] = b1 + (params[0] += (Y & params[1])); 62 | } 63 | 64 | // transformation 65 | buffer[M(I + 0)] = // chaotic map 66 | R(params[0], X % 17) ^ R(params[1], X % 17) ^ (X & a) ^ (Y & b); 67 | buffer[M(I + 1)] = (b >> 1) ^ (-(b & 1u) & 0xB400u); // LFSR 68 | 69 | // finalization 70 | X += params[0] ^ (b << 8) ^ (params[1] << 16) ^ (a & 0xFF) ^ ((a >> 8) << 24); 71 | 72 | // cleaning 73 | params[0] = params[1] = 0xFFFF; 74 | 75 | // increment 76 | I += 2; 77 | 78 | return X; 79 | } 80 | 81 | void ncg::__reset(void) { 82 | // clear parameters space 83 | params[0] = params[1] = 0; 84 | S = 0x19660D00; // seed is not defined (prime) 85 | I = 0x3C6EF35F; // increment should be set 86 | } 87 | 88 | #undef M // @1 89 | #undef R // @2 90 | 91 | } //::chaos::engines /////////////////////////////////////////////////////////// 92 | } //::chaos //////////////////////////////////////////////////////////////////// 93 | -------------------------------------------------------------------------------- /examples/graph.R: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env Rscript 2 | 3 | library(ggplot2) 4 | library(scales) 5 | library(sitools) 6 | library(RColorBrewer) 7 | 8 | p <- ggplot(legend = TRUE) + ggtitle('MCs & PRNGs benchmark') + 9 | scale_y_continuous(labels = comma, limits = c(0, 1.1 * 50000)) + 10 | scale_x_continuous(labels = comma) + 11 | xlab("Received Bytes") + ylab("Lookup Time") 12 | 13 | file_list = list.files(pattern = "*.csv") 14 | 15 | stl_data <- data.frame(algorithm=character(), 16 | bytes=integer(), 17 | rate=double(), 18 | stringsAsFactors=FALSE) 19 | lib_cm_data <- data.frame(algorithm=character(), 20 | bytes=integer(), 21 | rate=double(), 22 | stringsAsFactors=FALSE) 23 | lib_prng_data <- data.frame(algorithm=character(), 24 | bytes=integer(), 25 | rate=double(), 26 | stringsAsFactors=FALSE) 27 | 28 | for (i in 1:length(file_list)) { 29 | df <- read.csv(file_list[i], head = TRUE, sep = ",") 30 | print(ggplot(df, aes(x = bytes, y = rate)) + geom_point()) # [DEBUG] 31 | algorithm = gsub(".csv", "", file_list[i]) 32 | print(algorithm) 33 | df$algorithm <- rep(algorithm, nrow(df)) 34 | if (startsWith(algorithm, "STL")) { 35 | stl_data <<- rbind(stl_data, df) 36 | } 37 | if (startsWith(algorithm, "CHAOS_MACHINE")) { 38 | lib_cm_data <<- rbind(lib_cm_data, df) 39 | } 40 | if (startsWith(algorithm, "CHAOS_PRNG")) { 41 | lib_prng_data <<- rbind(lib_prng_data, df) 42 | } 43 | } 44 | 45 | stl_data <- stl_data[with(stl_data, order(-rate)), ] 46 | rownames(stl_data) <- 1:nrow(stl_data) 47 | 48 | lib_cm_data <- lib_cm_data[with(lib_cm_data, order(-rate)), ] 49 | rownames(lib_cm_data) <- 1:nrow(lib_cm_data) 50 | 51 | lib_prng_data <- lib_prng_data[with(lib_prng_data, order(-rate)), ] 52 | rownames(lib_prng_data) <- 1:nrow(lib_prng_data) 53 | 54 | p <- p + geom_smooth(data = stl_data, 55 | mapping = aes(x = bytes, y = rate, 56 | colour = algorithm), 57 | method = "loess", span = 0.20, se = FALSE) 58 | p <- p + geom_smooth(data = lib_cm_data, 59 | mapping = aes(x = bytes, y = rate, 60 | colour = algorithm), 61 | linetype = "dashed", 62 | method = "loess", span = 0.20, se = FALSE) 63 | p <- p + geom_smooth(data = lib_prng_data, 64 | mapping = aes(x = bytes, y = rate, 65 | colour = algorithm), 66 | method = "loess", span = 0.20, se = FALSE) 67 | 68 | # DEBUG [number of colors] 69 | my_colors = c(brewer.pal(6, "Reds"), 70 | c("royalblue", "royalblue2", "royalblue4"), 71 | brewer.pal(5, "Greens")) 72 | my_headers = c(unique(stl_data$algorithm), 73 | unique(lib_cm_data$algorithm), 74 | unique(lib_prng_data$algorithm)) 75 | 76 | p <- p + theme(legend.position = "bottom") + 77 | theme(legend.title = element_blank()) + 78 | theme(legend.key = element_rect(size = 5)) + 79 | theme(legend.key.size = unit(1.5, 'lines')) 80 | 81 | p <- p + scale_colour_manual( 82 | limits = my_headers, 83 | breaks = my_headers, 84 | values = my_colors) 85 | 86 | ggsave(p, file = "benchmark.svg", width = 12, height = 5) 87 | -------------------------------------------------------------------------------- /include/chaos/engines/xorring.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_ENGINES_XORRING_HH 2 | #define CHAOS_ENGINES_XORRING_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "chaos/machine.hh" 10 | #include "chaos/macros.hh" 11 | #include "chaos/seed.hh" 12 | #include "chaos/types.hh" 13 | 14 | #include "chaos/generators/xorshift.hh" 15 | #include "chaos/prng.hh" 16 | 17 | namespace chaos { //::chaos //////////////////////////////////////////////////// 18 | namespace engines { //::chaos::engines ///////////////////////////////////////// 19 | 20 | class xorring32 { 21 | public: 22 | // metadata 23 | CHAOS_META_DEFINE("xorring32", "Maciej A. Czyzewski"); 24 | 25 | // typename 26 | typedef uint32_t size_cell; 27 | typedef uint32_t size_push; 28 | typedef uint32_t size_pull; 29 | 30 | // interface 31 | void push(size_push); 32 | size_pull pull(void); 33 | 34 | // cleaning 35 | void __reset(void); 36 | 37 | // defaults 38 | const size_t __default_space = 5, __default_time = 1; 39 | const std::vector __default_key = { 40 | 0xbbe112c5, 0xa8354e67, 0x22c32ce1, 0xe5980656, 0xda498845}; 41 | 42 | protected: 43 | // costs 44 | size_t __cost_space = 0, __cost_time = 0; 45 | 46 | // methods 47 | virtual void __set_key(std::vector value, size_t begin = 0) { 48 | // set starting variable 49 | std::copy(value.begin(), value.end(), this->buffer.begin() + begin); 50 | } 51 | virtual void __set_space(size_t value) { 52 | // set new space parameter 53 | this->__cost_space = value; 54 | // resize machine spaces if needed 55 | this->buffer.resize(this->__cost_space); 56 | } 57 | virtual void __set_time(size_t value) { 58 | // set new time parameter 59 | this->__cost_time = value; 60 | } 61 | 62 | private: 63 | // variables 64 | std::deque buffer; 65 | }; 66 | 67 | class xorring64 { 68 | public: 69 | // metadata 70 | CHAOS_META_DEFINE("xorring64", "Maciej A. Czyzewski"); 71 | 72 | // typename 73 | typedef uint64_t size_cell; 74 | typedef uint64_t size_push; 75 | typedef uint64_t size_pull; 76 | 77 | // interface 78 | void push(size_push); 79 | size_pull pull(void); 80 | 81 | // cleaning 82 | void __reset(void); 83 | 84 | // defaults 85 | const size_t __default_space = 5, __default_time = 1; 86 | const std::vector __default_key = { 87 | 0x75a3d46301ec2524, 0x4d4e9485ccf00d9c, 0x29649ef6dbdd5078, 88 | 0x13f10a775c5fb54f, 0xea41d5a3bb1545bb}; 89 | 90 | protected: 91 | // costs 92 | size_t __cost_space = 0, __cost_time = 0; 93 | 94 | // methods 95 | virtual void __set_key(std::vector value, size_t begin = 0) { 96 | // set starting variable 97 | std::copy(value.begin(), value.end(), this->buffer.begin() + begin); 98 | } 99 | virtual void __set_space(size_t value) { 100 | // set new space parameter 101 | this->__cost_space = value; 102 | // resize machine spaces if needed 103 | this->buffer.resize(this->__cost_space); 104 | } 105 | virtual void __set_time(size_t value) { 106 | // set new time parameter 107 | this->__cost_time = value; 108 | } 109 | 110 | private: 111 | // variables 112 | std::deque buffer; 113 | }; 114 | 115 | } //::chaos::engines /////////////////////////////////////////////////////////// 116 | } //::chaos //////////////////////////////////////////////////////////////////// 117 | 118 | CHAOS_ENGINE_REGISTER(XORRING32, chaos::engines::xorring32); 119 | CHAOS_ENGINE_REGISTER(XORRING64, chaos::engines::xorring64); 120 | 121 | #endif // CHAOS_ENGINES_XORRING_HH 122 | -------------------------------------------------------------------------------- /docs/paper/bibliography.bib: -------------------------------------------------------------------------------- 1 | @BOOK{Knuth1973, 2 | author = "Donald E. Knuth", 3 | title = "Seminumerical Algorithms", 4 | series = "The Art of Computer Programming", 5 | edition = "Second", 6 | year = "1973", 7 | type = "Section", 8 | chapter = "3", 9 | volume = 2 10 | } 11 | 12 | @BOOK{Opac-b1101628, 13 | title = "Complex systems : chaos and beyond a constructive approach with applications in life sciences", 14 | author = "Kaneko, Kunihiko and Tsuda, Ichiro", 15 | series = "Physics and astronomy online library", 16 | publisher = "Springer", 17 | address = "Berlin, London", 18 | url = "http://opac.inria.fr/record=b1101628", 19 | isbn = "3-540-67202-8", 20 | note = "Translated from the Japanese", 21 | year = 2001 22 | } 23 | 24 | @INPROCEEDINGS{Viana2001, 25 | author = {Marcelo Viana}, 26 | title = {Dynamical Systems: Moving into the Next Century}, 27 | booktitle = {Mathematics Unlimited: 2001 and Beyond}, 28 | year = {2001}, 29 | pages = {116--7}, 30 | publisher = {Springer} 31 | } 32 | 33 | @INPROCEEDINGS{Devaney1984, 34 | author = {Robert L. Devaney}, 35 | title = {A Piecewise Linear Model for the Zones of Instability of an Area Preserving Map.}, 36 | year = {1984}, 37 | pages = {387-393}, 38 | booktitle = {Physica}, 39 | volume = 10 40 | } 41 | 42 | @ARTICLE{2014JChPh.140c4105T, 43 | author = {{Thomson}, C. and {Lue}, L. and {Bannerman}, M.~N.}, 44 | title = "{Mapping continuous potentials to discrete forms}", 45 | archivePrefix = "arXiv", 46 | eprint = {1309.7292}, 47 | primaryClass = "cond-mat.soft", 48 | year = 2014, 49 | month = jan, 50 | volume = 140, 51 | number = 3, 52 | eid = {034105}, 53 | pages = {034105}, 54 | doi = {10.1063/1.4861669}, 55 | adsurl = {http://adsabs.harvard.edu/abs/2014JChPh.140c4105T}, 56 | adsnote = {Provided by the SAO/NASA Astrophysics Data System} 57 | } 58 | 59 | @ARTICLE{2006math......3133H, 60 | author = {{Harrivel}, D.}, 61 | title = "{Butcher series and control theory}", 62 | journal = {ArXiv Mathematics e-prints}, 63 | eprint = {math/0603133}, 64 | keywords = {Mathematics - Optimization and Control, Mathematics - Classical Analysis and ODEs, 34H05, 93C10, 93C15, 41A58, 49J40, 93B03}, 65 | year = 2006, 66 | month = mar, 67 | adsurl = {http://adsabs.harvard.edu/abs/2006math......3133H}, 68 | adsnote = {Provided by the SAO/NASA Astrophysics Data System} 69 | } 70 | 71 | @ARTICLE{2013arXiv1310.1615W, 72 | author = {{Werndl}, C.}, 73 | title = "{Are Deterministic Descriptions And Indeterministic Descriptions Observationally Equivalent?}", 74 | journal = {ArXiv e-prints}, 75 | archivePrefix = "arXiv", 76 | eprint = {1310.1615}, 77 | primaryClass = "math.DS", 78 | keywords = {Mathematics - Dynamical Systems, Nonlinear Sciences - Chaotic Dynamics, Physics - Classical Physics, Physics - History and Philosophy of Physics}, 79 | year = 2013, 80 | month = oct, 81 | adsurl = {http://adsabs.harvard.edu/abs/2013arXiv1310.1615W}, 82 | adsnote = {Provided by the SAO/NASA Astrophysics Data System} 83 | } 84 | 85 | @ARTICLE{2014arXiv1412.7407O, 86 | author = {{{\"O}mer}, B. and {Pacher}, C.}, 87 | title = "{Saving fractional bits: A practical entropy efficient code for fair die rolls}", 88 | journal = {ArXiv e-prints}, 89 | archivePrefix = "arXiv", 90 | eprint = {1412.7407}, 91 | primaryClass = "cs.IT", 92 | keywords = {Computer Science - Information Theory}, 93 | year = 2014, 94 | month = dec, 95 | adsurl = {http://adsabs.harvard.edu/abs/2014arXiv1412.7407O}, 96 | adsnote = {Provided by the SAO/NASA Astrophysics Data System} 97 | } 98 | -------------------------------------------------------------------------------- /include/chaos/machine.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_MACHINE_HH 2 | #define CHAOS_MACHINE_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "chaos/macros.hh" 10 | #include "chaos/seed.hh" 11 | #include "chaos/types.hh" 12 | 13 | namespace chaos { //::chaos //////////////////////////////////////////////////// 14 | 15 | #define CHAOS_BUFFER_MASK(key, length) \ 16 | this->__set_key( \ 17 | chaos::keystream(key, length - key.size()), \ 18 | key.size()); 19 | 20 | template class machine : public virtual engine { 21 | private: 22 | // memory 23 | std::vector key; 24 | 25 | public: 26 | explicit machine(std::vector key = {}); 27 | 28 | // configuration 29 | void set_key(std::vector); 30 | void set_space(size_t); 31 | void set_time(size_t); 32 | 33 | // cleaning 34 | void reset(void); 35 | 36 | // API 37 | constexpr static typename engine::size_pull max(void) { 38 | return std::numeric_limits::max(); 39 | } 40 | constexpr static typename engine::size_pull min(void) { 41 | return std::numeric_limits::lowest(); 42 | } 43 | friend machine &operator<<(machine &instance, 44 | const typename engine::size_push &block) { 45 | instance.push(block); 46 | return instance; 47 | } 48 | friend machine &operator>>(machine &instance, 49 | typename engine::size_pull &block) { 50 | block = instance.pull(); 51 | return instance; 52 | } 53 | inline typename engine::size_pull operator()(void) noexcept { 54 | return this->pull(); 55 | } 56 | }; 57 | 58 | template 59 | machine::machine(std::vector key) { 60 | // check if there is a initial secret key 61 | this->key = key.size() != 0 ? key : this->__default_key; 62 | // configure space and time parameter 63 | this->set_space(this->key.size()); 64 | this->set_time(this->__default_time); 65 | // set starting variable 66 | this->reset(); 67 | } 68 | 69 | template 70 | void machine::set_key(std::vector key) { 71 | // check if received key is not empty 72 | this->key = key.size() != 0 ? key : this->__default_key; 73 | if (this->key.size() > this->__cost_space) 74 | this->set_space(this->key.size()); // set new space parameter 75 | else // if needs additional mask 76 | CHAOS_BUFFER_MASK(this->key, this->__cost_space) 77 | this->__set_key(this->key); // pass via algorithm 78 | }; 79 | 80 | template void machine::set_time(size_t value) { 81 | this->__set_time(value); // pass via algorithm 82 | }; 83 | 84 | template void machine::set_space(size_t value) { 85 | this->__set_space(value); // pass via algorithm 86 | if (this->key.size() < value) // if needs additional mask 87 | CHAOS_BUFFER_MASK(this->key, value) 88 | }; 89 | 90 | template void machine::reset(void) { 91 | // call reset function in algorithm 92 | this->__reset(); 93 | // replace memory with our key 94 | this->__set_key(this->key); 95 | // if needs additional mask 96 | if (this->key.size() < this->__cost_space) 97 | CHAOS_BUFFER_MASK(this->key, this->__cost_space) 98 | } 99 | 100 | } //::chaos //////////////////////////////////////////////////////////////////// 101 | 102 | #endif // CHAOS_MACHINE_HH 103 | -------------------------------------------------------------------------------- /docs/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Index — libchaos 0.0.1-dev documentation 11 | 12 | 13 | 14 | 15 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 |
37 |
38 |
39 |
40 | 41 | 42 |

Index

43 | 44 |
45 | M 46 | 47 |
48 |

M

49 | 50 | 64 | 78 |
51 | 52 |
machine.pull() (built-in function) 53 |
54 | 55 | 56 |
machine.push() (built-in function) 57 |
58 | 59 | 60 |
machine.reset() (built-in function) 61 |
62 | 63 |
65 | 66 |
machine.set_key() (built-in function) 67 |
68 | 69 | 70 |
machine.set_space() (built-in function) 71 |
72 | 73 | 74 |
machine.set_time() (built-in function) 75 |
76 | 77 |
79 | 80 | 81 | 82 |
83 |
84 |
85 | 102 |
103 |
104 | 108 | 109 | -------------------------------------------------------------------------------- /docs/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #f0f0f0; } 3 | .highlight .c { color: #60a0b0; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #60a0b0; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #60a0b0; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #888888 } /* Generic.Output */ 19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #902000 } /* Keyword.Type */ 29 | .highlight .m { color: #40a070 } /* Literal.Number */ 30 | .highlight .s { color: #4070a0 } /* Literal.String */ 31 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 32 | .highlight .nb { color: #007020 } /* Name.Builtin */ 33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #60add5 } /* Name.Constant */ 35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #007020 } /* Name.Exception */ 38 | .highlight .nf { color: #06287e } /* Name.Function */ 39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #40a070 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #40a070 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #40a070 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #40a070 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #40a070 } /* Literal.Number.Oct */ 50 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 51 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 52 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 53 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 54 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 55 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 56 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 57 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 58 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 59 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 60 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 61 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 62 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 63 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 64 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 65 | .highlight .il { color: #40a070 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/search.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Search — libchaos 0.0.1-dev documentation 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
46 |
47 | 48 |

Search

49 |
50 | 51 |

52 | Please activate JavaScript to enable the search 53 | functionality. 54 |

55 |
56 |

57 | From here you can search these documents. Enter your search 58 | words into the box below and click "search". Note that the search 59 | function will automatically search for all of the words. Pages 60 | containing fewer words won't appear in the result list. 61 |

62 |
63 | 64 | 65 | 66 |
67 | 68 |
69 | 70 |
71 | 72 |
73 |
74 |
75 | 97 |
98 |
99 | 103 | 104 | -------------------------------------------------------------------------------- /tests/b_engines.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark/benchmark.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | /// machines /////////////////////////////////////////////////////////////////// 10 | 11 | #define B_MACHINE(x) \ 12 | x machine_##x; \ 13 | \ 14 | static void B__##x##__Push(benchmark::State &state) { \ 15 | machine_##x.set_space(state.range(1)); \ 16 | machine_##x.set_time(state.range(2)); \ 17 | \ 18 | while (state.KeepRunning()) { \ 19 | for (int i = state.range(0); i--;) { \ 20 | machine_##x.push(0xAA); \ 21 | machine_##x.push(0xBB); \ 22 | machine_##x.push(0xCC); \ 23 | machine_##x.push(0xDD); \ 24 | } \ 25 | } \ 26 | \ 27 | state.SetComplexityN(state.range(0)); \ 28 | state.SetItemsProcessed(state.iterations() * state.range(0)); \ 29 | state.SetBytesProcessed(state.iterations() * state.range(0) * \ 30 | sizeof(x::size_push) * 4); \ 31 | } \ 32 | \ 33 | BENCHMARK(B__##x##__Push) \ 34 | ->RangeMultiplier(8) \ 35 | ->Ranges({{1 << 12, 1 << 12}, {1, 32}, {1, 32}}) \ 36 | ->Complexity(benchmark::oAuto) \ 37 | ->Unit(benchmark::kMicrosecond); \ 38 | \ 39 | static void B__##x##__Pull(benchmark::State &state) { \ 40 | machine_##x.set_space(state.range(1)); \ 41 | machine_##x.set_time(state.range(2)); \ 42 | \ 43 | while (state.KeepRunning()) { \ 44 | for (int i = state.range(0); i--;) { \ 45 | machine_##x.pull(); \ 46 | machine_##x.pull(); \ 47 | machine_##x.pull(); \ 48 | machine_##x.pull(); \ 49 | } \ 50 | } \ 51 | \ 52 | state.SetComplexityN(state.range(0)); \ 53 | state.SetItemsProcessed(state.iterations() * state.range(0)); \ 54 | state.SetBytesProcessed(state.iterations() * state.range(0) * \ 55 | sizeof(x::size_pull) * 4); \ 56 | } \ 57 | \ 58 | BENCHMARK(B__##x##__Pull) \ 59 | ->RangeMultiplier(8) \ 60 | ->Ranges({{1 << 12, 1 << 12}, {1, 32}, {1, 32}}) \ 61 | ->Complexity(benchmark::oAuto) \ 62 | ->Unit(benchmark::kMicrosecond); 63 | 64 | B_MACHINE(CHAOS_MACHINE_NCG) 65 | B_MACHINE(CHAOS_MACHINE_XORRING32) 66 | B_MACHINE(CHAOS_MACHINE_XORRING64) 67 | -------------------------------------------------------------------------------- /include/chaos/macros.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_MACROS_HH 2 | #define CHAOS_MACROS_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace chaos { //::chaos //////////////////////////////////////////////////// 10 | 11 | // double from signed 12 | 13 | #define CHAOS_DOUBLE_S08(x) ((double)((int8_t)x) / (double)INT8_MAX) 14 | #define CHAOS_DOUBLE_S16(x) ((double)((int16_t)x) / (double)INT16_MAX) 15 | #define CHAOS_DOUBLE_S32(x) ((double)((int32_t)x) / (double)INT32_MAX) 16 | #define CHAOS_DOUBLE_S64(x) ((double)((int64_t)x) / (double)INT64_MAX) 17 | 18 | // double from unsigned 19 | 20 | #define CHAOS_DOUBLE_U08(x) ((double)((uint8_t)x) / (double)UINT8_MAX) 21 | #define CHAOS_DOUBLE_U16(x) ((double)((uint16_t)x) / (double)UINT16_MAX) 22 | #define CHAOS_DOUBLE_U32(x) ((double)((uint32_t)x) / (double)UINT32_MAX) 23 | #define CHAOS_DOUBLE_U64(x) ((double)((uint64_t)x) / (double)UINT64_MAX) 24 | 25 | // rotation: left 26 | 27 | #define CHAOS_RO_L08(n, r) \ 28 | ((uint8_t)((uint8_t)(n) << (r)) | (uint8_t)((uint8_t)(n) >> (8 - (r)))) 29 | #define CHAOS_RO_L16(n, r) \ 30 | ((uint16_t)((uint16_t)(n) << (r)) | (uint16_t)((uint16_t)(n) >> (16 - (r)))) 31 | #define CHAOS_RO_L32(n, r) \ 32 | ((uint32_t)((uint32_t)(n) << (r)) | (uint32_t)((uint32_t)(n) >> (32 - (r)))) 33 | #define CHAOS_RO_L64(n, r) \ 34 | ((uint64_t)((uint64_t)(n) << (r)) | (uint64_t)((uint64_t)(n) >> (64 - (r)))) 35 | 36 | // rotation: right 37 | 38 | #define CHAOS_RO_R08(n, r) \ 39 | ((uint8_t)((uint8_t)(n) >> (r)) | (uint8_t)((uint8_t)(n) << (8 - (r)))) 40 | #define CHAOS_RO_R16(n, r) \ 41 | ((uint16_t)((uint16_t)(n) >> (r)) | (uint16_t)((uint16_t)(n) << (16 - (r)))) 42 | #define CHAOS_RO_R32(n, r) \ 43 | ((uint32_t)((uint32_t)(n) >> (r)) | (uint32_t)((uint32_t)(n) << (32 - (r)))) 44 | #define CHAOS_RO_R64(n, r) \ 45 | ((uint64_t)((uint64_t)(n) >> (r)) | (uint64_t)((uint64_t)(n) << (64 - (r)))) 46 | 47 | // string to chars 48 | 49 | #define CHAOS_STRING_TO_CHAR(str) \ 50 | ({ \ 51 | char *str_copy = new char[str.size() + 1]; \ 52 | std::copy(str.begin(), str.end(), str_copy); \ 53 | str_copy[str.size()] = '\0'; \ 54 | str_copy; \ 55 | }) 56 | 57 | // register prng 58 | 59 | #define CHAOS_GENERATOR_REGISTER(a, b) typedef chaos::prng CHAOS_PRNG_##a; 60 | 61 | // register engine 62 | 63 | #define CHAOS_ENGINE_REGISTER(a, b) typedef chaos::machine CHAOS_MACHINE_##a; 64 | 65 | // utils for meta 66 | 67 | #define CHAOS_META_DEFINE(a, b) std::string name = a, authors = b; 68 | 69 | #define CHAOS_META_NAME(module) ({ module inst; inst.name; }) 70 | #define CHAOS_META_AUTHORS(module) ({ module inst; inst.authors; }) 71 | 72 | /// special //////////////////////////////////////////////////////////////////// 73 | 74 | #define __chaos_note(S, ...) \ 75 | fprintf(stderr, \ 76 | "\x1b[1m(%s:%d, %s)\x1b[0m\n \x1b[1m\x1b[90mnote:\x1b[0m " S "\n", \ 77 | __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) 78 | 79 | #define __chaos_warn(S, ...) \ 80 | fprintf(stderr, \ 81 | "\x1b[1m(%s:%d, %s)\x1b[0m\n \x1b[1m\x1b[33mwarning:\x1b[0m " S \ 82 | "\n", \ 83 | __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__) 84 | 85 | #define __chaos_errn(S, ...) \ 86 | do { \ 87 | fprintf(stderr, \ 88 | "\x1b[1m(%s:%d, %s)\x1b[0m\n \x1b[1m\x1b[31merror:\x1b[0m " S \ 89 | "\n", \ 90 | __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); \ 91 | exit(1); \ 92 | } while (0) 93 | 94 | } //::chaos //////////////////////////////////////////////////////////////////// 95 | 96 | #endif // CHAOS_MACROS_HH 97 | -------------------------------------------------------------------------------- /docs/source/generators.rst: -------------------------------------------------------------------------------- 1 | .. role:: okay 2 | .. role:: poor 3 | .. role:: vbad 4 | 5 | .. _prngs: 6 | 7 | Pseudo-Random Number Generator 8 | ============================== 9 | 10 | PRNG is an algorithm for **generating a sequence of numbers** whose properties approximate the properties of sequences of random numbers. Generated sequence is **not truly random**, because it is completely determined by a relatively small set of initial values, called the seed. 11 | 12 | List of Generators 13 | ------------------ 14 | 15 | Abyssinian 16 | ^^^^^^^^^^ 17 | 18 | .. class:: chaos::generators::abyssinian 19 | 20 | +--------------------+----------+-----------------+--------------+--------------+ 21 | | Seed | Output | Period | Quality | Speed | 22 | +====================+==========+=================+==============+==============+ 23 | | uint32_t, uint32_t | uint32_t | :math:`2^{126}` | :okay:`high` | :okay:`high` | 24 | +--------------------+----------+-----------------+--------------+--------------+ 25 | 26 | Xoroshiro128+ 27 | ^^^^^^^^^^^^^ 28 | 29 | .. class:: chaos::generators::xoroshiro128plus 30 | 31 | +----------+----------+-----------------+--------------+--------------+ 32 | | Seed | Output | Period | Quality | Speed | 33 | +==========+==========+=================+==============+==============+ 34 | | uint64_t | uint64_t | :math:`2^{128}` | :okay:`high` | :okay:`high` | 35 | +----------+----------+-----------------+--------------+--------------+ 36 | 37 | Xoroshiro1024* 38 | ^^^^^^^^^^^^^^ 39 | 40 | .. class:: chaos::generators::xoroshiro1024star 41 | 42 | +----------+----------+------------------+--------------+--------------+ 43 | | Seed | Output | Period | Quality | Speed | 44 | +==========+==========+==================+==============+==============+ 45 | | uint64_t | uint64_t | :math:`2^{1024}` | :okay:`high` | :okay:`high` | 46 | +----------+----------+------------------+--------------+--------------+ 47 | 48 | KISS 49 | ^^^^^^^^ 50 | 51 | .. class:: chaos::generators::kiss 52 | 53 | https://eprint.iacr.org/2011/007.pdf 54 | 55 | +--------------------+----------+-------------------+--------------+--------------+ 56 | | Seed | Output | Period | Quality | Speed | 57 | +====================+==========+===================+==============+==============+ 58 | | uint32_t, uint32_t | uint32_t | :math:`2^{119.5}` | :okay:`high` | :okay:`high` | 59 | +--------------------+----------+-------------------+--------------+--------------+ 60 | 61 | .. Linear Congruential Generator 62 | .. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 63 | 64 | .. .. class:: chaos::generators::lcg 65 | 66 | .. https://en.wikipedia.org/wiki/Linear_congruential_generator 67 | 68 | .. +------+--------+---------------+-------------+--------------+ 69 | .. | Seed | Output | Period | Quality | Speed | 70 | .. +======+========+===============+=============+==============+ 71 | .. | ??? | ??? | :math:`2^{n}` | :vbad:`low` | :okay:`high` | 72 | .. +------+--------+---------------+-------------+--------------+ 73 | 74 | .. Xorshift 75 | .. ^^^^^^^^ 76 | 77 | .. .. class:: chaos::generators::xorshift 78 | 79 | .. http://www.jstatsoft.org/v08/i14/paper 80 | 81 | .. +-------+--------+---------------+----------------+--------------+ 82 | .. | Seed | Output | Period | Quality | Speed | 83 | .. +=======+========+===============+================+==============+ 84 | .. | ??? | ??? | :math:`2^{n}` | :poor:`medium` | :okay:`high` | 85 | .. +-------+--------+---------------+----------------+--------------+ 86 | 87 | Adapter’s Interface 88 | ------------------- 89 | 90 | Typical Case 91 | ^^^^^^^^^^^^ 92 | 93 | .. code-block:: c++ 94 | 95 | CHAOS_PRNG_XOROSHIRO128PLUS gen; // shortcut (default seed) 96 | chaos::prng gen_class; 97 | // above: gen == gen_class 98 | 99 | // seeding is optional 100 | gen.seed(0x8a5cd789635d2dff); 101 | 102 | gen.next(); // return number 103 | gen.next(); // and another... 104 | 105 | Advanced Example 106 | ^^^^^^^^^^^^^^^^ 107 | 108 | .. code-block:: c++ 109 | 110 | CHAOS_PRNG_KISS gen; 111 | 112 | CHAOS_PRNG_KISS::size_next out; // for @3 113 | // uint32_t == CHAOS_PRNG_KISS::size_next 114 | 115 | // seed 116 | gen.seed(0x11223344); // @1 117 | gen << 0x11223344; // @2 118 | 119 | // next 120 | gen.next(); // @1 121 | gen(); // @2 122 | gen >> out; // @3 123 | 124 | .. Customizable Template 125 | .. ^^^^^^^^^^^^^^^^^^^^^ 126 | 127 | .. .. code-block:: c++ 128 | 129 | .. chaos::generators::xorshift gen; 130 | .. gen.__seed(0x8a5cd789); // like normal generator 131 | .. gen.__next(); // returns uint32_t 132 | 133 | -------------------------------------------------------------------------------- /docs/_sources/generators.rst.txt: -------------------------------------------------------------------------------- 1 | .. role:: okay 2 | .. role:: poor 3 | .. role:: vbad 4 | 5 | .. _prngs: 6 | 7 | Pseudo-Random Number Generator 8 | ============================== 9 | 10 | PRNG is an algorithm for **generating a sequence of numbers** whose properties approximate the properties of sequences of random numbers. Generated sequence is **not truly random**, because it is completely determined by a relatively small set of initial values, called the seed. 11 | 12 | List of Generators 13 | ------------------ 14 | 15 | Abyssinian 16 | ^^^^^^^^^^ 17 | 18 | .. class:: chaos::generators::abyssinian 19 | 20 | +--------------------+----------+-----------------+--------------+--------------+ 21 | | Seed | Output | Period | Quality | Speed | 22 | +====================+==========+=================+==============+==============+ 23 | | uint32_t, uint32_t | uint32_t | :math:`2^{126}` | :okay:`high` | :okay:`high` | 24 | +--------------------+----------+-----------------+--------------+--------------+ 25 | 26 | Xoroshiro128+ 27 | ^^^^^^^^^^^^^ 28 | 29 | .. class:: chaos::generators::xoroshiro128plus 30 | 31 | +----------+----------+-----------------+--------------+--------------+ 32 | | Seed | Output | Period | Quality | Speed | 33 | +==========+==========+=================+==============+==============+ 34 | | uint64_t | uint64_t | :math:`2^{128}` | :okay:`high` | :okay:`high` | 35 | +----------+----------+-----------------+--------------+--------------+ 36 | 37 | Xoroshiro1024* 38 | ^^^^^^^^^^^^^^ 39 | 40 | .. class:: chaos::generators::xoroshiro1024star 41 | 42 | +----------+----------+------------------+--------------+--------------+ 43 | | Seed | Output | Period | Quality | Speed | 44 | +==========+==========+==================+==============+==============+ 45 | | uint64_t | uint64_t | :math:`2^{1024}` | :okay:`high` | :okay:`high` | 46 | +----------+----------+------------------+--------------+--------------+ 47 | 48 | KISS 49 | ^^^^^^^^ 50 | 51 | .. class:: chaos::generators::kiss 52 | 53 | https://eprint.iacr.org/2011/007.pdf 54 | 55 | +--------------------+----------+-------------------+--------------+--------------+ 56 | | Seed | Output | Period | Quality | Speed | 57 | +====================+==========+===================+==============+==============+ 58 | | uint32_t, uint32_t | uint32_t | :math:`2^{119.5}` | :okay:`high` | :okay:`high` | 59 | +--------------------+----------+-------------------+--------------+--------------+ 60 | 61 | .. Linear Congruential Generator 62 | .. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 63 | 64 | .. .. class:: chaos::generators::lcg 65 | 66 | .. https://en.wikipedia.org/wiki/Linear_congruential_generator 67 | 68 | .. +------+--------+---------------+-------------+--------------+ 69 | .. | Seed | Output | Period | Quality | Speed | 70 | .. +======+========+===============+=============+==============+ 71 | .. | ??? | ??? | :math:`2^{n}` | :vbad:`low` | :okay:`high` | 72 | .. +------+--------+---------------+-------------+--------------+ 73 | 74 | .. Xorshift 75 | .. ^^^^^^^^ 76 | 77 | .. .. class:: chaos::generators::xorshift 78 | 79 | .. http://www.jstatsoft.org/v08/i14/paper 80 | 81 | .. +-------+--------+---------------+----------------+--------------+ 82 | .. | Seed | Output | Period | Quality | Speed | 83 | .. +=======+========+===============+================+==============+ 84 | .. | ??? | ??? | :math:`2^{n}` | :poor:`medium` | :okay:`high` | 85 | .. +-------+--------+---------------+----------------+--------------+ 86 | 87 | Adapter’s Interface 88 | ------------------- 89 | 90 | Typical Case 91 | ^^^^^^^^^^^^ 92 | 93 | .. code-block:: c++ 94 | 95 | CHAOS_PRNG_XOROSHIRO128PLUS gen; // shortcut (default seed) 96 | chaos::prng gen_class; 97 | // above: gen == gen_class 98 | 99 | // seeding is optional 100 | gen.seed(0x8a5cd789635d2dff); 101 | 102 | gen.next(); // return number 103 | gen.next(); // and another... 104 | 105 | Advanced Example 106 | ^^^^^^^^^^^^^^^^ 107 | 108 | .. code-block:: c++ 109 | 110 | CHAOS_PRNG_KISS gen; 111 | 112 | CHAOS_PRNG_KISS::size_next out; // for @3 113 | // uint32_t == CHAOS_PRNG_KISS::size_next 114 | 115 | // seed 116 | gen.seed(0x11223344); // @1 117 | gen << 0x11223344; // @2 118 | 119 | // next 120 | gen.next(); // @1 121 | gen(); // @2 122 | gen >> out; // @3 123 | 124 | .. Customizable Template 125 | .. ^^^^^^^^^^^^^^^^^^^^^ 126 | 127 | .. .. code-block:: c++ 128 | 129 | .. chaos::generators::xorshift gen; 130 | .. gen.__seed(0x8a5cd789); // like normal generator 131 | .. gen.__next(); // returns uint32_t 132 | 133 | -------------------------------------------------------------------------------- /docs/source/quickstart.rst: -------------------------------------------------------------------------------- 1 | Quickstart 2 | ========== 3 | 4 | This page gives a good introduction to libchaos. It assumes you already have library installed. If you do not, head over to the :ref:`installation` section. 5 | 6 | A Minimal Program 7 | ----------------- 8 | 9 | The library is very simple to use. As a short example, this is how it could be used to initialize chaos machine, sent and receive some bytes, and finally analyze it: 10 | 11 | .. code-block:: c++ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include // library header 18 | // namespace chaos::* 19 | 20 | // allocate std::vector (our starting variable) 21 | std::vector y_secret = {0x14, 0x15, 0x92, 0x65, 22 | 0x35, 0x89, 0x79, 0x32}; 23 | 24 | // initialize chaos machine using NCG algorithm/engine 25 | chaos::machine x_machine(y_secret); 26 | 27 | int main(void) { 28 | // allocate std::vector (our message/bitstrings) 29 | std::string y_string = "Lorem ipsum dolor sit..."; 30 | std::vector y_vector(y_string.begin(), y_string.end()); 31 | 32 | // make use of chaos machine (push/pull interface) 33 | x_machine.message(y_vector); // push 34 | std::vector y_result = x_machine.digest(256); // pull 35 | std::sort(y_result.begin(), y_result.end()); // sort 36 | 37 | // print sorted for rank-it plot (analysis) 38 | for (size_t i = 0; i < y_result.size(); i++) 39 | printf("%zu, %d\n", i, y_result[i]); 40 | } 41 | 42 | That code can be compiled simply by linking our library: 43 | 44 | .. code-block:: console 45 | 46 | $ g++ example.cpp -std=c++11 -lchaos -o example 47 | 48 | Libchaos only provides data and results. So we need data visualation tool to see it readable. We can use `gnuplot `_ (portable command-line driven graphing utility). Simple code to generate `rank-it plot `_: 49 | 50 | .. code-block:: gnuplot 51 | 52 | # filename: rankit.plt 53 | 54 | set terminal svg 55 | set output 'result.svg' 56 | 57 | set xrange [0:256] 58 | set yrange [0:256] 59 | 60 | plot x linecolor rgb "red" notitle 61 | plot 'points_x_y.csv' using 1:2 with points notitle 62 | 63 | Then we use command-line utilities: 64 | 65 | .. code-block:: console 66 | 67 | $ ./example > points_x_y.csv 68 | $ gnuplot rankit.plt 69 | 70 | Final result (data visualization): 71 | 72 | .. image:: _static/ncg_basic_rankit.svg 73 | :width: 100% 74 | 75 | Testing & Benchmarking 76 | ---------------------- 77 | 78 | Project uses `Google Test `_ and `Google Benchmark `_. To execute tests you need to build library manualy with option ``-DLIBCHAOS_ENABLE_TESTING=ON``. 79 | 80 | .. code-block:: console 81 | 82 | tests/ 83 | - b_.cc # for benchmarking | BENCHMARK(TEST_NAME) 84 | - t_.cc # for testing | TEST(TEST_NAME, CASE_NAME) 85 | 86 | After ``make build``, repository should contains programs named as: ``bchaos`` and ``tchaos`` (separately for benchmark and test), because tests are *required* while benchmarks are *optional*. 87 | 88 | Contributing To Project 89 | ----------------------- 90 | 91 | Our work flow is a `typical GitHub flow `_, where contributors fork the `libchaos repository `_, make their changes on branch, and submit a `Pull Request `_ (a.k.a. "PR"). Pull requests should usually be targeted at the `master` branch. 92 | 93 | Please include a nice description of your changes when you submit your PR; if we have to read the whole diff to figure out why you're contributing in the first place, you're less likely to get feedback and have your change merged in. 94 | 95 | Life will be a lot easier for you if you follow this pattern (i.e. fork, named branch, submit PR). If you use your fork's `master` branch directly, things can get messy. 96 | 97 | Before wrapping up a PR, you should be sure to: 98 | 99 | * Write tests to cover any functional changes. 100 | * Update documentation for any changed public APIs. 101 | * Add to the `CHANGELOG.md `_ file describing any major changes. 102 | 103 | Future Ideas 104 | ^^^^^^^^^^^^ 105 | 106 | If you are starting to work on a particular area, feel free to submit a PR that highlights your work in progress (and note in the PR title that it's not ready to merge). These early PRs are welcome and will help in getting visibility for your fix, allow others to comment early on the changes and also let others know that you are currently working on something. 107 | -------------------------------------------------------------------------------- /docs/_sources/quickstart.rst.txt: -------------------------------------------------------------------------------- 1 | Quickstart 2 | ========== 3 | 4 | This page gives a good introduction to libchaos. It assumes you already have library installed. If you do not, head over to the :ref:`installation` section. 5 | 6 | A Minimal Program 7 | ----------------- 8 | 9 | The library is very simple to use. As a short example, this is how it could be used to initialize chaos machine, sent and receive some bytes, and finally analyze it: 10 | 11 | .. code-block:: c++ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include // library header 18 | // namespace chaos::* 19 | 20 | // allocate std::vector (our starting variable) 21 | std::vector y_secret = {0x14, 0x15, 0x92, 0x65, 22 | 0x35, 0x89, 0x79, 0x32}; 23 | 24 | // initialize chaos machine using NCG algorithm/engine 25 | chaos::machine x_machine(y_secret); 26 | 27 | int main(void) { 28 | // allocate std::vector (our message/bitstrings) 29 | std::string y_string = "Lorem ipsum dolor sit..."; 30 | std::vector y_vector(y_string.begin(), y_string.end()); 31 | 32 | // make use of chaos machine (push/pull interface) 33 | x_machine.message(y_vector); // push 34 | std::vector y_result = x_machine.digest(256); // pull 35 | std::sort(y_result.begin(), y_result.end()); // sort 36 | 37 | // print sorted for rank-it plot (analysis) 38 | for (size_t i = 0; i < y_result.size(); i++) 39 | printf("%zu, %d\n", i, y_result[i]); 40 | } 41 | 42 | That code can be compiled simply by linking our library: 43 | 44 | .. code-block:: console 45 | 46 | $ g++ example.cpp -std=c++11 -lchaos -o example 47 | 48 | Libchaos only provides data and results. So we need data visualation tool to see it readable. We can use `gnuplot `_ (portable command-line driven graphing utility). Simple code to generate `rank-it plot `_: 49 | 50 | .. code-block:: gnuplot 51 | 52 | # filename: rankit.plt 53 | 54 | set terminal svg 55 | set output 'result.svg' 56 | 57 | set xrange [0:256] 58 | set yrange [0:256] 59 | 60 | plot x linecolor rgb "red" notitle 61 | plot 'points_x_y.csv' using 1:2 with points notitle 62 | 63 | Then we use command-line utilities: 64 | 65 | .. code-block:: console 66 | 67 | $ ./example > points_x_y.csv 68 | $ gnuplot rankit.plt 69 | 70 | Final result (data visualization): 71 | 72 | .. image:: _static/ncg_basic_rankit.svg 73 | :width: 100% 74 | 75 | Testing & Benchmarking 76 | ---------------------- 77 | 78 | Project uses `Google Test `_ and `Google Benchmark `_. To execute tests you need to build library manualy with option ``-DLIBCHAOS_ENABLE_TESTING=ON``. 79 | 80 | .. code-block:: console 81 | 82 | tests/ 83 | - b_.cc # for benchmarking | BENCHMARK(TEST_NAME) 84 | - t_.cc # for testing | TEST(TEST_NAME, CASE_NAME) 85 | 86 | After ``make build``, repository should contains programs named as: ``bchaos`` and ``tchaos`` (separately for benchmark and test), because tests are *required* while benchmarks are *optional*. 87 | 88 | Contributing To Project 89 | ----------------------- 90 | 91 | Our work flow is a `typical GitHub flow `_, where contributors fork the `libchaos repository `_, make their changes on branch, and submit a `Pull Request `_ (a.k.a. "PR"). Pull requests should usually be targeted at the `master` branch. 92 | 93 | Please include a nice description of your changes when you submit your PR; if we have to read the whole diff to figure out why you're contributing in the first place, you're less likely to get feedback and have your change merged in. 94 | 95 | Life will be a lot easier for you if you follow this pattern (i.e. fork, named branch, submit PR). If you use your fork's `master` branch directly, things can get messy. 96 | 97 | Before wrapping up a PR, you should be sure to: 98 | 99 | * Write tests to cover any functional changes. 100 | * Update documentation for any changed public APIs. 101 | * Add to the `CHANGELOG.md `_ file describing any major changes. 102 | 103 | Future Ideas 104 | ^^^^^^^^^^^^ 105 | 106 | If you are starting to work on a particular area, feel free to submit a PR that highlights your work in progress (and note in the PR title that it's not ready to merge). These early PRs are welcome and will help in getting visibility for your fix, allow others to comment early on the changes and also let others know that you are currently working on something. 107 | -------------------------------------------------------------------------------- /src/engines/xorring.cc: -------------------------------------------------------------------------------- 1 | #include "chaos/engines/xorring.hh" 2 | 3 | namespace chaos { //::chaos //////////////////////////////////////////////////// 4 | namespace engines { //::chaos::engines ///////////////////////////////////////// 5 | 6 | void xorring32::push(uint32_t block) { 7 | for (size_t i = 0; i < this->__cost_time; i++) { 8 | uint32_t cache = this->pull(); 9 | buffer.front() += cache + block; 10 | } 11 | } 12 | 13 | uint32_t xorring32::pull(void) { 14 | uint32_t a = buffer.front(), b = buffer.back(), c; 15 | 16 | buffer.pop_front(), c = (a ^ (a >> 3)); 17 | buffer.push_back(c = (b ^ (b << 13)) ^ (c ^ (c << 7))); 18 | 19 | return (a + b + 1) * c; 20 | } 21 | 22 | void xorring32::__reset(void) {} 23 | 24 | //////////////////////////////////////////////////////////////////////////////// 25 | 26 | void xorring64::push(uint64_t block) { 27 | for (size_t i = 0; i < this->__cost_time; i++) { 28 | uint64_t cache = this->pull(); 29 | buffer.front() += cache + block; 30 | } 31 | } 32 | 33 | uint64_t xorring64::pull(void) { 34 | uint64_t a = buffer.front(), b = buffer.back(), c; 35 | 36 | buffer.pop_front(), c = (a ^ (a >> 4)); 37 | buffer.push_back(c = (b ^ (b << 9)) ^ (c ^ (c << 13))); 38 | 39 | return (a + b + 1) * c; 40 | } 41 | 42 | void xorring64::__reset(void) {} 43 | 44 | } //::chaos::engines /////////////////////////////////////////////////////////// 45 | } //::chaos //////////////////////////////////////////////////////////////////// 46 | 47 | /* 48 | 49 | XORRING32 50 | 51 | | 1, 3,10| 1, 5,16| 1, 5,19| 1, 9,29| 1,11, 6| 1,11,16| 1,19, 3| 1,21,20| 1,27,27| 52 | | 2, 5,15| 2, 5,21| 2, 7, 7| 2, 7, 9| 2, 7,25| 2, 9,15| 2,15,17| 2,15,25| 2,21, 9| 53 | | 3, 1,14| 3, 3,26| 3, 3,28| 3, 3,29| 3, 5,20| 3, 5,22| 3, 5,25| 3, 7,29| 3,13, 7| 54 | | 3,23,25| 3,25,24| 3,27,11| 4, 3,17| 4, 3,27| 4, 5,15| 5, 3,21| 5, 7,22| 5, 9,7 | 55 | | 5, 9,28| 5, 9,31| 5,13, 6| 5,15,17| 5,17,13| 5,21,12| 5,27, 8| 5,27,21| 5,27,25| 56 | | 5,27,28| 6, 1,11| 6, 3,17| 6,17, 9| 6,21, 7| 6,21,13| 7, 1, 9| 7, 1,18| 7, 1,25| 57 | | 7,13,25| 7,17,21| 7,25,12| 7,25,20| 8, 7,23| 8,9,23 | 9, 5,1 | 9, 5,25| 9,11,19| 58 | | 9,21,16|10, 9,21|10, 9,25|11, 7,12|11, 7,16|11,17,13|11,21,13|12, 9,23|13, 3,17| 59 | |13, 3,27|13, 5,19|13,17,15|14, 1,15|14,13,15|15, 1,29|17,15,20|17,15,23|17,15,26| 60 | 61 | XORRING64 62 | 63 | | 1, 1,54| 1, 1,55| 1, 3,45| 1, 7, 9| 1, 7,44| 1, 7,46| 1, 9,50| 1,11,35| 1,11,50| 64 | | 1,13,45| 1,15, 4| 1,15,63| 1,19, 6| 1,19,16| 1,23,14| 1,23,29| 1,29,34| 1,35, 5| 65 | | 1,35,11| 1,35,34| 1,45,37| 1,51,13| 1,53, 3| 1,59,14| 2,13,23| 2,31,51| 2,31,53| 66 | | 2,43,27| 2,47,49| 3, 1,11| 3, 5,21| 3,13,59| 3,21,31| 3,25,20| 3,25,31| 3,25,56| 67 | | 3,29,40| 3,29,47| 3,29,49| 3,35,14| 3,37,17| 3,43, 4| 3,43, 6| 3,43,11| 3,51,16| 68 | | 3,53, 7| 3,61,17| 3,61,26| 4, 7,19| 4, 9,13| 4,15,51| 4,15,53| 4,29,45| 4,29,49| 69 | | 4,31,33| 4,35,15| 4,35,21| 4,37,11| 4,37,21| 4,41,19| 4,41,45| 4,43,21| 4,43,31| 70 | | 4,53, 7| 5, 9,23| 5,11,54| 5,15,27| 5,17,11| 5,23,36| 5,33,29| 5,41,20| 5,45,16| 71 | | 5,47,23| 5,53,20| 5,59,33| 5,59,35| 5,59,63| 6, 1,17| 6, 3,49| 6,17,47| 6,23,27| 72 | | 6,27, 7| 6,43,21| 6,49,29| 6,55,17| 7, 5,41| 7, 5,47| 7, 5,55| 7, 7,20| 7, 9,38| 73 | | 7,11,10| 7,11,35| 7,13,58| 7,19,17| 7,19,54| 7,23, 8| 7,25,58| 7,27,59| 7,33, 8| 74 | | 7,41,40| 7,43,28| 7,51,24| 7,57,12| 8, 5,59| 8, 9,25| 8,13,25| 8,13,61| 8,15,21| 75 | | 8,25,59| 8,29,19| 8,31,17| 8,37,21| 8,51,21| 9, 1,27| 9, 5,36| 9, 5,43| 9, 7,18| 76 | | 9,19,18| 9,21,11| 9,21,20| 9,21,40| 9,23,57| 9,27,10| 9,29,12| 9,29,37| 9,37,31| 77 | | 9,41,45|10, 7,33|10,27,59|10,53,13|11, 5,32|11, 5,34|11, 5,43|11, 5,45|11, 9,14| 78 | |11, 9,34|11,13,40|11,15,37|11,23,42|11,23,56|11,25,48|11,27,26|11,29,14|11,31,18| 79 | |11,53,23|12, 1,31|12, 3,13|12, 3,49|12, 7,13|12,11,47|12,25,27|12,39,49|12,43,19| 80 | |13, 3,40|13, 3,53|13, 7,17|13, 9,15|13, 9,50|13,13,19|13,17,43|13,19,28|13,19,47| 81 | |13,21,18|13,21,49|13,29,35|13,35,30|13,35,38|13,47,23|13,51,21|14,13,17|14,15,19| 82 | |14,23,33|14,31,45|14,47,15|15, 1,19|15, 5,37|15,13,28|15,13,52|15,17,27|15,19,63| 83 | |15,21,46|15,23,23|15,45,17|15,47,16|15,49,26|16, 5,17|16, 7,39|16,11,19|16,11,27| 84 | |16,13,55|16,21,35|16,25,43|16,27,53|16,47,17|17,15,58|17,23,29|17,23,51|17,23,52| 85 | |17,27,22|17,45,22|17,47,28|17,47,29|17,47,54|18, 1,25|18, 3,43|18,19,19|18,25,21| 86 | |18,41,23|19, 7,36|19, 7,55|19,13,37|19,15,46|19,21,52|19,25,20|19,41,21|19,43,27| 87 | |20, 1,31|20, 5,29|21, 1,27|21, 9,29|21,13,52|21,15,28|21,15,29|21,17,24|21,17,30| 88 | |21,17,48|21,21,32|21,21,34|21,21,37|21,21,38|21,21,40|21,21,41|21,21,43|21,41,23| 89 | |22, 3,39|23, 9,38|23, 9,48|23, 9,57|23,13,38|23,13,58|23,13,61|23,17,25|23,17,54| 90 | |23,17,56|23,17,62|23,41,34|23,41,51|24, 9,35|24,11,29|24,25,25|24,31,35|25, 7,46| 91 | |25, 7,49|25, 9,39|25,11,57|25,13,29|25,13,39|25,13,62|25,15,47|25,21,44|25,27,27| 92 | |25,27,53|25,33,36|25,39,54|28, 9,55|28,11,53|29,27,37|31, 1,51|31,25,37|31,27,35| 93 | |33,31,43|33,31,55|43,21,46|49,15,61|55, 9,56| 94 | 95 | */ 96 | -------------------------------------------------------------------------------- /tests/t_mixins.cc: -------------------------------------------------------------------------------- 1 | #include "gtest/gtest.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | /// mixins ///////////////////////////////////////////////////////////////////// 11 | 12 | TEST(MIXINS, T__CHAOS_TRUELY__AdapterInitialization) { 13 | chaos::truely gen_0, gen_1; 14 | 15 | size_t n = 100; 16 | std::vector a(n), b(n); 17 | 18 | for (size_t i = 0; i < n; i++) 19 | a.push_back(gen_0()); 20 | 21 | for (size_t i = 0; i < n; i++) 22 | b.push_back(gen_1()); 23 | 24 | EXPECT_NE(a, b); 25 | } 26 | 27 | TEST(MIXINS, T__CHAOS_PASSWORD__AvalancheTime) { 28 | std::string a, b, c, d; 29 | 30 | a = chaos::password("OMG AAA OMG1", 31 | "WTF"); 32 | b = chaos::password("OMG AAA OMG1", 33 | "WTF"); 34 | c = chaos::password("OMG AAA OMG1", 35 | "WTF"); 36 | d = chaos::password("OMG AAA OMG1", 37 | "WTF"); 38 | 39 | EXPECT_STREQ(a.c_str(), "4012BDD17547BBEE9A638E5A22829A7625F1B860"); 40 | EXPECT_STREQ(b.c_str(), "D67B0DF02DEE6A4824083D004C722A3672734BCE"); 41 | EXPECT_STREQ(c.c_str(), "4A2BC5F8117B83D16C69BA8F71F8D1CB2238ED94"); 42 | EXPECT_STREQ(d.c_str(), "3F871BE85A214A0D4159675B992052699E5D8A46"); 43 | } 44 | 45 | TEST(MIXINS, T__CHAOS_PASSWORD__AvalancheSpace) { 46 | std::string a, b, c, d; 47 | 48 | a = chaos::password("OMG AAA OMG1", 49 | "WTFX"); 50 | b = chaos::password("OMG AAA OMG1", 51 | "WTFX"); 52 | c = chaos::password("OMG AAA OMG1", 53 | "WTFX"); 54 | d = chaos::password("OMG AAA OMG1", 55 | "WTFX"); 56 | 57 | EXPECT_STREQ(a.c_str(), "53C7B08FBA52042423F921D020DE30ACC93D3266"); 58 | EXPECT_STREQ(b.c_str(), "ABC80FD2E489D828914F126F544A1FDCAD5CD806"); 59 | EXPECT_STREQ(c.c_str(), "A97071E2BE1982C8D24EFBA3EC85C37B1F892BE9"); 60 | EXPECT_STREQ(d.c_str(), "4B17D7A28566AE061E8F5A734D2650A3665D6903"); 61 | } 62 | 63 | TEST(MIXINS, T__CHAOS_PASSWORD__AvalanchePassword) { 64 | std::string a, b, c, d; 65 | 66 | a = chaos::password("OMG AAA OMG1", 67 | "WTF"); 68 | b = chaos::password("OMG AAA OMG2", 69 | "WTF"); 70 | c = chaos::password("OMG AAA OMG ", 71 | "WTF"); 72 | d = chaos::password("2MG AAA OMG1", 73 | "WTF"); 74 | 75 | EXPECT_STREQ(a.c_str(), "21504EE0E99E1073B191D591FC73D3A0D8C88454"); 76 | EXPECT_STREQ(b.c_str(), "9A5E6500C880C490799024B0D36238DF72B2FCF8"); 77 | EXPECT_STREQ(c.c_str(), "181DD01633E0743BB464606033F2E8259E09849E"); 78 | EXPECT_STREQ(d.c_str(), "51387B0ED6AD2AE633D98C0927146587DD81440C"); 79 | } 80 | 81 | TEST(MIXINS, T__CHAOS_PASSWORD__AvalancheSalt) { 82 | std::string a, b, c, d; 83 | 84 | a = chaos::password("OMG AAA OMG1", 85 | "WTF1"); 86 | b = chaos::password("OMG AAA OMG1", 87 | "WTF2"); 88 | c = chaos::password("OMG AAA OMG1", 89 | "WTF3"); 90 | d = chaos::password("OMG AAA OMG1", 91 | "WTF4"); 92 | 93 | EXPECT_STREQ(a.c_str(), "C750FC104071A69944974036FD1B747C19643BB3"); 94 | EXPECT_STREQ(b.c_str(), "8590CE2C93D6F06867080B0D2B40D466462A9E35"); 95 | EXPECT_STREQ(c.c_str(), "39E71B96FCFCD037C2FFB6A8EA12EBF072AE0837"); 96 | EXPECT_STREQ(d.c_str(), "600BF07C9F0040F6852B1D80C95D32C4B316D8F2"); 97 | } 98 | 99 | /* FIXME 100 | TEST(MIXINS, MACROS) { 101 | // machines 102 | EXPECT_EQ(CHAOS_META_NAME(CHAOS_MACHINE_NCG), 103 | "NCG (Naive Czyzewski Generator)"); 104 | EXPECT_EQ(CHAOS_META_AUTHORS(CHAOS_MACHINE_NCG), "Maciej A. Czyzewski"); 105 | 106 | // prngs 107 | EXPECT_EQ(CHAOS_META_NAME(CHAOS_PRNG_KISS), "KISS (Keep It Simple Stupid)"); 108 | EXPECT_EQ(CHAOS_META_AUTHORS(CHAOS_PRNG_KISS), "G. Marsaglia and A. Zaman"); 109 | } 110 | */ 111 | -------------------------------------------------------------------------------- /tests/b_generators.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark/benchmark.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | /// prng /////////////////////////////////////////////////////////////////////// 10 | 11 | #define B_PRNG(x) \ 12 | x prng_##x; \ 13 | \ 14 | static void B__##x##__Next(benchmark::State &state) { \ 15 | while (state.KeepRunning()) { \ 16 | for (int i = state.range(0); i--;) { \ 17 | prng_##x.next(); \ 18 | prng_##x.next(); \ 19 | prng_##x.next(); \ 20 | prng_##x.next(); \ 21 | } \ 22 | } \ 23 | \ 24 | state.SetComplexityN(state.range(0)); \ 25 | state.SetItemsProcessed(state.iterations() * state.range(0)); \ 26 | state.SetBytesProcessed(state.iterations() * state.range(0) * \ 27 | sizeof(x::size_next) * 4); \ 28 | } \ 29 | \ 30 | BENCHMARK(B__##x##__Next) \ 31 | ->RangeMultiplier(4) \ 32 | ->Range(1 << 14, 1 << 20) \ 33 | ->Complexity(benchmark::oAuto) \ 34 | ->Unit(benchmark::kMicrosecond); 35 | 36 | #define B_PRNG_BASE(x, y) \ 37 | x prng_##x; \ 38 | \ 39 | static void B__##x##__Next(benchmark::State &state) { \ 40 | while (state.KeepRunning()) { \ 41 | for (int i = state.range(0); i--;) { \ 42 | prng_##x(); \ 43 | prng_##x(); \ 44 | prng_##x(); \ 45 | prng_##x(); \ 46 | } \ 47 | } \ 48 | \ 49 | state.SetComplexityN(state.range(0)); \ 50 | state.SetItemsProcessed(state.iterations() * state.range(0)); \ 51 | state.SetBytesProcessed(state.iterations() * state.range(0) * sizeof(y) * \ 52 | 4); \ 53 | } \ 54 | \ 55 | BENCHMARK(B__##x##__Next) \ 56 | ->RangeMultiplier(4) \ 57 | ->Range(1 << 14, 1 << 20) \ 58 | ->Complexity(benchmark::oAuto) \ 59 | ->Unit(benchmark::kMicrosecond); 60 | 61 | /// lib /////////////////////////////////////////////////////////////////////// 62 | 63 | B_PRNG(CHAOS_PRNG_KISS) 64 | B_PRNG(CHAOS_PRNG_ABYSSINIAN) 65 | B_PRNG(CHAOS_PRNG_XOROSHIRO128PLUS) 66 | B_PRNG(CHAOS_PRNG_XOROSHIRO1024STAR) 67 | B_PRNG(CHAOS_PRNG_XORSHF96) 68 | 69 | /// stl //////////////////////////////////////////////////////////////////////// 70 | 71 | typedef std::linear_congruential_engine 73 | STL_MINSTD_RAND; 74 | typedef std::mersenne_twister_engine 77 | STL_MT19937; 78 | typedef std::mersenne_twister_engine< 79 | std::uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9, 29, 80 | 0x5555555555555555, 17, 0x71d67fffeda60000, 37, 0xfff7eee000000000, 43, 81 | 6364136223846793005> 82 | STL_MT19937_64; 83 | typedef std::discard_block_engine STL_RANLUX24; 84 | typedef std::discard_block_engine STL_RANLUX48; 85 | typedef std::shuffle_order_engine STL_KNUTH_B; 86 | 87 | B_PRNG_BASE(STL_MINSTD_RAND, uint_fast32_t) 88 | B_PRNG_BASE(STL_MT19937, uint_fast32_t) 89 | B_PRNG_BASE(STL_MT19937_64, uint_fast64_t) 90 | B_PRNG_BASE(STL_RANLUX24, uint_fast32_t) 91 | B_PRNG_BASE(STL_RANLUX48, uint_fast64_t) 92 | B_PRNG_BASE(STL_KNUTH_B, uint_fast32_t) 93 | -------------------------------------------------------------------------------- /include/chaos/analysis.hh: -------------------------------------------------------------------------------- 1 | #ifndef CHAOS_ANALYSIS_HH 2 | #define CHAOS_ANALYSIS_HH 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "chaos/types.hh" 11 | 12 | namespace chaos { //::chaos //////////////////////////////////////////////////// 13 | 14 | typedef double (*AP)(void); 15 | 16 | //////////////////////////////////////////////////////////////////////////////// 17 | 18 | #define CHAOS_ANALYSIS_TEST(f, r, o) \ 19 | { \ 20 | for (size_t i = 0; i < r; i++) \ 21 | o += f; \ 22 | o /= r; \ 23 | } 24 | 25 | #define CHAOS_ANALYSIS_RESULT(f, o) \ 26 | { \ 27 | if (o >= 1 || o <= 0) { \ 28 | printf("%30s | %12f | \x1b[31mFAILED\x1b[0m\n", #f, o); \ 29 | } else { \ 30 | printf("%30s | %12f | \x1b[32mPASSED\x1b[0m\n", #f, o); \ 31 | } \ 32 | } 33 | 34 | //////////////////////////////////////////////////////////////////////////////// 35 | 36 | class basic_adapter { 37 | AP adapter; 38 | 39 | public: 40 | void connect(AP func) { adapter = func; } 41 | constexpr static size_t max(void) { 42 | return std::numeric_limits::max(); 43 | } 44 | constexpr static size_t min(void) { 45 | return std::numeric_limits::lowest(); 46 | } 47 | uint32_t operator()(void) noexcept { 48 | return (uint32_t)(adapter() * (double)UINT32_MAX); 49 | } 50 | }; 51 | 52 | //////////////////////////////////////////////////////////////////////////////// 53 | 54 | double arithmetic_average(AP); 55 | double dirichlet_probe(AP); 56 | double pi_calculus(AP); 57 | 58 | //////////////////////////////////////////////////////////////////////////////// 59 | 60 | template 61 | double sample_mean(basic_adapter adapter, TDistribution dist, int sample_size) { 62 | double sum = 0; 63 | for (int i = 0; i < sample_size; ++i) 64 | sum += dist(adapter); 65 | return sum / sample_size; 66 | } 67 | 68 | template 69 | double test_mean(basic_adapter adapter, TDistribution dist, double true_mean, 70 | double true_variance) { 71 | double true_stdev = sqrt(true_variance); 72 | int sample_size = 10000000 / 50; 73 | double mean = sample_mean(adapter, dist, sample_size); 74 | double lower = true_mean - true_stdev / sqrt((double)sample_size); 75 | double upper = true_mean + true_stdev / sqrt((double)sample_size); 76 | return ((100 * (mean - lower)) / (upper - lower)) / 100; 77 | } 78 | 79 | //////////////////////////////////////////////////////////////////////////////// 80 | 81 | class analysis { 82 | AP adapter_01; 83 | basic_adapter adapter; 84 | 85 | public: 86 | explicit analysis(AP x) { 87 | adapter_01 = x; 88 | adapter.connect(x); 89 | }; 90 | void raport(void) { 91 | double result = 0; 92 | 93 | CHAOS_ANALYSIS_TEST(arithmetic_average(adapter_01), 100, result); 94 | CHAOS_ANALYSIS_RESULT(arithmetic_average, result); 95 | 96 | CHAOS_ANALYSIS_TEST(pi_calculus(adapter_01), 500, result); 97 | CHAOS_ANALYSIS_RESULT(pi_calculus, result); 98 | 99 | CHAOS_ANALYSIS_TEST(dirichlet_probe(adapter_01), 25, result); 100 | CHAOS_ANALYSIS_RESULT(dirichlet_probe, result); 101 | 102 | int n; 103 | double p, lambda, shape, mu, sigma; 104 | 105 | n = 5; 106 | p = 0.3; 107 | std::binomial_distribution binomial(n, p); 108 | CHAOS_ANALYSIS_TEST(test_mean(adapter, binomial, n * p, n * p * (1 - p)), 109 | 50, result); 110 | CHAOS_ANALYSIS_RESULT(binomial_distribution, result); 111 | 112 | lambda = 4.0; 113 | std::exponential_distribution exponential(lambda); 114 | CHAOS_ANALYSIS_TEST( 115 | test_mean(adapter, exponential, 1.0 / lambda, 1.0 / (lambda * lambda)), 116 | 50, result); 117 | CHAOS_ANALYSIS_RESULT(exponential_distribution, result); 118 | 119 | shape = 3.0; 120 | std::gamma_distribution gamma(shape); 121 | CHAOS_ANALYSIS_TEST(test_mean(adapter, gamma, shape, shape), 50, result); 122 | CHAOS_ANALYSIS_RESULT(gamma_distribution, result); 123 | 124 | p = 0.001; 125 | std::geometric_distribution geometric(p); 126 | CHAOS_ANALYSIS_TEST(test_mean(adapter, geometric, 1.0 / p, 1.0 / (p * p)), 127 | 50, result); 128 | CHAOS_ANALYSIS_RESULT(geometric_distribution, result); 129 | 130 | mu = 3.0; 131 | sigma = 4.0; 132 | std::normal_distribution normal(mu, sigma); 133 | CHAOS_ANALYSIS_TEST(test_mean(adapter, normal, mu, sigma * sigma), 50, 134 | result); 135 | CHAOS_ANALYSIS_RESULT(normal_distribution, result); 136 | 137 | lambda = 7.0; 138 | std::poisson_distribution poisson(7.0); 139 | CHAOS_ANALYSIS_TEST(test_mean(adapter, poisson, lambda, lambda), 50, 140 | result); 141 | CHAOS_ANALYSIS_RESULT(poisson_distribution, result); 142 | 143 | p = 0.6; 144 | std::bernoulli_distribution bernoulli(p); 145 | CHAOS_ANALYSIS_TEST(test_mean(adapter, bernoulli, p, p * (1 - p)), 50, 146 | result); 147 | CHAOS_ANALYSIS_RESULT(bernoulli_distribution, result); 148 | }; 149 | }; 150 | 151 | } //::chaos //////////////////////////////////////////////////////////////////// 152 | 153 | #endif // CHAOS_ANALYSIS_HH 154 | -------------------------------------------------------------------------------- /examples/benchmark_graph.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //////////////////////////////////////////////////////////////////////////////// 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | typedef std::linear_congruential_engine 15 | STL_MINSTD_RAND; 16 | typedef std::mersenne_twister_engine 19 | STL_MT19937; 20 | typedef std::mersenne_twister_engine< 21 | std::uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9, 29, 22 | 0x5555555555555555, 17, 0x71d67fffeda60000, 37, 0xfff7eee000000000, 43, 23 | 6364136223846793005> 24 | STL_MT19937_64; 25 | typedef std::discard_block_engine STL_RANLUX24; 26 | typedef std::discard_block_engine STL_RANLUX48; 27 | typedef std::shuffle_order_engine STL_KNUTH_B; 28 | 29 | #define CLOCK_POINT(a) \ 30 | std::chrono::high_resolution_clock::time_point a = \ 31 | std::chrono::high_resolution_clock::now(); 32 | #define CLOCK_DIFF(a, b) \ 33 | std::chrono::duration_cast(b - a).count() 34 | 35 | //////////////////////////////////////////////////////////////////////////////// 36 | 37 | #define BENCHMARK(algorithm, func, size_output) \ 38 | { \ 39 | std::string name = #algorithm; \ 40 | printf("[%s]\n", name.c_str()); \ 41 | \ 42 | std::ofstream file; \ 43 | file.open(name + ".csv"); \ 44 | file << "bytes,rate\n"; \ 45 | \ 46 | size_t d = 400; \ 47 | if (sizeof(size_output) != 8) d *= 8 / (int)sizeof(size_output); \ 48 | \ 49 | for (size_t p = 1; p < d; p++) { \ 50 | fprintf(stderr, "."); \ 51 | size_t num = 5 * p; \ 52 | size_t rep = 500 * 1.5; \ 53 | \ 54 | std::vector v(rep); \ 55 | \ 56 | for (size_t i = 0; i < rep; i++) { \ 57 | uint64_t x = 0; \ 58 | CLOCK_POINT(A) \ 59 | for (size_t j = 0; j < num; j++) x ^= func; \ 60 | CLOCK_POINT(B) \ 61 | v[i] = CLOCK_DIFF(A, B); \ 62 | } \ 63 | \ 64 | std::sort(v.begin(), v.end()); \ 65 | v.erase(v.begin(), v.begin() + rep / 5); \ 66 | v.resize(rep - 2 * rep / 5); \ 67 | \ 68 | double sum = std::accumulate(v.begin(), v.end(), 0.0); \ 69 | double mean = sum / v.size(); \ 70 | \ 71 | size_t bytes = sizeof(size_output) * num; \ 72 | file << (uint64_t)bytes << "," << mean << "\n"; \ 73 | } \ 74 | \ 75 | file.close(); \ 76 | printf("\n\n"); \ 77 | } 78 | 79 | #define B_CM(algorithm) \ 80 | { \ 81 | algorithm gen; \ 82 | BENCHMARK(algorithm, gen.pull(), typename algorithm::size_pull); \ 83 | } 84 | 85 | #define B_PRNG(algorithm) \ 86 | { \ 87 | algorithm gen; \ 88 | BENCHMARK(algorithm, gen.next(), typename algorithm::size_next); \ 89 | } 90 | 91 | #define B_PRNG_BASE(algorithm, typename_size) \ 92 | { \ 93 | algorithm gen; \ 94 | BENCHMARK(algorithm, gen(), typename_size); \ 95 | } 96 | 97 | //////////////////////////////////////////////////////////////////////////////// 98 | 99 | int main(void) { 100 | // CMs 101 | B_CM(CHAOS_MACHINE_NCG); 102 | B_CM(CHAOS_MACHINE_XORRING32); 103 | B_CM(CHAOS_MACHINE_XORRING64); 104 | 105 | // PRNGs 106 | B_PRNG(CHAOS_PRNG_KISS) 107 | B_PRNG(CHAOS_PRNG_ABYSSINIAN) 108 | B_PRNG(CHAOS_PRNG_XOROSHIRO128PLUS) 109 | B_PRNG(CHAOS_PRNG_XOROSHIRO1024STAR) 110 | B_PRNG(CHAOS_PRNG_XORSHF96) 111 | 112 | // STLs 113 | B_PRNG_BASE(STL_MINSTD_RAND, uint_fast32_t) 114 | B_PRNG_BASE(STL_MT19937, uint_fast32_t) 115 | B_PRNG_BASE(STL_MT19937_64, uint_fast64_t) 116 | B_PRNG_BASE(STL_RANLUX24, uint_fast32_t) 117 | B_PRNG_BASE(STL_RANLUX48, uint_fast64_t) 118 | B_PRNG_BASE(STL_KNUTH_B, uint_fast32_t) 119 | 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /docs/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["generators","index","installation","machines","quickstart"],envversion:50,filenames:["generators.rst","index.rst","installation.rst","machines.rst","quickstart.rst"],objects:{machine:{pull:[3,0,1,""],push:[3,0,1,""],reset:[3,0,1,""],set_key:[3,0,1,""],set_space:[3,0,1,""],set_time:[3,0,1,""]}},objnames:{"0":["py","function","Python function"]},objtypes:{"0":"py:function"},terms:{"02x":3,"08x":3,"0x11":3,"0x11223344":0,"0x14":[3,4],"0x15":[3,4],"0x22":3,"0x32":[3,4],"0x33":3,"0x35":[3,4],"0x44":3,"0x65":[3,4],"0x79":[3,4],"0x89":[3,4],"0x8a5cd789635d2dff":0,"0x92":[3,4],"byte":[3,4],"char":3,"class":3,"default":[0,3],"final":4,"function":1,"int":[3,4],"null":3,"public":4,"return":[0,3],"short":4,"true":3,"void":[3,4],"while":[3,4],PRs:4,That:[3,4],The:[1,3,4],Then:[2,4],There:3,These:4,__default_kei:3,about:1,abov:0,absorb:3,action:3,adapt:3,add:[2,4],addit:3,adventur:1,after:[3,4],aim:3,algorithm:[0,3,4],all:[2,3],alloc:[3,4],allow:4,alpha:1,alreadi:4,also:[3,4],analyz:4,ani:4,anoth:0,anyth:3,api:[1,4],appli:[1,3],applicat:1,approxim:0,area:4,argc:3,argv:3,ask:1,assum:4,attack:3,authent:3,automat:2,avalanch:3,background:1,base:3,basic:1,bchao:4,becaus:[0,3,4],been:3,befor:4,begin:[1,3,4],below:3,benchmark:[1,2],benefit:3,big:3,bit:3,bitstr:[3,4],bolor:3,bps:3,branch:4,brew:2,buffer:3,bug:1,build:[2,4],calcul:3,call:[0,2],can:[1,3,4],case_name:4,chang:[3,4],changelog:4,chao:[0,1],chaos_machine_ncg:3,chaos_prng_kiss:0,chaos_prng_xoroshiro128plus:0,check:[1,3],clear:3,clock:3,clone:2,cmake:2,cmp:3,code:[1,3,4],collect:3,com:2,combin:3,command:4,comment:4,common:3,compar:3,comparison:3,compat:3,compil:[2,4],complet:0,complex:3,comput:[1,3],concomitantli:3,condit:3,configur:3,constant:3,construct:3,contain:[2,3,4],contribut:[1,2],contributor:4,control:3,core:1,cost:3,could:4,cover:4,cpp:4,creat:[1,2,3],csv:4,ctime:3,current:4,customiz:[1,3],data:4,date:2,defin:3,describ:4,descript:4,design:[1,3],determin:[0,3],determinist:3,dev:3,develop:1,diehard:3,diff:4,differ:3,digest:[3,4],directli:4,discuss:3,distribut:1,dive:1,dlibchaos_enable_testing:[2,4],document:[1,4],doe:3,dolor:[3,4],download:2,drawback:3,driven:4,dure:3,dynam:3,each:3,earli:[1,4],easi:1,easier:4,effect:3,emphasi:3,empti:3,end:[3,4],engag:3,engin:[3,4],engine:1,eprint:[0,3],everi:1,evolut:3,execut:[2,3,4],extern:3,extra:3,extractor:[1,3],fake_dev_random:3,fake_hash_funct:3,featur:1,feedback:4,feel:[1,4],figur:4,file:[2,4],filenam:4,find:1,first:4,fix:[3,4],flow:4,focus:1,follow:4,fork:4,format:3,free:[1,4],from:3,further:2,futur:2,gen:0,gen_class:0,get:[1,2,4],git:2,github:[1,2,4],give:4,gnuplot:[1,4],good:4,googl:[2,4],graph:4,hard:3,hardwar:1,has:[2,3],have:[1,2,4],head:4,header:[3,4],help:[1,4],hexadecim:3,high:[0,3],highlight:4,his:3,hold:3,homebrew:2,how:[3,4],howev:3,http:[0,3],huge:3,iacr:[0,3],idea:[1,2,3],illustr:1,implement:[1,3],includ:[1,3,4],increas:3,indic:3,inflict:3,inform:1,initi:[0,3,4],instal:[2,4],install_manifest:2,installat:1,instruct:1,introduct:4,iostream:[3,4],ipsum:[3,4],irc:1,issue:1,its:[2,3],keep:3,kei:3,know:4,languag:1,larger:3,last:3,later:3,latest:3,lchao:4,length:3,less:4,let:4,level:3,librari:1,life:4,like:[3,4],limit:3,line:4,linecolor:4,link:[1,4],longer:3,lorem:[3,4],lot:4,low:3,mac:3,machin:1,maciejczyzewski:2,main:[3,4],mainli:3,major:4,make:[2,3,4],mani:3,manual:1,manuali:4,master:4,mathemat:3,medium:3,memori:3,merg:4,messag:[3,4],messi:4,minim:1,mkdir:2,modern:1,modifi:3,modul:3,modular:[1,3],mostli:1,much:1,name:4,namespac:4,ncg:[3,4],need:[1,2,3,4],newer:2,next:0,nice:4,nist:3,note:4,notitl:4,octet:3,ones:3,onli:[1,4],open:1,oper:3,option:[0,4],oracl:3,org:[0,3],other:4,our:[3,4],out:[0,1,4],output:0,over:4,own:[2,3],packag:2,page:4,paramet:1,part:1,particular:4,pass:3,patch:2,pattern:4,pdf:0,perform:3,period:[0,3],piec:1,place:[1,3,4],plan:2,pleas:[1,4],plot:4,plt:4,point:4,points_x_i:4,portabl:4,possibl:[1,3],post:1,power:3,prefer:3,present:[1,3],primarili:3,primit:3,print:[3,4],printf:[3,4],prng:0,probabl:1,problem:1,procedur:3,produc:3,program:1,progress:4,project:1,properli:1,properti:[0,3],prose:1,provid:[1,3,4],pull:[3,4],purpos:3,push:[3,4],putc_unlock:3,qualiti:[0,3],quantiti:3,question:1,quickstart:1,rang:1,rank:4,rankit:4,reach:1,read:[3,4],readabl:4,readi:[1,4],receiv:4,recurs:2,red:4,reddit:3,rel:0,report:1,repositori:[1,3,4],request:4,requir:[2,3,4],research:1,resist:3,result:[3,4],rgb:4,round:3,same:3,sampl:1,scheme:[1,3],scientif:1,second:3,secret:3,secret_kei:3,section:4,secur:3,see:[1,4],seed:[0,3],select:3,sens:3,sensit:[1,3],sent:4,separ:4,sequenc:[0,3],serv:3,set:0,set_kei:3,set_spac:3,set_tim:3,shortcut:[0,3],should:4,show:3,simpl:[3,4],simpli:[2,4],sit:[3,4],size:[3,4],size_cel:3,size_next:0,size_pul:3,size_push:3,size_t:[3,4],slow:3,small:0,softwar:1,some:[1,4],someth:4,sort:4,sourc:[1,3],space:3,specif:[1,3],speed:[0,3],stabl:2,stackoverflow:1,stage:1,start:[2,3,4],static_cast:3,std:[3,4],stdout:3,step:1,still:[1,3],stl:3,stop:3,string:[3,4],submit:4,submodul:2,summari:1,support:2,sure:[1,2,4],svg:4,system:3,tag:1,take:3,target:[2,4],tchao:4,templat:3,termin:4,test:[1,2,3],test_name:4,testu01:3,thei:3,theori:3,therefor:3,thi:[1,2,3,4],thing:4,three:3,time:3,titl:4,tool:4,tri:1,truli:0,txt:2,type:3,uint32_t:[0,3],uint64_t:0,uint8_t:[3,4],uninstal:1,uniqu:3,univers:[1,3],update:4,use:[1,3,4],used:[3,4],uses:[2,3,4],using:[3,4],usual:4,util:[1,4],valu:[0,3],variabl:[3,4],vector:[3,4],veri:[3,4],version:[1,2,3],visibl:4,visual:4,wai:3,wall:3,welcom:[2,4],what:1,when:[2,4],where:[1,2,3,4],which:[1,2,3],whole:4,whose:0,why:4,wide:1,work:[1,3,4],wrap:4,write:4,written:1,x_machin:[3,4],xoroshiro1024star:0,xoroshiro128plu:0,xrang:4,xxd:3,y_result:[3,4],y_secret:[3,4],y_string:[3,4],y_vector:[3,4],you:[1,2,4],your:4,yrang:4},titles:["Pseudo-Random Number Generator","libchaos: randomization, hashing and statistical analysis","Installation","Chaos Machines","Quickstart"],titleterms:{"case":0,"function":3,abyssinian:0,adapter:[0,3],advanc:0,analysi:1,applicat:3,basic:2,benchmark:4,chao:3,contribut:4,cryptograph:3,czyzewski:3,engine:3,exampl:0,famili:3,futur:4,gener:[0,3],guid:1,hash:[1,3],idea:4,initial:3,input:3,installat:2,interfac:[0,3],kiss:0,libchao:1,librari:2,list:[0,3],machin:3,manual:2,minim:4,naiv:3,number:0,output:3,paramet:3,program:4,project:4,pseudo:[0,3],quickstart:4,random:[0,1,3],reset:3,sampl:3,set:3,state:3,statist:1,test:4,todo:2,typic:0,uninstal:2,user:1,xoroshiro1024:0,xoroshiro128:0,xorspac:3}}) -------------------------------------------------------------------------------- /docs/installation.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Installation — libchaos 0.0.1-dev documentation 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 |
38 |
39 |
40 |
41 | 42 |
43 |

Installation

44 |

Library needs C++ compiler that supports C++11. You will need g++ 4.7 or newer to get started, so be sure to have an up-to-date compiler.

45 |
46 |

Todo

47 |

Add this library to Homebrew. Then simply $ brew install libchaos to install this package on OS X. This is future idea, when library will have stable version.

48 |
49 |
50 |

Basic Installation

51 |
$ git clone git@github.com:maciejczyzewski/libchaos.git
 52 | $ cd libchaos && ./install.sh
 53 | 
54 |
55 |
56 |
57 |

Manual Installation

58 |

We welcome patches. If you plan to contribute a patch, you need to build libchaos and its own tests, which has further requirements:

59 | 63 |
$ git clone --recursive git@github.com:maciejczyzewski/libchaos.git
 64 | $ mkdir libchaos/build && cd "$_"
 65 | $ cmake -DLIBCHAOS_ENABLE_TESTING=ON ..
 66 | $ make && make install
 67 | 
68 |
69 |
70 |
71 |

Uninstalling Library

72 |

CMake creates a file called install_manifest.txt when executing the install target. This contains a list of all installed files.

73 |
$ make uninstall # where is install_manifest.txt
 74 | 
75 |
76 |
77 |
78 | 79 | 80 |
81 |
82 |
83 | 123 |
124 |
125 | 129 | 130 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = . 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 16 | 17 | .PHONY: help 18 | help: 19 | @echo "Please use \`make ' where is one of" 20 | @echo " html to make standalone HTML files" 21 | @echo " dirhtml to make HTML files named index.html in directories" 22 | @echo " singlehtml to make a single large HTML file" 23 | @echo " pickle to make pickle files" 24 | @echo " json to make JSON files" 25 | @echo " htmlhelp to make HTML files and a HTML help project" 26 | @echo " qthelp to make HTML files and a qthelp project" 27 | @echo " applehelp to make an Apple Help Book" 28 | @echo " devhelp to make HTML files and a Devhelp project" 29 | @echo " epub to make an epub" 30 | @echo " epub3 to make an epub3" 31 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 32 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 33 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 34 | @echo " text to make text files" 35 | @echo " man to make manual pages" 36 | @echo " texinfo to make Texinfo files" 37 | @echo " info to make Texinfo files and run them through makeinfo" 38 | @echo " gettext to make PO message catalogs" 39 | @echo " changes to make an overview of all changed/added/deprecated items" 40 | @echo " xml to make Docutils-native XML files" 41 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 42 | @echo " linkcheck to check all external links for integrity" 43 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 44 | @echo " coverage to run coverage check of the documentation (if enabled)" 45 | @echo " dummy to check syntax errors of document sources" 46 | 47 | .PHONY: clean 48 | clean: 49 | rm -rf $(BUILDDIR)/* 50 | 51 | .PHONY: html 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | .PHONY: dirhtml 58 | dirhtml: 59 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 60 | @echo 61 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 62 | 63 | .PHONY: singlehtml 64 | singlehtml: 65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 66 | @echo 67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 68 | 69 | .PHONY: pickle 70 | pickle: 71 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 72 | @echo 73 | @echo "Build finished; now you can process the pickle files." 74 | 75 | .PHONY: json 76 | json: 77 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 78 | @echo 79 | @echo "Build finished; now you can process the JSON files." 80 | 81 | .PHONY: htmlhelp 82 | htmlhelp: 83 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 84 | @echo 85 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 86 | ".hhp project file in $(BUILDDIR)/htmlhelp." 87 | 88 | .PHONY: qthelp 89 | qthelp: 90 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 91 | @echo 92 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 93 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 94 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/machines.qhcp" 95 | @echo "To view the help file:" 96 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/machines.qhc" 97 | 98 | .PHONY: applehelp 99 | applehelp: 100 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 101 | @echo 102 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 103 | @echo "N.B. You won't be able to view it unless you put it in" \ 104 | "~/Library/Documentation/Help or install it in your application" \ 105 | "bundle." 106 | 107 | .PHONY: devhelp 108 | devhelp: 109 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 110 | @echo 111 | @echo "Build finished." 112 | @echo "To view the help file:" 113 | @echo "# mkdir -p $$HOME/.local/share/devhelp/machines" 114 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/machines" 115 | @echo "# devhelp" 116 | 117 | .PHONY: epub 118 | epub: 119 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 120 | @echo 121 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 122 | 123 | .PHONY: epub3 124 | epub3: 125 | $(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3 126 | @echo 127 | @echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3." 128 | 129 | .PHONY: latex 130 | latex: 131 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 132 | @echo 133 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 134 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 135 | "(use \`make latexpdf' here to do that automatically)." 136 | 137 | .PHONY: latexpdf 138 | latexpdf: 139 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 140 | @echo "Running LaTeX files through pdflatex..." 141 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 142 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 143 | 144 | .PHONY: latexpdfja 145 | latexpdfja: 146 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 147 | @echo "Running LaTeX files through platex and dvipdfmx..." 148 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 149 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 150 | 151 | .PHONY: text 152 | text: 153 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 154 | @echo 155 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 156 | 157 | .PHONY: man 158 | man: 159 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 160 | @echo 161 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 162 | 163 | .PHONY: texinfo 164 | texinfo: 165 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 166 | @echo 167 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 168 | @echo "Run \`make' in that directory to run these through makeinfo" \ 169 | "(use \`make info' here to do that automatically)." 170 | 171 | .PHONY: info 172 | info: 173 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 174 | @echo "Running Texinfo files through makeinfo..." 175 | make -C $(BUILDDIR)/texinfo info 176 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 177 | 178 | .PHONY: gettext 179 | gettext: 180 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 181 | @echo 182 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 183 | 184 | .PHONY: changes 185 | changes: 186 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 187 | @echo 188 | @echo "The overview file is in $(BUILDDIR)/changes." 189 | 190 | .PHONY: linkcheck 191 | linkcheck: 192 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 193 | @echo 194 | @echo "Link check complete; look for any errors in the above output " \ 195 | "or in $(BUILDDIR)/linkcheck/output.txt." 196 | 197 | .PHONY: doctest 198 | doctest: 199 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 200 | @echo "Testing of doctests in the sources finished, look at the " \ 201 | "results in $(BUILDDIR)/doctest/output.txt." 202 | 203 | .PHONY: coverage 204 | coverage: 205 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 206 | @echo "Testing of coverage in the sources finished, look at the " \ 207 | "results in $(BUILDDIR)/coverage/python.txt." 208 | 209 | .PHONY: xml 210 | xml: 211 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 212 | @echo 213 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 214 | 215 | .PHONY: pseudoxml 216 | pseudoxml: 217 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 218 | @echo 219 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 220 | 221 | .PHONY: dummy 222 | dummy: 223 | $(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy 224 | @echo 225 | @echo "Build finished. Dummy builder generates no files." 226 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8.7 FATAL_ERROR) 2 | 3 | SET(CMAKE_BUILD_TYPE Release ... FORCE) 4 | 5 | OPTION(LIBCHAOS_ENABLE_TESTING 6 | "Enable testing & benchmarking of the libchaos library." ON) 7 | 8 | IF(POLICY CMP0050) 9 | CMAKE_POLICY(SET CMP0050 OLD) 10 | ENDIF() 11 | 12 | # Setting C++11 standard as default. 13 | SET(CMAKE_CXX_STANDARD 11) 14 | SET(CMAKE_CXX_STANDARD_REQUIRED ON) 15 | SET(CMAKE_DISABLE_SOURCE_CHANGES ON) 16 | SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON) 17 | 18 | # Disable in-source builds. 19 | IF("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") 20 | MESSAGE(FATAL_ERROR 21 | "In-source builds are not allowed. Please use ./install.sh to choose a build directory and initialize the build configuration. \n") 22 | ENDIF() 23 | 24 | # == BASICS ==================================================================== 25 | 26 | PROJECT(libchaos C CXX ASM) 27 | 28 | # Package information. 29 | SET(PACKAGE_NAME "libchaos") 30 | SET(PACKAGE_VERSION "1.1-dev") 31 | SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") 32 | SET(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") 33 | SET(PACKAGE_BUGREPORT "https://github.com/maciejczyzewski/libchaos/issues") 34 | 35 | MARK_AS_ADVANCED(CLEAR CMAKE_INSTALL_PREFIX) 36 | IF(APPLE) 37 | # CMake really likes finding libraries inside OS X frameworks. This can 38 | # create super unexpected results, such as the LDAP framework, where the 39 | # ldap.h header there just consists of "#include " -- obviously 40 | # assuming /usr/include appears on the include path before that framework 41 | # (which wasn't really supposed to be on the include path at all). This 42 | # leads to a hilarious recursive include and general fireworks. Instead, 43 | # tell CMake to search frameworks *last*, if it doesn't find something in 44 | # /usr (or MacPorts/Homebrew). 45 | SET(CMAKE_FIND_FRAMEWORK "LAST") 46 | MARK_AS_ADVANCED(CMAKE_OSX_ARCHITECTURES 47 | CMAKE_OSX_DEPLOYMENT_TARGET 48 | CMAKE_OSX_SYSROOT) 49 | ENDIF() 50 | 51 | CONFIGURE_FILE( 52 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" 53 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" 54 | IMMEDIATE @ONLY) 55 | 56 | ADD_CUSTOM_TARGET(uninstall 57 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) 58 | 59 | # == DISTRIBUTION ============================================================== 60 | 61 | # Tarball information. 62 | SET(CPACK_SOURCE_GENERATOR "ZIP;TGZ") 63 | SET(CPACK_PACKAGE_NAME ${PACKAGE_NAME}) 64 | SET(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION}) 65 | SET(CPACK_SOURCE_PACKAGE_FILE_NAME ${PACKAGE_TARNAME}) 66 | SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY ${PACKAGE_STRING}) 67 | SET(CPACK_SOURCE_IGNORE_FILES "/build/;/.bzr/;~$;${CPACK_SOURCE_IGNORE_FILES}") 68 | 69 | # Package generator. 70 | INCLUDE(CPack) 71 | 72 | ADD_CUSTOM_TARGET(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) 73 | 74 | # == FLAGS ===================================================================== 75 | 76 | ADD_COMPILE_OPTIONS( 77 | -std=c++11 78 | -Wall -Wextra 79 | -Wstrict-aliasing 80 | -Wunreachable-code 81 | -O3 -flto 82 | -mtune=native 83 | -march=native 84 | ) 85 | 86 | # == COMPONENTS ================================================================ 87 | 88 | # Find the appropriate compiler. 89 | IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") 90 | EXECUTE_PROCESS( 91 | COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) 92 | IF(NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7)) 93 | MESSAGE(FATAL_ERROR "Project requires g++ 4.7 or greater.") 94 | ENDIF() 95 | ELSEIF("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") 96 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") 97 | ELSE() 98 | MESSAGE(FATAL_ERROR "Your C++ compiler does not support C++11.") 99 | ENDIF() 100 | 101 | # Enable ccache if present and not already enabled system wide. 102 | OPTION(SKIP_CCACHE 103 | "Skip enabling for ccache - no effect if ccache enabled system wide" OFF) 104 | IF(NOT SKIP_CCACHE) 105 | FIND_PROGRAM(CCACHE_FOUND ccache) 106 | IF(CCACHE_FOUND) 107 | IF(NOT ("${CMAKE_CXX_COMPILER} ${CMAKE_C_COMPILER}" MATCHES ".*ccache.*")) 108 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND}) 109 | set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND}) 110 | MESSAGE(STATUS 111 | "Found ccache: ${CCACHE_FOUND} - enabling ccache as compiler wrapper") 112 | ELSE() 113 | MESSAGE(STATUS 114 | "Found ccache - ccache already in use as C and/or CXX compiler wrapper") 115 | ENDIF() 116 | ENDIF(CCACHE_FOUND) 117 | ENDIF(NOT SKIP_CCACHE) 118 | 119 | # == BUILD ===================================================================== 120 | 121 | # API 122 | FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/api DESTINATION ${CMAKE_BINARY_DIR}) 123 | 124 | # Docs 125 | FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/docs DESTINATION ${CMAKE_BINARY_DIR}) 126 | 127 | # Tests 128 | FILE(COPY ${CMAKE_CURRENT_SOURCE_DIR}/tests DESTINATION ${CMAKE_BINARY_DIR}) 129 | 130 | ################################################################################## 131 | # add_executable(_testu01 src/_testu01.cpp) ###################################### 132 | # target_link_libraries (_testu01 chaos testu01 probdist mylib m) ################ 133 | ################################################################################## 134 | 135 | ################################################################################## 136 | # add_executable(_sandbox src/_sandbox.cpp) ###################################### 137 | # target_link_libraries (_sandbox chaos testu01 probdist mylib m) ################ 138 | ################################################################################## 139 | 140 | ################################################################################## 141 | # add_executable(chaosdeep src/chaosdeep.cpp) #################################### 142 | # target_link_libraries (chaosdeep chaos) ######################################## 143 | ################################################################################## 144 | 145 | # == LIBRARY =================================================================== 146 | 147 | FILE(GLOB_RECURSE FILES src/*.cc) 148 | ADD_LIBRARY(chaos ${FILES}) 149 | 150 | # Define headers for library. PUBLIC headers are used for compiling 151 | # the library, and will be added to client build paths. 152 | TARGET_INCLUDE_DIRECTORIES(chaos PUBLIC 153 | $ 154 | $ 155 | PRIVATE src) 156 | 157 | # If we have compiler requirements for library, list them here. 158 | TARGET_COMPILE_FEATURES(chaos 159 | PUBLIC cxx_auto_type 160 | PRIVATE cxx_variadic_templates) 161 | 162 | # Installation 'make install' to the correct location. 163 | INSTALL(TARGETS chaos 164 | ARCHIVE DESTINATION lib 165 | LIBRARY DESTINATION lib 166 | RUNTIME DESTINATION bin) # Windows 167 | INSTALL(DIRECTORY include/ DESTINATION include) 168 | 169 | # Cross-platform tool to compute hashes. (FIXME) 170 | # INSTALL(TARGETS chaosdeep RUNTIME DESTINATION bin) 171 | 172 | # This makes the project importable from the build directory. 173 | EXPORT(TARGETS chaos FILE ChaosConfig.cmake) 174 | 175 | ## == FINAL ==================================================================== 176 | 177 | # Show build configuration overview. 178 | MESSAGE("\n[${PACKAGE_NAME} v${PACKAGE_VERSION}]\n 179 | ## compiler | ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} 180 | ## flags | ${CMAKE_CXX_FLAGS} 181 | ## build dir | ${CMAKE_BINARY_DIR} 182 | ## install prefix | ${CMAKE_INSTALL_PREFIX} 183 | ## testing | ${LIBCHAOS_ENABLE_TESTING} 184 | ") 185 | 186 | IF(LIBCHAOS_ENABLE_TESTING) ######################################### TESTING ## 187 | ENABLE_TESTING() 188 | 189 | ## == TESTS: TESTING =========================================================== 190 | # https://github.com/google/googletest 191 | 192 | # Configuring library. 193 | SET(GMOCK_BUILD_TESTS OFF CACHE BOOL 194 | "Enable testing of the testing library.") 195 | 196 | # External package for testing. 197 | ADD_SUBDIRECTORY(deps/googletest EXCLUDE_FROM_ALL) 198 | INCLUDE_DIRECTORIES(${GTEST_SOURCE_DIR}/include ${GTEST_SOURCE_DIR}) 199 | 200 | # All files containing tests should be listed here. 201 | FILE(GLOB FILES tests/t_*.cc) 202 | ADD_EXECUTABLE(tchaos cmake/googletest_header.cc ${FILES}) 203 | 204 | # Linking our libchaos and libgtest. 205 | TARGET_LINK_LIBRARIES(tchaos chaos 206 | gtest gtest_main gmock gmock_main) 207 | 208 | # Final tests (TODO: split to engines/library tests). 209 | ADD_TEST(tchaos tchaos) 210 | 211 | ## == TESTS: BENCHMARKING ====================================================== 212 | # https://github.com/google/benchmark 213 | 214 | # Configuring library. 215 | SET(CMAKE_BUILD_TYPE Release) 216 | SET(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL 217 | "Enable testing of the benchmarking library.") 218 | 219 | # External package for benchmarking. 220 | ADD_SUBDIRECTORY(deps/benchmark EXCLUDE_FROM_ALL) 221 | INCLUDE_DIRECTORIES(${BENCH_SOURCE_DIR}/include ${BENCH_SOURCE_DIR}) 222 | 223 | # All files containing tests should be listed here. 224 | FILE(GLOB FILES tests/b_*.cc) 225 | ADD_EXECUTABLE(bchaos cmake/benchmark_header.cc ${FILES}) 226 | 227 | # Linking our libchaos and libgtest. 228 | TARGET_LINK_LIBRARIES(bchaos chaos 229 | benchmark) 230 | 231 | # Final tests (TODO: split to engines/library tests). 232 | ADD_TEST(bchaos bchaos) 233 | 234 | ENDIF() ############################################################# TESTING ## 235 | -------------------------------------------------------------------------------- /docs/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s == 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node) { 70 | if (node.nodeType == 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { 74 | var span = document.createElement("span"); 75 | span.className = className; 76 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 77 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 78 | document.createTextNode(val.substr(pos + text.length)), 79 | node.nextSibling)); 80 | node.nodeValue = val.substr(0, pos); 81 | } 82 | } 83 | else if (!jQuery(node).is("button, select, textarea")) { 84 | jQuery.each(node.childNodes, function() { 85 | highlight(this); 86 | }); 87 | } 88 | } 89 | return this.each(function() { 90 | highlight(this); 91 | }); 92 | }; 93 | 94 | /* 95 | * backward compatibility for jQuery.browser 96 | * This will be supported until firefox bug is fixed. 97 | */ 98 | if (!jQuery.browser) { 99 | jQuery.uaMatch = function(ua) { 100 | ua = ua.toLowerCase(); 101 | 102 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 103 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 104 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 105 | /(msie) ([\w.]+)/.exec(ua) || 106 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 107 | []; 108 | 109 | return { 110 | browser: match[ 1 ] || "", 111 | version: match[ 2 ] || "0" 112 | }; 113 | }; 114 | jQuery.browser = {}; 115 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 116 | } 117 | 118 | /** 119 | * Small JavaScript module for the documentation. 120 | */ 121 | var Documentation = { 122 | 123 | init : function() { 124 | this.fixFirefoxAnchorBug(); 125 | this.highlightSearchWords(); 126 | this.initIndexTable(); 127 | 128 | }, 129 | 130 | /** 131 | * i18n support 132 | */ 133 | TRANSLATIONS : {}, 134 | PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, 135 | LOCALE : 'unknown', 136 | 137 | // gettext and ngettext don't access this so that the functions 138 | // can safely bound to a different name (_ = Documentation.gettext) 139 | gettext : function(string) { 140 | var translated = Documentation.TRANSLATIONS[string]; 141 | if (typeof translated == 'undefined') 142 | return string; 143 | return (typeof translated == 'string') ? translated : translated[0]; 144 | }, 145 | 146 | ngettext : function(singular, plural, n) { 147 | var translated = Documentation.TRANSLATIONS[singular]; 148 | if (typeof translated == 'undefined') 149 | return (n == 1) ? singular : plural; 150 | return translated[Documentation.PLURALEXPR(n)]; 151 | }, 152 | 153 | addTranslations : function(catalog) { 154 | for (var key in catalog.messages) 155 | this.TRANSLATIONS[key] = catalog.messages[key]; 156 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 157 | this.LOCALE = catalog.locale; 158 | }, 159 | 160 | /** 161 | * add context elements like header anchor links 162 | */ 163 | addContextElements : function() { 164 | $('div[id] > :header:first').each(function() { 165 | $('\u00B6'). 166 | attr('href', '#' + this.id). 167 | attr('title', _('Permalink to this headline')). 168 | appendTo(this); 169 | }); 170 | $('dt[id]').each(function() { 171 | $('\u00B6'). 172 | attr('href', '#' + this.id). 173 | attr('title', _('Permalink to this definition')). 174 | appendTo(this); 175 | }); 176 | }, 177 | 178 | /** 179 | * workaround a firefox stupidity 180 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 181 | */ 182 | fixFirefoxAnchorBug : function() { 183 | if (document.location.hash) 184 | window.setTimeout(function() { 185 | document.location.href += ''; 186 | }, 10); 187 | }, 188 | 189 | /** 190 | * highlight the search words provided in the url in the text 191 | */ 192 | highlightSearchWords : function() { 193 | var params = $.getQueryParameters(); 194 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 195 | if (terms.length) { 196 | var body = $('div.body'); 197 | if (!body.length) { 198 | body = $('body'); 199 | } 200 | window.setTimeout(function() { 201 | $.each(terms, function() { 202 | body.highlightText(this.toLowerCase(), 'highlighted'); 203 | }); 204 | }, 10); 205 | $('') 207 | .appendTo($('#searchbox')); 208 | } 209 | }, 210 | 211 | /** 212 | * init the domain index toggle buttons 213 | */ 214 | initIndexTable : function() { 215 | var togglers = $('img.toggler').click(function() { 216 | var src = $(this).attr('src'); 217 | var idnum = $(this).attr('id').substr(7); 218 | $('tr.cg-' + idnum).toggle(); 219 | if (src.substr(-9) == 'minus.png') 220 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 221 | else 222 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 223 | }).css('display', ''); 224 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 225 | togglers.click(); 226 | } 227 | }, 228 | 229 | /** 230 | * helper function to hide the search marks again 231 | */ 232 | hideSearchWords : function() { 233 | $('#searchbox .highlight-link').fadeOut(300); 234 | $('span.highlighted').removeClass('highlighted'); 235 | }, 236 | 237 | /** 238 | * make the url absolute 239 | */ 240 | makeURL : function(relativeURL) { 241 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 242 | }, 243 | 244 | /** 245 | * get the current relative url 246 | */ 247 | getCurrentURL : function() { 248 | var path = document.location.pathname; 249 | var parts = path.split(/\//); 250 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 251 | if (this == '..') 252 | parts.pop(); 253 | }); 254 | var url = parts.join('/'); 255 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 256 | }, 257 | 258 | initOnKeyListeners: function() { 259 | $(document).keyup(function(event) { 260 | var activeElementType = document.activeElement.tagName; 261 | // don't navigate when in search box or textarea 262 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') { 263 | switch (event.keyCode) { 264 | case 37: // left 265 | var prevHref = $('link[rel="prev"]').prop('href'); 266 | if (prevHref) { 267 | window.location.href = prevHref; 268 | return false; 269 | } 270 | case 39: // right 271 | var nextHref = $('link[rel="next"]').prop('href'); 272 | if (nextHref) { 273 | window.location.href = nextHref; 274 | return false; 275 | } 276 | } 277 | } 278 | }); 279 | } 280 | }; 281 | 282 | // quick alias for translations 283 | _ = Documentation.gettext; 284 | 285 | $(document).ready(function() { 286 | Documentation.init(); 287 | }); -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | libchaos: randomization, hashing and statistical analysis — libchaos 0.0.1-dev documentation 10 | 11 | 12 | 13 | 14 | 24 | 25 | 26 | 27 | 28 | 31 | 32 | 33 | 34 | 35 | 36 |
37 |
38 |
39 |
40 | 41 |
42 |

libchaos: randomization, hashing and statistical analysis

43 |

Libchaos is a computing library written in C++ language to help with the development of software for scientific research. The library tries to be as general as possible, modern and easy-to-use.

44 |

Project implements wide range of chaos machines, which presents the idea to create a universal scheme with modular design and customizable parameters, that can be applied where randomness and sensitiveness is needed.

45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 |
lorenz_3dlorenz_time
56 |

A summary of core features:

57 |
58 | 66 |
67 |

68 |

Getting Help

69 |

If you have questions about the library, please be sure to check out the API documentation. If you still have questions, reach out to us on IRC or post a question on StackOverflow (with the libchaos tag).

70 |

Reporting Bugs

71 |

Please open a GitHub Issue and include as much information as possible. If possible, provide sample code that illustrates the problem you’re seeing. If you’re seeing a bug only on a specific repository, please provide a link to it if possible.

72 |

We ask that you not open a GitHub Issue for help, only for bug reports.

73 |
74 |

User’s Guide

75 |
76 |

Warning

77 |

This project is at an early stage of development, every piece of hardware and software is in alpha version, if you are an adventurer this is a place for you!

78 |

The list of core features is not ready. You need to dive into source code to find out what is working properly. If you have some ideas, feel free to contribute.

79 |
80 |

This part of the documentation, which is mostly prose, begins with some background information about libchaos, then focuses on step-by-step instructions for working with libchaos.

81 | 108 |
109 |
110 | 111 | 112 |
113 |
114 |
115 | 154 |
155 |
156 | 160 | 161 | -------------------------------------------------------------------------------- /docs/_static/underscore.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.3.1 2 | // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= 11 | b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | --------------------------------------------------------------------------------