diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..fc4ca4d0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,12 @@ +**/CmakeFiles/* +docs/* +documentation/* +out/* +Testing/* +models/* +dataset/* + +.idea/* +.vs/* +.vscode/* +.scannerwork/* \ No newline at end of file diff --git a/.github/action_helpers/actions_linux_python_libs.sh b/.github/action_helpers/actions_linux_python_libs.sh index 3b257f8e..c844d9cc 100644 --- a/.github/action_helpers/actions_linux_python_libs.sh +++ b/.github/action_helpers/actions_linux_python_libs.sh @@ -1,18 +1,22 @@ #!/bin/bash +pwd +whoami +ls /root/ -alR +ls /opt/ -alR # work inside include folder cd /opt/hostedtoolcache/Python/$1*/x64/include; echo "Working with python$1" # Create symlink without "m" in name -[[ -f "python$1" ]] || sudo ln -s python$1m python$1; +[[ -f "python$1" ]] || ln -s python$1m python$1; # copy libraries and includes to global paths -sudo cp -r /opt/hostedtoolcache/Python/$1*/x64/lib/* /usr/local/lib/; -sudo cp -r /opt/hostedtoolcache/Python/$1*/x64/include/py* /usr/include/; -sudo ln -s /usr/include/$1m /usr/include/$1; +cp -r /opt/hostedtoolcache/Python/$1*/x64/lib/* /usr/local/lib/; +cp -r /opt/hostedtoolcache/Python/$1*/x64/include/py* /usr/include/; +ln -s /usr/include/$1m /usr/include/$1; # Create symlink without "m" in name -[[ -f "/usr/local/lib/libpython$1.so.1.0" ]] || sudo ln -s /usr/local/lib/libpython$1m.so.1.0 /usr/local/lib/libpython$1.so.1.0; -[[ -f "/usr/local/lib/libpython$1.so" ]] || sudo ln -s /usr/local/lib/libpython$1m.so /usr/local/lib/libpython$1.so; +[[ -f "/usr/local/lib/libpython$1.so.1.0" ]] || ln -s /usr/local/lib/libpython$1m.so.1.0 /usr/local/lib/libpython$1.so.1.0; +[[ -f "/usr/local/lib/libpython$1.so" ]] || ln -s /usr/local/lib/libpython$1m.so /usr/local/lib/libpython$1.so; diff --git a/.github/action_helpers/actions_linux_setup_boost.sh b/.github/action_helpers/actions_linux_setup_boost.sh index deb89e2e..981eadbf 100644 --- a/.github/action_helpers/actions_linux_setup_boost.sh +++ b/.github/action_helpers/actions_linux_setup_boost.sh @@ -5,4 +5,4 @@ cd /home/runner/; tar -xf /home/runner/boost_1_76_0.tar.gz; cd /home/runner/boost_1_76_0/; ./bootstrap.sh --with-python=$(which python$1) --with-python-version=$1; -sudo ./b2 --with-python --with-program_options stage; \ No newline at end of file +./b2 --with-python --with-program_options stage; \ No newline at end of file diff --git a/.github/action_helpers/actions_linux_setup_libboost.sh b/.github/action_helpers/actions_linux_setup_libboost.sh index ced57da4..9e7925fd 100644 --- a/.github/action_helpers/actions_linux_setup_libboost.sh +++ b/.github/action_helpers/actions_linux_setup_libboost.sh @@ -1,4 +1,4 @@ #!/bin/bash -sudo cp -r /home/runner/boost_1_76_0/stage/lib/* /usr/local/lib; -sudo cp -r /home/runner/boost_1_76_0/boost /usr/include/boost; \ No newline at end of file +cp -r /home/runner/boost_1_76_0/stage/lib/* /usr/local/lib; +cp -r /home/runner/boost_1_76_0/boost /usr/include/boost; \ No newline at end of file diff --git a/.github/action_helpers/actions_windows_libpython.ps1 b/.github/action_helpers/actions_windows_libpython.ps1 index a07ab6b1..25d27dc8 100644 --- a/.github/action_helpers/actions_windows_libpython.ps1 +++ b/.github/action_helpers/actions_windows_libpython.ps1 @@ -3,6 +3,12 @@ param ( [string]$pythonver = "3.8" ) +$a = $pythonver.substring(0,1) +$b = $pythonver.substring(2,1) +echo "$a$b" +echo "set-output name=python_ver::$a$b" +echo "::set-output name=python_ver::$a$b" + which python; mkdir D:\a\python$pythonver; diff --git a/.github/action_helpers/build.py b/.github/action_helpers/build.py index 43b93794..aa234d4e 100644 --- a/.github/action_helpers/build.py +++ b/.github/action_helpers/build.py @@ -52,18 +52,20 @@ def set_action_outputs(**kwargs): if(args.step == "version_matrix"): if(a_type == "minor"): - lm = "[3.6, 3.7, 3.8, 3.9]" - wm = "[3.8, 3.9]" + lm = "[36, 37, 38, 39]" + wm = "[36, 37, 38, 39]" + wms = "[3.6, 3.7, 3.8, 3.9]" elif(a_type == "patch"): - lm = "[3.8]" - wm = "[3.8]" - + lm = "[38]" + wm = "[38]" + wms = "[3.8]" else: - lm = "[3.8]" - wm = "[3.8]" + lm = "[38]" + wm = "[38]" + wms = "[3.8]" - set_action_outputs(linux_matrix=lm, windows_matrix=wm) + set_action_outputs(linux_matrix=lm, windows_matrix=wm, windows_matrix_sep=wms) if(args.step == "linux_python_libs"): os.system(f".github/action_helpers/actions_linux_python_libs.sh {args.pyversion}") diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f66bc92c..6fc17130 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,6 +48,7 @@ jobs: runs-on: ubuntu-latest outputs: upload_url: ${{ steps.create_release.outputs.upload_url }} + tag: ${{ steps.tag_version.outputs.new_tag }} steps: - uses: actions/checkout@v2 @@ -81,98 +82,141 @@ jobs: runs-on: ubuntu-latest outputs: windows_matrix: ${{ steps.core.outputs.windows_matrix }} + windows_matrix_sep: ${{ steps.core.outputs.windows_matrix_sep }} linux_matrix: ${{ steps.core.outputs.linux_matrix }} steps: - uses: actions/checkout@v2 - name: Configure Version Matrix for Python id: core run: python3 ./.github/action_helpers/build.py version_matrix + + build_linux: - name: Build All on Linux with Makefile + name: Build python libraries on linux with CMake needs: [reversion, setup_build_matrix] runs-on: ubuntu-latest + container: ahakcil/markopy:0.5.0 strategy: matrix: python-version: ${{fromJson(needs.setup_build_matrix.outputs.linux_matrix) }} steps: - # Check cache for boost libraries - - name: Cache Boost - uses: actions/cache@v2 - id: cache-boost - with: - path: | - /home/runner/boost_1_76_0/stage - /home/runner/boost_1_76_0/boost - key: 'nix-boost-src-latest-py${{ matrix.python-version }}' - - # Checkout current commit - uses: actions/checkout@v2 - - # Set up Python - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} + - name: Compile CPP + run: | + ls -al; + cmake . -DPYTHON_VER=${{ matrix.python-version }} -DPARTIAL=1 -DB_LIBS=1 -DB_CUDA=1 -DPROJ_VERSION="${{ needs.reversion.outputs.tag }}" -DCMAKE_BUILD_TYPE=Release; + cmake --build . --config Release; + ls -alR out/; + ls -al /usr/local/lib; - # Link Python includes and libraries - - name: Set up libraries for Python ${{ matrix.python-version }} + - name: Zip library files # This would actually build your project, using zip for an example artifact + if: matrix.python-version == '38' run: | - chmod 755 ./.github/action_helpers/*; - ./.github/action_helpers/actions_linux_python_libs.sh ${{ matrix.python-version }} + zip --junk-paths libmarkov-${{ needs.reversion.outputs.tag }}-linux.zip out/lib/libmarkov.so out/bin/markovp + zip --junk-paths libcudamarkov-${{ needs.reversion.outputs.tag }}-linux.zip out/lib/libcudamarkov.so out/bin/cudamarkovp - # Setup boost - - name: Setup boost - if: steps.cache-boost.outputs.cache-hit != 'true' - run: ./.github/action_helpers/actions_linux_setup_boost.sh ${{ matrix.python-version }} - + - name: Zip models files # This would actually build your project, using zip for an example artifact + if: matrix.python-version == '38' + run: | + zip -r models-${{ needs.reversion.outputs.tag }}.zip models/* + + - name: Zip python files + run: | + mkdir markopy-linux; + mkdir cudamarkopy-linux; + cp out/lib/markopy.so out/lib/libmarkov.so Markopy/src/CLI/*.py /usr/local/lib/libboost_python${{ matrix.python-version }}*so.1* markopy-linux/ + zip -r markopy-${{ needs.reversion.outputs.tag }}-linux-py${{ matrix.python-version }}.so.zip markopy-linux + cp out/lib/markopy.so out/lib/libmarkov.so out/lib/libcudamarkov.so out/lib/cudamarkopy.so Markopy/src/CLI/*.py CudaMarkopy/src/CLI/*.py /usr/local/lib/libboost_python${{ matrix.python-version }}*so.1* cudamarkopy-linux/ + zip -r cudamarkopy-${{ needs.reversion.outputs.tag }}-linux-py${{ matrix.python-version }}.so.zip cudamarkopy-linux + + + - name: Upload LibMarkov + if: matrix.python-version == '38' + id: upload-release-asset-libmarkov + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.reversion.outputs.upload_url }} + asset_path: ./libmarkov-${{ needs.reversion.outputs.tag }}-linux.zip + asset_name: libmarkov-${{ needs.reversion.outputs.tag }}-linux.zip + asset_content_type: application/zip - - name: Link boost libraries - run: ./.github/action_helpers/actions_linux_setup_libboost.sh ${{ matrix.python-version }} + - name: Upload LibCudaMarkov + if: matrix.python-version == '38' + id: upload-release-asset-libcudamarkov + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.reversion.outputs.upload_url }} + asset_path: ./libcudamarkov-${{ needs.reversion.outputs.tag }}-linux.zip + asset_name: libcudamarkov-${{ needs.reversion.outputs.tag }}-linux.zip + asset_content_type: application/zip - - name: Compile CPP - run: make PYTHON_VERSION=${{ matrix.python-version }} all + - name: Upload Markopy + id: upload-release-asset-markopy + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.reversion.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./markopy-${{ needs.reversion.outputs.tag }}-linux-py${{ matrix.python-version }}.so.zip + asset_name: markopy-${{ needs.reversion.outputs.tag }}-linux-py${{ matrix.python-version }}.so.zip + asset_content_type: application/zip - - name: Zip built files # This would actually build your project, using zip for an example artifact - run: zip --junk-paths markopy-linux-py${{ matrix.python-version }}.so.zip Markopy/src/CLI/markopy_cli.py bin/markopy.so /usr/local/lib/libboost_python*.so.1.76.0 - - - name: Upload Release Asset - id: upload-release-asset + - name: Upload CudaMarkopy + id: upload-release-asset-cudamarkopy uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.reversion.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./markopy-linux-py${{ matrix.python-version }}.so.zip - asset_name: markopy-linux-py${{ matrix.python-version }}.so.zip + asset_path: ./cudamarkopy-${{ needs.reversion.outputs.tag }}-linux-py${{ matrix.python-version }}.so.zip + asset_name: cudamarkopy-${{ needs.reversion.outputs.tag }}-linux-py${{ matrix.python-version }}.so.zip asset_content_type: application/zip - MSBuild: - name: Build All on Windows with MSBuild + - name: Upload Models + id: upload-release-asset-models + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.reversion.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps + asset_path: ./models-${{ needs.reversion.outputs.tag }}.zip + asset_name: models-${{ needs.reversion.outputs.tag }}.zip + asset_content_type: application/zip + + + build_windows: + name: Build All on Windows with CMake needs: [reversion, setup_build_matrix] runs-on: windows-latest strategy: fail-fast: false - max-parallel: 3 + max-parallel: 4 matrix: - python-version: ${{ fromJson(needs.setup_build_matrix.outputs.windows_matrix) }} + #python-version: ${{ fromJson(needs.setup_build_matrix.outputs.windows_matrix) }} + python-version-sep: ${{ fromJson(needs.setup_build_matrix.outputs.windows_matrix_sep) }} steps: - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.python-version-sep }} uses: actions/setup-python@v2 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.python-version-sep }} - name: Link python libraries And clean boost ones - run: .\.github\action_helpers\actions_windows_libpython.ps1 -pythonver ${{ matrix.python-version }} + id: link_python + run: .\.github\action_helpers\actions_windows_libpython.ps1 -pythonver ${{ matrix.python-version-sep }} - name: Cache Boost uses: actions/cache@v2 id: cache-boost with: path: ${{env.GITHUB_ACTION_WIN_PROJECT}}\boost - key: 'windows-boost-1.76-markopy-${{ matrix.python-version }}' + key: 'windows-boost-1.76-markopy-${{ matrix.python-version-sep }}' - name: Build Boost id: boost @@ -186,39 +230,71 @@ jobs: - name: Rename boost static and dynamic libraries if: steps.cache-boost.outputs.cache-hit != 'true' - run: .\.github\action_helpers\actions_windows_libboost.ps1 -pythonver ${{ matrix.python-version }} + run: .\.github\action_helpers\actions_windows_libboost.ps1 -pythonver ${{ matrix.python-version-sep }} + + # These work, but take a damn hour to complete, if only github actions allowed custom containers + #- uses: Jimver/cuda-toolkit@v0.2.2 + # id: cuda-toolkit + # with: + # cuda: '11.2.2' + + #- name: Cache Qt + # id: cache-qt + # uses: actions/cache@v1 + # with: + # path: ../Qt + # key: ${{ runner.os }}-QtCache - - name: Add MSBuild to PATH - uses: microsoft/setup-msbuild@v1 + #- name: Install Qt + # uses: jurplel/install-qt-action@v2 + # with: + # modules: 'qtwebengine' + # cached: ${{ steps.cache-qt.outputs.cache-hit }} - #- name: Restore NuGet packages - # working-directory: ${{env.GITHUB_WORKSPACE}} - # run: nuget restore ${{env.SOLUTION_FILE_PATH}} - name: Build working-directory: ${{env.GITHUB_WORKSPACE}} - run: | - $env:PYTHON_PATH = "D:\a\python${{ matrix.python-version }}"; + $env:PYTHON_PATH = "D:\a\python${{ matrix.python-version-sep }}"; $env:BOOST_ROOT = "${{env.GITHUB_ACTION_WIN_PROJECT}}\boost"; - msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}} + cmake . -DPYTHON_VER=${{ steps.link_python.outputs.python_ver}} -DPARTIAL=1 -DBOOST_VER="1.76.0" -DPROJ_VERSION="${{ needs.reversion.outputs.tag }}" -DCMAKE_BUILD_TYPE=MinSizeRel -DPY_DEV_PATH="D:\a\python${{ matrix.python-version-sep }}" + cmake --build . --config Release; - name: Zip built files # This would actually build your project, using zip for an example artifact - run: - powershell "Compress-Archive Markopy/src/CLI/markopy_cli.py,x64/Release/markopy.pyd,${{env.GITHUB_ACTION_WIN_PROJECT}}\boost\stage\lib\boost_python*.dll markopy-windows-py${{ matrix.python-version }}.pyd.zip" + run: | + dir .; + dir out/; + dir out/lib/Release; + mkdir markopy-windows + copy-item -Path Markopy\src\CLI\*.py,out\lib\Release\markopy.pyd,${{env.GITHUB_ACTION_WIN_PROJECT}}\boost\stage\lib\boost_python*.dll -Destination markopy-windows\ + powershell "Compress-Archive markopy-windows markopy-${{ needs.reversion.outputs.tag }}-win64-py${{ steps.link_python.outputs.python_ver}}.pyd.zip" + powershell "Compress-Archive out\lib\Release\markov.lib libmarkov-${{ needs.reversion.outputs.tag }}-win64.zip" + + - name: Upload LibMarkov + if: matrix.python-version-sep == '3.8' + id: upload-release-asset-libmarkov + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.reversion.outputs.upload_url }} + asset_path: ./libmarkov-${{ needs.reversion.outputs.tag }}-win64.zip + asset_name: libmarkov-${{ needs.reversion.outputs.tag }}-win64.zip + asset_content_type: application/zip< - - - name: Upload Markopy Release Assets - id: upload-release-asset + - name: Upload Markopy + id: upload-release-asset-markopy uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.reversion.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps - asset_path: ./markopy-windows-py${{ matrix.python-version }}.pyd.zip - asset_name: markopy-windows-py${{ matrix.python-version }}.pyd.zip + asset_path: ./markopy-${{ needs.reversion.outputs.tag }}-win64-py${{ steps.link_python.outputs.python_ver}}.pyd.zip + asset_name: markopy-${{ needs.reversion.outputs.tag }}-win64-py${{ steps.link_python.outputs.python_ver}}.pyd.zip asset_content_type: application/zip + + #Integrity check on pull requests with sonar sonar: if: github.event_name == 'push' && github.ref == 'refs/heads/main' @@ -244,4 +320,4 @@ jobs: - name: Delete drafts uses: hugo19941994/delete-draft-releases@v0.1.0 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6473a3bf..33a54b5a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ ## ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore -*.txt # User-specific files *.rsuser *.suo @@ -359,7 +358,7 @@ MigrationBackup/ # Development models and datasets datasets/* -models/* +#models/* # Sample datasets Markopy/src/CLI/sample_datasets/* @@ -373,4 +372,32 @@ Markopy/src/CLI/markopy.so # Build shared object files include/*.so -nvsight/* \ No newline at end of file +#cuda performance reports +nvsight/* + +*.vcxproj +*.vcxproj.filters +*.sln + +#cmake ignores +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + + +#library files +lib/* + +out/**/* + +build/* +**/*_autogen/**/* + +**/ui_*.h \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..c365b9c3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,122 @@ +# CMakeList.txt : Top-level CMake project file, do global configuration +# and include sub-projects here. +# +cmake_minimum_required (VERSION 3.8) + +## BUILD EXAMPLES +# +# Build everything: +# $ cmake . -DPYTHON_VER=38 && cmake --build . +# +# This will build all the libraries and executables. Requires python-dev, CUDA, QT5, QT5-Webview +# +# Build libraries only: +# $ cmake . -DPARTIAL=1 -DB_LIBS=1 && cmake --build . +# +# Only build basic libraries. Requires only CXX compiler. +# +# Build CUDA-accelerated libraries: +# $ cmake . -DPARTIAL=1 -DB_CUDA=1 && cmake --build . +# +# Build libraries along with cuda accelerated ones. +# +# Build python module & libraries: +# $ cmake . -DPARTIAL=1 -DPYTHON_VER=39 && cmake --build . +# +# Will build basic libraries and python modules. +# +# Build CUDA accelerated python module: +# $ cmake . -DPARTIAL=1 -DPYTHON_VER=39 -DB_CUDA=1 && cmake --build . +# +# Will build cudamarkopy. +# +# Build CUDA accelerated python module and the GUI: +# $ cmake . -DPARTIAL=1 -DPYTHON_VER=39 -DB_CUDA=1 -DB_GUI && cmake --build . +# +# Combine methods +# +## + + +if(NOT PROJ_VERSION) + message("No version defined. Defaulting to 0.0.0") + set(PROJ_VERSION "0.0.0") +else() + message("Formatting version suffix") + string(REPLACE "-" ";0x" PROJ_VERSION_REP ${PROJ_VERSION}) + list(LENGTH PROJ_VERSION_REP len) + if(len GREATER 1) + list(GET PROJ_VERSION_REP 0 PROJ_VER_0) + list(GET PROJ_VERSION_REP 1 SUFFIX) + math(EXPR SUFFIX "${SUFFIX}*1") + set(PROJ_VERSION "${PROJ_VER_0}.${SUFFIX}") + endif() + +endif() + +message("Building version ${PROJ_VERSION}") + +project(Markopy LANGUAGES CXX VERSION "${PROJ_VERSION}" DESCRIPTION "Password generation toolset with markov chains") +if(NOT PARTIAL) + message("Building everything, including cuda") + enable_language(CUDA) + + + add_subdirectory ("MarkovModel") + add_subdirectory ("MarkovAPI") + add_subdirectory ("CudaMarkovAPI") + add_subdirectory ("MarkovAPICLI") + add_subdirectory ("Markopy") + add_subdirectory ("CudaMarkopy") + add_subdirectory ("MarkovPasswordsGUI") + +else() + if(B_GUI) + if(NOT B_LIBS) + set(B_LIBS 1) + endif() + endif() + if(B_CLI) + if(NOT B_LIBS) + set(B_LIBS 1) + endif() + endif() + if(B_CUDA) + enable_language(CUDA) + if(NOT B_LIBS) + set(B_LIBS 1) + endif() + endif() + if(PYTHON_VER) + if(NOT B_LIBS) + set(B_LIBS 1) + endif() + endif() + + if(B_LIBS) + message("Building libraries") + add_subdirectory ("MarkovAPI") + add_subdirectory ("MarkovModel") + endif() + if(B_CLI) + add_subdirectory ("MarkovAPICLI") + endif() + if(B_CUDA) + message("Building cuda libraries") + add_subdirectory ("CudaMarkovAPI") + endif() + if(B_GUI) + message("Building GUI") + add_subdirectory ("MarkovPasswordsGUI") + endif() + if(PYTHON_VER) + message("Building cpython extensions") + add_subdirectory ("Markopy") + if(B_CUDA) + message("Building CUDA-accelerated cpython extensions") + add_subdirectory ("CudaMarkopy") + endif() + endif() +endif() + +#include(CTest) diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 00000000..b4922e91 --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "x64 Release", + "generator": "Ninja", + "configurationType": "Release", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${projectDir}\\out\\build\\${name}", + "installRoot": "${projectDir}\\out\\install\\${name}", + "cmakeCommandArgs": "", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "variables": [] + } + ] +} \ No newline at end of file diff --git a/CopyOfCMakeCache.txt b/CopyOfCMakeCache.txt new file mode 100644 index 00000000..2aa570ec --- /dev/null +++ b/CopyOfCMakeCache.txt @@ -0,0 +1,473 @@ +# This is the CMakeCache file. +# For build in directory: /home/ignis/MarkovPasswords +# It was generated by CMake: /usr/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//The directory containing a CMake configuration file for Boost. +Boost_DIR:PATH=/usr/local/lib/cmake/Boost-1.76.0 + +//Path to a file. +Boost_INCLUDE_DIR:PATH=/usr/local/include + +Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE:STRING=/usr/local/lib/libboost_program_options.a + +Boost_PYTHON_LIBRARY_RELEASE:STRING=/usr/local/lib/libboost_python310-3_10.so.1.76.0 + +//Path to a program. +CMAKE_ADDR2LINE:FILEPATH=/usr/bin/addr2line + +//Path to a program. +CMAKE_AR:FILEPATH=/usr/bin/ar + +//Choose the type of build, options are: None Debug Release RelWithDebInfo +// MinSizeRel ... +CMAKE_BUILD_TYPE:STRING= + +//Enable/Disable color output during build. +CMAKE_COLOR_MAKEFILE:BOOL=ON + +//CUDA compiler +CMAKE_CUDA_COMPILER:FILEPATH=/usr/local/cuda-11.0/bin/nvcc + +//Flags used by the CUDA compiler during all build types. +CMAKE_CUDA_FLAGS:STRING= + +//Flags used by the CUDA compiler during DEBUG builds. +CMAKE_CUDA_FLAGS_DEBUG:STRING=-g + +//Flags used by the CUDA compiler during MINSIZEREL builds. +CMAKE_CUDA_FLAGS_MINSIZEREL:STRING=-O1 -DNDEBUG + +//Flags used by the CUDA compiler during RELEASE builds. +CMAKE_CUDA_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the CUDA compiler during RELWITHDEBINFO builds. +CMAKE_CUDA_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//CXX compiler +CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++ + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-9 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-9 + +//Flags used by the CXX compiler during all build types. +CMAKE_CXX_FLAGS:STRING= + +//Flags used by the CXX compiler during DEBUG builds. +CMAKE_CXX_FLAGS_DEBUG:STRING=-g + +//Flags used by the CXX compiler during MINSIZEREL builds. +CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the CXX compiler during RELEASE builds. +CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the CXX compiler during RELWITHDEBINFO builds. +CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//C compiler +CMAKE_C_COMPILER:FILEPATH=/usr/bin/cc + +//A wrapper around 'ar' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-9 + +//A wrapper around 'ranlib' adding the appropriate '--plugin' option +// for the GCC compiler +CMAKE_C_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-9 + +//Flags used by the C compiler during all build types. +CMAKE_C_FLAGS:STRING= + +//Flags used by the C compiler during DEBUG builds. +CMAKE_C_FLAGS_DEBUG:STRING=-g + +//Flags used by the C compiler during MINSIZEREL builds. +CMAKE_C_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG + +//Flags used by the C compiler during RELEASE builds. +CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG + +//Flags used by the C compiler during RELWITHDEBINFO builds. +CMAKE_C_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG + +//Path to a program. +CMAKE_DLLTOOL:FILEPATH=CMAKE_DLLTOOL-NOTFOUND + +//Flags used by the linker during all build types. +CMAKE_EXE_LINKER_FLAGS:STRING= + +//Flags used by the linker during DEBUG builds. +CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during MINSIZEREL builds. +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during RELEASE builds. +CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during RELWITHDEBINFO builds. +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Enable/Disable output of compile commands during generation. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF + +//Install path prefix, prepended onto install directories. +CMAKE_INSTALL_PREFIX:PATH=/usr/local + +//Path to a program. +CMAKE_LINKER:FILEPATH=/usr/bin/ld + +//Path to a program. +CMAKE_MAKE_PROGRAM:FILEPATH=/usr/bin/make + +//Flags used by the linker during the creation of modules during +// all build types. +CMAKE_MODULE_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of modules during +// DEBUG builds. +CMAKE_MODULE_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of modules during +// MINSIZEREL builds. +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of modules during +// RELEASE builds. +CMAKE_MODULE_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of modules during +// RELWITHDEBINFO builds. +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_NM:FILEPATH=/usr/bin/nm + +//Path to a program. +CMAKE_OBJCOPY:FILEPATH=/usr/bin/objcopy + +//Path to a program. +CMAKE_OBJDUMP:FILEPATH=/usr/bin/objdump + +//Value Computed by CMake +CMAKE_PROJECT_DESCRIPTION:STATIC=Password generation with markov chains + +//Value Computed by CMake +CMAKE_PROJECT_HOMEPAGE_URL:STATIC= + +//Value Computed by CMake +CMAKE_PROJECT_NAME:STATIC=Markopy + +//Value Computed by CMake +CMAKE_PROJECT_VERSION:STATIC=0.5.1 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MAJOR:STATIC=0 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_MINOR:STATIC=5 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_PATCH:STATIC=1 + +//Value Computed by CMake +CMAKE_PROJECT_VERSION_TWEAK:STATIC= + +//Path to a program. +CMAKE_RANLIB:FILEPATH=/usr/bin/ranlib + +//Path to a program. +CMAKE_READELF:FILEPATH=/usr/bin/readelf + +//Flags used by the linker during the creation of shared libraries +// during all build types. +CMAKE_SHARED_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of shared libraries +// during DEBUG builds. +CMAKE_SHARED_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of shared libraries +// during MINSIZEREL builds. +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of shared libraries +// during RELEASE builds. +CMAKE_SHARED_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of shared libraries +// during RELWITHDEBINFO builds. +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//If set, runtime paths are not added when installing shared libraries, +// but are added when building. +CMAKE_SKIP_INSTALL_RPATH:BOOL=NO + +//If set, runtime paths are not added when using shared libraries. +CMAKE_SKIP_RPATH:BOOL=NO + +//Flags used by the linker during the creation of static libraries +// during all build types. +CMAKE_STATIC_LINKER_FLAGS:STRING= + +//Flags used by the linker during the creation of static libraries +// during DEBUG builds. +CMAKE_STATIC_LINKER_FLAGS_DEBUG:STRING= + +//Flags used by the linker during the creation of static libraries +// during MINSIZEREL builds. +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELEASE builds. +CMAKE_STATIC_LINKER_FLAGS_RELEASE:STRING= + +//Flags used by the linker during the creation of static libraries +// during RELWITHDEBINFO builds. +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO:STRING= + +//Path to a program. +CMAKE_STRIP:FILEPATH=/usr/bin/strip + +//No help, variable specified on the command line. +CMAKE_SYSTEM_NAME:UNINITIALIZED=WindowsCE + +//No help, variable specified on the command line. +CMAKE_SYSTEM_VERSION:UNINITIALIZED=10.0 + +//No help, variable specified on the command line. +CMAKE_TOOLCHAIN_FILE:UNINITIALIZED=toolchains/mingw-w64-x86_64.cmake + +//If this value is on, makefiles will be generated without the +// .SILENT directive, and all commands will be echoed to the console +// during the make. This is useful for debugging only. With Visual +// Studio IDE projects all commands are done without /nologo. +CMAKE_VERBOSE_MAKEFILE:BOOL=FALSE + +//Value Computed by CMake +Markopy_BINARY_DIR:STATIC=/home/ignis/MarkovPasswords + +//Value Computed by CMake +Markopy_SOURCE_DIR:STATIC=/home/ignis/MarkovPasswords + +//Path to a library. +PYTHON_LIBRARY:FILEPATH=PYTHON_LIBRARY-NOTFOUND + +//Path to a library. +PYTHON_LIBRARY_DEBUG:FILEPATH=PYTHON_LIBRARY_DEBUG-NOTFOUND + +//Path to a library. +PYTHON_LIBRARY_RELEASE:FILEPATH=PYTHON_LIBRARY_RELEASE-NOTFOUND + +//The directory containing a CMake configuration file for boost_headers. +boost_headers_DIR:PATH=/usr/local/lib/cmake/boost_headers-1.76.0 + +//The directory containing a CMake configuration file for boost_program_options. +boost_program_options_DIR:PATH=/usr/local/lib/cmake/boost_program_options-1.76.0 + +//The directory containing a CMake configuration file for boost_python. +boost_python_DIR:PATH=/usr/local/lib/cmake/boost_python-1.76.0 + +//Dependencies for the target +cudamarkov_LIB_DEPENDS:STATIC=general;markov; + + +######################## +# INTERNAL cache entries +######################## + +//ADVANCED property for variable: Boost_DIR +Boost_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_ADDR2LINE +CMAKE_ADDR2LINE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_AR +CMAKE_AR-ADVANCED:INTERNAL=1 +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/ignis/MarkovPasswords +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=16 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 +//ADVANCED property for variable: CMAKE_COLOR_MAKEFILE +CMAKE_COLOR_MAKEFILE-ADVANCED:INTERNAL=1 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest +//ADVANCED property for variable: CMAKE_CUDA_COMPILER +CMAKE_CUDA_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CUDA_FLAGS +CMAKE_CUDA_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CUDA_FLAGS_DEBUG +CMAKE_CUDA_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CUDA_FLAGS_MINSIZEREL +CMAKE_CUDA_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CUDA_FLAGS_RELEASE +CMAKE_CUDA_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CUDA_FLAGS_RELWITHDEBINFO +CMAKE_CUDA_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER +CMAKE_CXX_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_AR +CMAKE_CXX_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_COMPILER_RANLIB +CMAKE_CXX_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS +CMAKE_CXX_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_DEBUG +CMAKE_CXX_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_MINSIZEREL +CMAKE_CXX_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELEASE +CMAKE_CXX_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_CXX_FLAGS_RELWITHDEBINFO +CMAKE_CXX_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER +CMAKE_C_COMPILER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_AR +CMAKE_C_COMPILER_AR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_COMPILER_RANLIB +CMAKE_C_COMPILER_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS +CMAKE_C_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_DEBUG +CMAKE_C_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_MINSIZEREL +CMAKE_C_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELEASE +CMAKE_C_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_C_FLAGS_RELWITHDEBINFO +CMAKE_C_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_DLLTOOL +CMAKE_DLLTOOL-ADVANCED:INTERNAL=1 +//Executable file format +CMAKE_EXECUTABLE_FORMAT:INTERNAL=ELF +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS +CMAKE_EXE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_DEBUG +CMAKE_EXE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_MINSIZEREL +CMAKE_EXE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELEASE +CMAKE_EXE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_EXPORT_COMPILE_COMMANDS +CMAKE_EXPORT_COMPILE_COMMANDS-ADVANCED:INTERNAL=1 +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Unix Makefiles +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Test CMAKE_HAVE_LIBC_PTHREAD +CMAKE_HAVE_LIBC_PTHREAD:INTERNAL= +//Have include pthread.h +CMAKE_HAVE_PTHREAD_H:INTERNAL=1 +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/home/ignis/MarkovPasswords +//ADVANCED property for variable: CMAKE_LINKER +CMAKE_LINKER-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MAKE_PROGRAM +CMAKE_MAKE_PROGRAM-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS +CMAKE_MODULE_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_DEBUG +CMAKE_MODULE_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL +CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELEASE +CMAKE_MODULE_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_NM +CMAKE_NM-ADVANCED:INTERNAL=1 +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=2 +//ADVANCED property for variable: CMAKE_OBJCOPY +CMAKE_OBJCOPY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_OBJDUMP +CMAKE_OBJDUMP-ADVANCED:INTERNAL=1 +//Platform information initialized +CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_RANLIB +CMAKE_RANLIB-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_READELF +CMAKE_READELF-ADVANCED:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.16 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS +CMAKE_SHARED_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_DEBUG +CMAKE_SHARED_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL +CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELEASE +CMAKE_SHARED_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_INSTALL_RPATH +CMAKE_SKIP_INSTALL_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_SKIP_RPATH +CMAKE_SKIP_RPATH-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS +CMAKE_STATIC_LINKER_FLAGS-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_DEBUG +CMAKE_STATIC_LINKER_FLAGS_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL +CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELEASE +CMAKE_STATIC_LINKER_FLAGS_RELEASE-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO +CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: CMAKE_STRIP +CMAKE_STRIP-ADVANCED:INTERNAL=1 +//uname command +CMAKE_UNAME:INTERNAL=/usr/bin/uname +//ADVANCED property for variable: CMAKE_VERBOSE_MAKEFILE +CMAKE_VERBOSE_MAKEFILE-ADVANCED:INTERNAL=1 +//Details about finding Boost +FIND_PACKAGE_MESSAGE_DETAILS_Boost:INTERNAL=[/usr/local/lib/cmake/Boost-1.76.0/BoostConfig.cmake][cfound components: python ][v1.76.0()] +//Details about finding Threads +FIND_PACKAGE_MESSAGE_DETAILS_Threads:INTERNAL=[TRUE][v()] +//ADVANCED property for variable: PYTHON_LIBRARY +PYTHON_LIBRARY-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: PYTHON_LIBRARY_DEBUG +PYTHON_LIBRARY_DEBUG-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: PYTHON_LIBRARY_RELEASE +PYTHON_LIBRARY_RELEASE-ADVANCED:INTERNAL=1 +//Result of TRY_COMPILE +THREADS_HAVE_PTHREAD_ARG:INTERNAL=TRUE +//ADVANCED property for variable: boost_headers_DIR +boost_headers_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: boost_program_options_DIR +boost_program_options_DIR-ADVANCED:INTERNAL=1 +//ADVANCED property for variable: boost_python_DIR +boost_python_DIR-ADVANCED:INTERNAL=1 + diff --git a/CudaMarkopy/CMakeLists.txt b/CudaMarkopy/CMakeLists.txt new file mode 100644 index 00000000..b1274376 --- /dev/null +++ b/CudaMarkopy/CMakeLists.txt @@ -0,0 +1,70 @@ +# CMakeList.txt : CMake project for CudaMarkopy, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.8) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/bin) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include_directories(${PROJECT_SOURCE_DIR}) + +link_directories(${PROJECT_SOURCE_DIR}/out/lib) + +include_directories(${PROJECT_SOURCE_DIR}) + +file(GLOB_RECURSE CMPY_FILES + "src/*.cu" +) + +if(WIN32) + link_directories( $ENV{BOOST_ROOT}/stage/lib/) + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME OFF) +endif() + +set(THREADS_PREFER_PTHREAD_FLAG ON) + +string(REGEX REPLACE "^(.)(.+)" "\\1.\\2" PYTHON_VER_SEP ${PYTHON_VER}) + +find_package(Threads REQUIRED) +find_package(Boost COMPONENTS python${PYTHON_VER} REQUIRED) +if(PY_DEV_PATH) + message("Using ${PY_DEV_PATH}") + include_directories("${PY_DEV_PATH}/include") + link_directories("${PY_DEV_PATH}/libs") +else() + find_package(PythonLibs ${PYTHON_VER_SEP} REQUIRED) +endif() + + +add_library(cudamarkopy SHARED ${CMPY_FILES}) +add_dependencies (cudamarkopy cudamarkov) + +set(CMPY_CPP_FLAGS "${MP_C_FLAGS} -std=c++17") +if(WIN32) +set(CMPY_LINK_FLAGS "${SGX_COMMON_CFLAGS}") +else() +set(CMPY_LINK_FLAGS "${SGX_COMMON_CFLAGS} -Wl,-rpath='${ORIGIN}'") +endif() + + +set_target_properties(cudamarkopy PROPERTIES COMPILE_FLAGS "${CMPY_CPP_FLAGS}") +set_target_properties(cudamarkopy PROPERTIES LINK_FLAGS "${CMPY_LINK_FLAGS}") + +set_target_properties(cudamarkopy + PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + +set_target_properties(cudamarkopy PROPERTIES PREFIX "") +target_include_directories(cudamarkopy PUBLIC ${PYTHON_INCLUDE_DIRS}) + +target_link_libraries(cudamarkopy cudamarkov) +target_link_libraries(cudamarkopy ${PYTHON_LIBRARIES}) +target_link_libraries(cudamarkopy Boost::python${PYTHON_VER}) +target_link_libraries(cudamarkopy markov) +if(WIN32) + set_target_properties(markopy PROPERTIES SUFFIX ".pyd") +endif() \ No newline at end of file diff --git a/CudaMarkopy/src/CLI/cudamarkopy.py b/CudaMarkopy/src/CLI/cudamarkopy.py new file mode 100644 index 00000000..6fefc5f8 --- /dev/null +++ b/CudaMarkopy/src/CLI/cudamarkopy.py @@ -0,0 +1,99 @@ +""" @package cudamarkopy + @file cudamarkopy_cli.py + @namespace Python::CUDA::Markopy + @brief Command line + @authors Ata Hakçıl +""" + +import sys +import os +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader, ExtensionFileLoader +import inspect +try: + spec = spec_from_loader("markopy", SourceFileLoader("markopy", os.path.abspath("markopy.py"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) +except (ModuleNotFoundError,FileNotFoundError) as e: + if(os.path.exists("../../../Markopy/src/CLI/markopy.py")): + spec = spec_from_loader("markopy", SourceFileLoader("markopy", "../../../Markopy/src/CLI/markopy.py")) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) + +try: + from cudammx import CudaModelMatrixCLI + from mmx import ModelMatrixCLI + from mp import MarkovPasswordsCLI + +except ModuleNotFoundError as e: + print("Working in development mode. Trying to load markopy.py from ../../../Markopy/") + if(os.path.exists("../../../Markopy/src/CLI/cudammx.py")): + sys.path.insert(1, '../../../Markopy/src/CLI/') + from cudammx import CudaModelMatrixCLI + from mmx import ModelMatrixCLI + from mp import MarkovPasswordsCLI + else: + raise e + + +#print(markopy) +#print(inspect.getmembers(markopy)) +#import code +#code.interact(local=locals()) + +from termcolor import colored + + +class CudaMarkopyCLI(markopy.MarkopyCLI): + def __init__(self) -> None: + super().__init__(add_help=False) + self.parser.epilog+=f""" + {__file__.split("/")[-1]} -mt CUDA generate trained.mdl -n 500 -w output.txt + Import trained.mdl, and generate 500 lines to output.txt + """ + + def help(self): + self.parser.print_help = self.stub + self.args = self.parser.parse_known_args()[0] + if(self.args.model_type!="_MMX"): + if(self.args.model_type=="MP"): + mp = MarkovPasswordsCLI() + mp.add_arguments() + mp.parser.print_help() + elif(self.args.model_type=="MMX"): + mp = ModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + elif(self.args.model_type == "CUDA"): + mp = CudaModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + else: + print(colored("Model Mode selection choices:", "green")) + self.print_help() + print(colored("Following are applicable for -mt MP mode:", "green")) + mp = MarkovPasswordsCLI() + mp.add_arguments() + mp.parser.print_help() + print(colored("Following are applicable for -mt MMX mode:", "green")) + mp = ModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + print(colored("Following are applicable for -mt CUDA mode:", "green")) + mp = CudaModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + exit() + + def parse_fail(self): + if(self.args.model_type == "CUDA"): + self.cli = CudaModelMatrixCLI() + else: + super().parse_fail() + + +if __name__ == "__main__": + mp = CudaMarkopyCLI() + #mp = markopy_cli.MarkopyCLI() + mp.parse() + mp.process() \ No newline at end of file diff --git a/CudaMarkopy/src/CLI/cudammx.py b/CudaMarkopy/src/CLI/cudammx.py new file mode 100644 index 00000000..47956e4f --- /dev/null +++ b/CudaMarkopy/src/CLI/cudammx.py @@ -0,0 +1,74 @@ +""" @package markopy + @file cudammx_cli.py + @namespace Python::Markopy::CUDA::ModelMatrix + @brief Command line class for CudaModelMatrix + @authors Ata Hakçıl +""" + +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader, ExtensionFileLoader +import os +import sys + +ext = "so" +if os.name == 'nt': + ext="pyd" +try: + spec = spec_from_loader("cudamarkopy", ExtensionFileLoader("cudamarkopy", os.path.abspath(f"cudamarkopy.{ext}"))) + cudamarkopy = module_from_spec(spec) + spec.loader.exec_module(cudamarkopy) +except ImportError as e: + print(f"({__file__}) Working in development mode. Trying to load cudamarkopy.{ext} from ../../../out/") + if(os.path.exists(f"../../../out/lib/cudamarkopy.{ext}")): + spec = spec_from_loader("cudamarkopy", ExtensionFileLoader("cudamarkopy", os.path.abspath(f"../../../out/lib/cudamarkopy.{ext}"))) + cudamarkopy = module_from_spec(spec) + spec.loader.exec_module(cudamarkopy) + else: + raise e + + + +try: + spec = spec_from_loader("markopy", SourceFileLoader("markopy", os.path.abspath("markopy.py"))) + markopy = module_from_spec(spec) + + from mmx import ModelMatrixCLI + from base import BaseCLI,AbstractGenerationModelCLI, AbstractTrainingModelCLI + +except ImportError as e: + print("Working in development mode. Trying to load from ../../../out/") + if(os.path.exists("../../../Markopy/src/CLI/markopy.py")): + spec = spec_from_loader("markopy", SourceFileLoader("markopy", os.path.abspath("../../../Markopy/src/CLI/markopy.py"))) + markopy = module_from_spec(spec) + sys.path.insert(1, '../../../Markopy/src/CLI/') + + from mmx import ModelMatrixCLI + from base import BaseCLI,AbstractGenerationModelCLI, AbstractTrainingModelCLI + else: + raise e + +import os +import allogate as logging + +class CudaModelMatrixCLI(ModelMatrixCLI,AbstractGenerationModelCLI): + def __init__(self): + super().__init__() + self.model = cudamarkopy.CUDAModelMatrix() + + def add_arguments(self): + super().add_arguments() + self.parser.add_argument("-if", "--infinite", action="store_true", help="Infinite generation mode") + + + + def init_post_arguments(self): + super().init_post_arguments() + self.bInfinite = self.args.infinite + + def _generate(self, wordlist : str ): + self.model.FastRandomWalk(int(self.args.count), wordlist, int(self.args.min), int(self.args.max), self.fileIO, self.bInfinite) + +if __name__ == "__main__": + mp = CudaModelMatrixCLI() + mp.parse() + mp.process() \ No newline at end of file diff --git a/CudaMarkopy/src/Module/cudaMarkopy.cu b/CudaMarkopy/src/Module/cudaMarkopy.cu new file mode 100644 index 00000000..3df69a2f --- /dev/null +++ b/CudaMarkopy/src/Module/cudaMarkopy.cu @@ -0,0 +1,35 @@ +/** @file cudaMarkopy.cpp + * @brief CPython wrapper for libcudamarkov utils. GPU + * @authors Ata Hakçıl + * + * @copydoc markopy.cpp + * @copydoc cudaModelMatrix.cu + */ + +#define BOOST_PYTHON_STATIC_LIB +#include +#include +#include "CudaMarkovAPI/src/cudaModelMatrix.h" + +using namespace boost::python; + +namespace Markov::Markopy::CUDA{ + BOOST_PYTHON_MODULE(cudamarkopy) + { + bool (Markov::API::MarkovPasswords::*Export)(const char*) = &Markov::Model::Export; + void (Markov::API::CUDA::CUDAModelMatrix::*FastRandomWalk)(unsigned long int, const char*, int, int, bool, bool) = &Markov::API::CUDA::CUDAModelMatrix::FastRandomWalk; + + class_("CUDAModelMatrix", init<>()) + + .def(init<>()) + .def("Train", &Markov::API::ModelMatrix::Train) + .def("Import", &Markov::API::ModelMatrix::Import, "Import a model file.") + .def("Export", Export, "Export a model to file.") + .def("ConstructMatrix",&Markov::API::ModelMatrix::ConstructMatrix) + .def("DumpJSON",&Markov::API::ModelMatrix::DumpJSON) + .def("FastRandomWalk", FastRandomWalk) + ; + }; +}; + + diff --git a/CudaMarkovAPI/CMakeLists.txt b/CudaMarkovAPI/CMakeLists.txt new file mode 100644 index 00000000..49120921 --- /dev/null +++ b/CudaMarkovAPI/CMakeLists.txt @@ -0,0 +1,55 @@ +# CMakeList.txt : CMake project for CudaMarkovAPI, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.8) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include_directories(${PROJECT_SOURCE_DIR}) +link_directories(${PROJECT_SOURCE_DIR}/out/lib) + + +file(GLOB_RECURSE CMP_FILES + "src/*.h" + "src/*.cu" +) + +if(WIN32) +add_library(cudamarkov STATIC ${CMP_FILES} src/cudaDeviceController.cu src/cudaModelMatrix.cu) +else() + add_library(cudamarkov SHARED ${CMP_FILES}) +endif() + +add_dependencies (cudamarkov markov) + +set(CMP_CPP_FLAGS "${MP_C_FLAGS} -std=c++17") +if(WIN32) +set(CMP_LINK_FLAGS "${SGX_COMMON_CFLAGS}") +else() +set(CMP_LINK_FLAGS "${SGX_COMMON_CFLAGS} -Wl,-rpath='${ORIGIN}'") +endif() + + +set_target_properties(cudamarkov PROPERTIES COMPILE_FLAGS "${CMP_CPP_FLAGS}") +set_target_properties(cudamarkov PROPERTIES LINK_FLAGS "${CMP_LINK_FLAGS}") +set_target_properties(cudamarkov PROPERTIES LINKER_LANGUAGE CUDA) + +set_target_properties(cudamarkov + PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + +target_link_libraries(cudamarkov markov) + + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/bin) +add_executable(cudamarkovp src/main.cu) +add_dependencies (cudamarkovp cudamarkov) +set_target_properties(cudamarkovp PROPERTIES LINKER_LANGUAGE CUDA) +set_target_properties(cudamarkovp PROPERTIES COMPILE_FLAGS "${CMP_CPP_FLAGS}") +set_target_properties(cudamarkovp PROPERTIES LINK_FLAGS "${CMP_LINK_FLAGS}") +target_link_libraries(cudamarkovp markov) +target_link_libraries(cudamarkovp cudamarkov) \ No newline at end of file diff --git a/CudaMarkovPasswords/src/cudaDeviceController.cu b/CudaMarkovAPI/src/cudaDeviceController.cu similarity index 87% rename from CudaMarkovPasswords/src/cudaDeviceController.cu rename to CudaMarkovAPI/src/cudaDeviceController.cu index 2b9b64d8..d63f059b 100644 --- a/CudaMarkovPasswords/src/cudaDeviceController.cu +++ b/CudaMarkovAPI/src/cudaDeviceController.cu @@ -1,5 +1,16 @@ +/** @file cudaDeviceController.cu + * @brief Simple static class for basic CUDA device controls. + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CUDA::CUDADeviceController + */ + #include "cudaDeviceController.h" #include +#include +#include +#include +#include namespace Markov::API::CUDA{ __host__ void Markov::API::CUDA::CUDADeviceController::ListCudaDevices() { //list cuda Capable devices on host. diff --git a/CudaMarkovPasswords/src/cudaDeviceController.h b/CudaMarkovAPI/src/cudaDeviceController.h similarity index 96% rename from CudaMarkovPasswords/src/cudaDeviceController.h rename to CudaMarkovAPI/src/cudaDeviceController.h index 762c1e3b..0d295e60 100644 --- a/CudaMarkovPasswords/src/cudaDeviceController.h +++ b/CudaMarkovAPI/src/cudaDeviceController.h @@ -1,10 +1,12 @@ +/** @file cudaDeviceController.h + * @brief Simple static class for basic CUDA device controls. + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CUDA::CUDADeviceController + */ #pragma once #include -#include -#include -#include -#include /** @brief Namespace for objects requiring CUDA libraries. */ diff --git a/CudaMarkovPasswords/src/cudaModelMatrix.cu b/CudaMarkovAPI/src/cudaModelMatrix.cu similarity index 97% rename from CudaMarkovPasswords/src/cudaModelMatrix.cu rename to CudaMarkovAPI/src/cudaModelMatrix.cu index deae0c1c..db78d9fc 100644 --- a/CudaMarkovPasswords/src/cudaModelMatrix.cu +++ b/CudaMarkovAPI/src/cudaModelMatrix.cu @@ -1,5 +1,18 @@ +/** @file cudaModelMatrix.cu + * @brief CUDA accelerated extension of Markov::API::ModelMatrix + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CUDA::CUDAModelMatrix + */ + #include "cudaModelMatrix.h" -#include "CudaMarkovPasswords/src/cudarandom.h" +#include "cudarandom.h" + + +#include +#include +#include +#include using Markov::API::CUDA::CUDADeviceController; diff --git a/CudaMarkovPasswords/src/cudaModelMatrix.h b/CudaMarkovAPI/src/cudaModelMatrix.h similarity index 94% rename from CudaMarkovPasswords/src/cudaModelMatrix.h rename to CudaMarkovAPI/src/cudaModelMatrix.h index 8da71dca..172a9c0b 100644 --- a/CudaMarkovPasswords/src/cudaModelMatrix.h +++ b/CudaMarkovAPI/src/cudaModelMatrix.h @@ -1,9 +1,12 @@ -#include "MarkovPasswords/src/modelMatrix.h" +/** @file cudaModelMatrix.h + * @brief CUDA accelerated extension of Markov::API::ModelMatrix + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CUDA::CUDAModelMatrix + */ + +#include "MarkovAPI/src/modelMatrix.h" #include "cudaDeviceController.h" -#include -#include -#include -#include /** @brief Namespace for objects requiring CUDA libraries. */ @@ -11,8 +14,9 @@ namespace Markov::API::CUDA{ /** @brief Extension of Markov::API::ModelMatrix which is modified to run on GPU devices. * * This implementation only supports Nvidia devices. + * @copydoc Markov::API::ModelMatrix */ - class CUDAModelMatrix : public ModelMatrix, public CUDADeviceController{ + class CUDAModelMatrix : public Markov::API::ModelMatrix, public CUDADeviceController{ public: /** @brief Migrate the class members to the VRAM diff --git a/CudaMarkovPasswords/src/cudarandom.h b/CudaMarkovAPI/src/cudarandom.h similarity index 88% rename from CudaMarkovPasswords/src/cudarandom.h rename to CudaMarkovAPI/src/cudarandom.h index 887c33be..62ffbbab 100644 --- a/CudaMarkovPasswords/src/cudarandom.h +++ b/CudaMarkovAPI/src/cudarandom.h @@ -1,12 +1,21 @@ +/** @file cudarandom.h + * @brief Extension of Markov::Random::Marsaglia for CUDA + * @authors Ata Hakçıl + * + * @copydoc Markov::Random::Marsaglia + */ + #pragma once #include "MarkovModel/src/random.h" -#include "CudaMarkovPasswords/src/cudaDeviceController.h" +#include "cudaDeviceController.h" /** @brief Namespace for Random engines operable under __device__ space. */ namespace Markov::API::CUDA::Random{ /** @brief Extension of Markov::Random::Marsaglia which is capable o working on __device__ space. + * + * @copydoc Markov::Random::Marsaglia */ class Marsaglia : public Markov::Random::Marsaglia, public CUDADeviceController{ public: diff --git a/CudaMarkovPasswords/src/main.cu b/CudaMarkovAPI/src/main.cu similarity index 85% rename from CudaMarkovPasswords/src/main.cu rename to CudaMarkovAPI/src/main.cu index fb575e7b..d98332b0 100644 --- a/CudaMarkovPasswords/src/main.cu +++ b/CudaMarkovAPI/src/main.cu @@ -1,4 +1,11 @@ -#pragma once +/** @file main.cu + * @brief Simple test file to check libcudamarkov + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CUDA::CudaModelMatrix + * @copydoc Markov::API::CUDA::CUDADeviceController + */ + #include #include #include diff --git a/CudaMarkovPasswords/CudaMarkovPasswords.vcxproj b/CudaMarkovPasswords/CudaMarkovPasswords.vcxproj deleted file mode 100644 index 34727931..00000000 --- a/CudaMarkovPasswords/CudaMarkovPasswords.vcxproj +++ /dev/null @@ -1,107 +0,0 @@ - - - - - Debug - x64 - - - Release - x64 - - - - - - - - - - - - - - - - - - - {ACCAF49C-AED2-4977-AE26-90B72C960779} - CudaMarkovPasswords - 10.0 - - - - Application - true - MultiByte - v142 - - - Application - false - true - MultiByte - v142 - - - - - - - - - - - - - - true - - - - Level3 - Disabled - WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - true - Console - cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - 64 - %(AdditionalIncludeDirectories);$(SolutionDir); - --std=c++17 - - - - - Level3 - MaxSpeed - true - true - WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - stdcpp17 - %(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir);$(SolutionDir); - - - true - true - true - Console - cudart_static.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - 64 - %(AdditionalIncludeDirectories);$(SolutionDir); - - - -std=c++17 - - - - - - - \ No newline at end of file diff --git a/CudaMarkovPasswords/CudaMarkovPasswords.vcxproj.filters b/CudaMarkovPasswords/CudaMarkovPasswords.vcxproj.filters deleted file mode 100644 index 4f08ed49..00000000 --- a/CudaMarkovPasswords/CudaMarkovPasswords.vcxproj.filters +++ /dev/null @@ -1,47 +0,0 @@ - - - - - {e1ec9855-e976-42be-b815-9d7b42f6e4f1} - - - {11eb7e44-3e7d-4cbd-ba72-91bc3a693a65} - - - {174ef79e-6321-4d4c-90b7-96704e1e0f2c} - - - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - - - Dependencies - - - Dependencies - - - Dependencies - - - \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6ad9ab9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ +FROM nvidia/cuda:11.0.3-devel-ubuntu20.04 +MAINTAINER + +# Install add-apt-repository +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update \ + && apt-get install -y software-properties-common \ + && add-apt-repository ppa:deadsnakes/ppa \ + && apt-get -y update \ + && apt-get -y install \ + build-essential \ + cmake \ + git \ + wget \ + python3.10-dev\ + python3.9-dev\ + python3.8-dev\ + python3.7-dev\ + python3.6-dev \ + qt5-qmake-bin \ + qtwebengine5-dev \ + zip \ + && wget https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz -O /root/boost_1_76_0.tar.gz -q \ + && cd /root && tar -xf /root/boost_1_76_0.tar.gz; \ + cd /root/boost_1_76_0; \ + ./bootstrap.sh; \ + ./b2 variant=release link=static threading=multi --with-program_options install; \ + ./bootstrap.sh --with-python=$(which python3.6) --with-python-version=3.6; \ + ./b2 --with-python --buildid=3.6 install; \ + ./bootstrap.sh --with-python=$(which python3.7) --with-python-version=3.7; \ + ./b2 --with-python --buildid=3.7 install; \ + ./bootstrap.sh --with-python=$(which python3.8) --with-python-version=3.8; \ + ./b2 --with-python --buildid=3.8 install; \ + ./bootstrap.sh --with-python=$(which python3.9) --with-python-version=3.9; \ + ./b2 --with-python --buildid=3.9 install; \ + ./bootstrap.sh --with-python=$(which python3.10) --with-python-version=3.10; \ + ./b2 --with-python --buildid=3.10 install; \ + rm -r /root/boost_1_76_0 \ + && apt-get remove wget software-properties-common \ + && apt-get -y autoclean \ + && apt-get -y autoremove \ + && rm /root/boost_1_76_0.tar.gz; \ + rm -rf /var/lib/apt/lists/* diff --git a/Dockerfile.cross-win32 b/Dockerfile.cross-win32 new file mode 100644 index 00000000..c31a829b --- /dev/null +++ b/Dockerfile.cross-win32 @@ -0,0 +1,12 @@ +FROM ahakcil/markopy:0.5.0 + +ARG DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get install -y mingw-w64 + +RUN apt-get -y autoclean \ + && apt-get -y autoremove + +RUN rm -rf /var/lib/apt/lists/* + +COPY . /root/markopy/ \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 815995ae..00000000 --- a/Makefile +++ /dev/null @@ -1,125 +0,0 @@ - - -############################################################################################################## -##################################### Global Options ################################# -############################################################################################################## - -# Compiler -CC := g++ -# Cuda Compiler -NVCC := nvcc -#output directory -BIN := bin -#include directory -INCLUDE := include -#Libraries -LIB := lib -LIBRARIES := -CUDAPATH = /usr/lib/cuda11.0 - - -ifndef PYTHON_VERSION -PYTHON_VERSION := $(shell python3 -c "import sys;t='{v[0]}.{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";) #3.8 -endif - -PYTHON_VERSION_ :=$(shell python$(PYTHON_VERSION) -c "import sys;t='{v[0]}{v[1]}'.format(v=list(sys.version_info[:2]));sys.stdout.write(t)";) #38 -PYTHON_VERSION3 :=$(shell python$(PYTHON_VERSION) -c "import sys;t='{v[0]}.{v[1]}.{v[2]}'.format(v=list(sys.version_info[:3]));sys.stdout.write(t)";) #3.8.s2 - -############################################################################################################## -##################################### MarkovPassword project options ################################# -############################################################################################################## - -MP_C_FLAGS := -Wall -Wextra -g -Ofast -std=c++17 -MP_EXEC := Markov -MP_SRC := $(shell find ./MarkovPasswords/src/ -name '*.cpp') -MP_INC := -MP_LIB := -lboost_program_options -lpthread -MP_INC := $(shell pwd) - -#build pattern -$(BIN)/$(MP_EXEC): $(MP_SRC) - $(CC) $(MP_C_FLAGS) -I$(MP_INC) -L$(LIB) $^ -o $@ $(MP_LIB) - - -############################################################################################################## -################################### CUDAMarkovPassword project options ################################# -############################################################################################################## - -NVCCFLAGS := -std=c++17 -g -O3 -Xptxas "--allow-expensive-optimizations true --opt-level 3" -L$(CUDAPATH)/lib -MPC_EXEC := CUDAMarkov -MPC_SRC := $(shell find ./CudaMarkovPasswords/src/ -name '*.cpp') $(shell find ./CudaMarkovPasswords/src/ -name '*.cu') MarkovPasswords/src/threadSharedListHandler.cpp MarkovPasswords/src/markovPasswords.cpp MarkovPasswords/src/modelMatrix.cpp -MPC_INC := $(CUDAPATH)/include -MPC_LIB := -lboost_program_options -lpthread -lcuda -lcudart -lm -MPC_INC := $(shell pwd) - -#build pattern -$(BIN)/$(MPC_EXEC): $(MPC_SRC) - $(NVCC) $(NVCCFLAGS) -I$(MPC_INC) -L$(LIB) $^ -o $@ $(MPC_LIB) - -############################################################################################################## -##################################### MarkovModel project options ################################# -############################################################################################################## -MM_SRC_DIR := MarkovModel/src/ -MM_SRC := $(shell find $(MM_SRC_DIR) -name '*.cpp') -MM_OBJS := $(MM_SRC:%=$(BIN)/%.o) -MM_DEPS := $(MM_OBJS:.o=.d) -MM_LDFLAGS := -shared -MM_C_FLAGS := $(MM_INC_FLAGS) -MMD -MP -Ofast -std=c++17 -MM_INC_DIRS := $(shell find $(MM_SRC_DIR) -type d) -MM_INC_FLAGS := $(addprefix -I,$(MM_INC_DIRS)) -MM_LIB := model.so - -$(INCLUDE)/$(MM_LIB): $(MM_OBJS) - echo $(MM_OBJS) - $(CC) $(MM_OBJS) -o $@ $(MM_LDFLAGS) - -# Build step for C++ source -$(BIN)/%.cpp.o:%.cpp - mkdir -p $(dir $@) - $(CC) $(MM_C_FLAGS) -c $< -o $@ - --include $(MM_DEPS) - -############################################################################################################## -##################################### Markopy Options ################################# -############################################################################################################## - -MPY_SRC := MarkovPasswords/src/markovPasswords.cpp MarkovPasswords/src/threadSharedListHandler.cpp MarkovPasswords/src/modelMatrix.cpp $(shell find Markopy/src/Module/ -name '*.cpp') -MPY_SRC_DIR := Markopy/src/ -MPY_OBJS := $(MPY_SRC:%=$(BIN)/%.o) -MPY_DEPS := $(MPY_OBJS:.o=.d) -MPY_LDFLAGS := -shared -lboost_python$(PYTHON_VERSION_) -lpython$(PYTHON_VERSION) -lpthread -MPY_C_FLAGS := $(MPY_INC_FLAGS) -MMD -MP -fPIC -I/usr/include/python$(PYTHON_VERSION) -Ofast -std=c++17 -MPY_INC_DIRS := $(shell find $(MPY_SRC_DIR) -type d) $(shell pwd) -MPY_INC_FLAGS := $(addprefix -I,$(MPY_INC_DIRS)) -MPY_SO := markopy.so - -$(BIN)/$(MPY_SO): $(MPY_OBJS) - $(CC) $(MPY_OBJS) -o $@ $(MPY_LDFLAGS) - -# Build step for C++ source -$(BIN)/%.cpp.o:%.cpp - mkdir -p $(dir $@) - $(CC) $(MPY_C_FLAGS) $(MPY_INC_FLAGS) -c $< -o $@ - --include $(MPY_DEPS) - -############################################################################################################## -##################################### Directives ################################# -############################################################################################################## - -.PHONY: all -all: model mp markopy -model: $(INCLUDE)/$(MM_LIB) - -mp: $(BIN)/$(MP_EXEC) - -mpcuda: $(BIN)/$(MPC_EXEC) - -markopy: $(BIN)/$(MPY_SO) - -.PHONY: clean - -clean: $(RM) -r $(BIN)/* - - diff --git a/Markopy/CMakeLists.txt b/Markopy/CMakeLists.txt new file mode 100644 index 00000000..04f9fc28 --- /dev/null +++ b/Markopy/CMakeLists.txt @@ -0,0 +1,72 @@ +# CMakeList.txt : CMake project for Markopy, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.12) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/bin) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include_directories(${PROJECT_SOURCE_DIR}) + +link_directories(${PROJECT_SOURCE_DIR}/out/lib) + +include_directories(${PROJECT_SOURCE_DIR}) + +file(GLOB_RECURSE MPY_FILES + "src/Module/*.h" + "src/Module/*.cpp" +) + +if(WIN32) + link_directories( $ENV{BOOST_ROOT}/stage/lib/) + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME OFF) +endif() + +set(THREADS_PREFER_PTHREAD_FLAG ON) + +string(REGEX REPLACE "^(.)(.+)" "\\1.\\2" PYTHON_VER_SEP ${PYTHON_VER}) + +find_package(Threads REQUIRED) +find_package(Boost COMPONENTS python${PYTHON_VER} REQUIRED) +if(PY_DEV_PATH) + message("Using ${PY_DEV_PATH}") + include_directories("${PY_DEV_PATH}/include") + link_directories("${PY_DEV_PATH}/libs") +else() + find_package(PythonLibs ${PYTHON_VER_SEP} REQUIRED) +endif() + +if(WIN32) + add_library(markopy MODULE ${MPY_FILES} ) +else() + add_library(markopy SHARED ${MPY_FILES} ) +endif() + +add_dependencies (markopy markov) + +set(MPY_CPP_FLAGS "${MPY_C_FLAGS} -std=c++17") +if(WIN32) +set(MPY_LINK_FLAGS "${SGX_COMMON_CFLAGS}") +else() +set(MPY_LINK_FLAGS "${SGX_COMMON_CFLAGS} -Wl,-rpath='${ORIGIN}'") +endif() + +set_target_properties(markopy PROPERTIES COMPILE_FLAGS "${MPY_CPP_FLAGS}") +set_target_properties(markopy PROPERTIES LINK_FLAGS "${MPY_LINK_FLAGS}") +set_target_properties(markopy PROPERTIES LINKER_LANGUAGE CXX) + +set_target_properties(markopy PROPERTIES PREFIX "") +target_include_directories(markopy PUBLIC ${PYTHON_INCLUDE_DIRS}) +target_link_libraries(markopy PRIVATE ${PYTHON_LIBRARIES}) +target_link_libraries(markopy PRIVATE Boost::python${PYTHON_VER}) +target_link_libraries(markopy PRIVATE Threads::Threads) +target_link_libraries(markopy PRIVATE markov) + +if(WIN32) + set_target_properties(markopy PROPERTIES SUFFIX ".pyd") +endif() \ No newline at end of file diff --git a/Markopy/Markopy.vcxproj b/Markopy/Markopy.vcxproj deleted file mode 100644 index 06ed6bfc..00000000 --- a/Markopy/Markopy.vcxproj +++ /dev/null @@ -1,169 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - Win32Proj - {b3b712c9-fe83-4a38-adf1-61b01370ff95} - Markopy - 10.0 - markopy - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - false - - - true - .pyd - - - false - .pyd - $(SolutionDir)$(Platform)\intermediate\Markopy - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(pythonLocation)\include;$(PYTHON_PATH)\include;$(BOOST_ROOT);$(SolutionDir)MarkovModel\src\;$(SolutionDir)\MarkovPasswords\src\; - - - Console - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);python3*.lib;boost_python*-vc*-mt-*.lib - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(pythonLocation)\include;$(PYTHON_PATH)\include;$(BOOST_ROOT);$(SolutionDir)MarkovModel\src\;$(SolutionDir)\MarkovPasswords\src\; - - - Console - true - true - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);python3*.lib;boost_python*-vc*-mt-*.lib - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(pythonLocation)\include;$(PYTHON_PATH)\include;$(BOOST_ROOT);$(SolutionDir)MarkovModel\src\;$(SolutionDir)\MarkovPasswords\src\; - stdcpp17 - - - Console - true - $(BOOST_ROOT)\stage\lib;$(PYTHON_PATH)\libs; - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);python3*.lib;boost_python*-vc*-mt-*.lib - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(SolutionDir);$(pythonLocation)\include;$(PYTHON_PATH)\include;$(BOOST_ROOT); - stdcpp17 - - - Console - true - true - true - $(BOOST_ROOT)\stage\lib;$(PYTHON_PATH)\libs; - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);python3*.lib;boost_python*-vc*-mt-*.lib - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Markopy/Markopy.vcxproj.filters b/Markopy/Markopy.vcxproj.filters deleted file mode 100644 index 86441c4e..00000000 --- a/Markopy/Markopy.vcxproj.filters +++ /dev/null @@ -1,48 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {9d5b2d69-53e7-4ec2-9cec-6ff689eba092} - - - {c6f0bc14-5cba-4f99-b4b2-dc22cd3f06e7} - - - {9fe04840-08b7-4f78-8ae7-6513c3349fd5} - - - {ab5a1a08-ca20-48d3-9c82-4fd5e43bb20a} - - - - - Source Files\Module - - - Dependencies\MarkovPasswords - - - Dependencies\MarkovPasswords - - - Dependencies\MarkovPasswords - - - - - Source Files\CLI - - - \ No newline at end of file diff --git a/Markopy/src/CLI/base.py b/Markopy/src/CLI/base.py new file mode 100644 index 00000000..9af1cf72 --- /dev/null +++ b/Markopy/src/CLI/base.py @@ -0,0 +1,232 @@ +import argparse +import allogate as logging +import os +from abc import abstractmethod +from termcolor import colored + +class BaseCLI(): + """ Base CLI class to handle user interactions""" + def __init__(self, add_help=True): + self.parser = argparse.ArgumentParser(description="Python wrapper for MarkovPasswords.", + epilog=f"""{colored("Sample runs:", "yellow")} + {__file__.split("/")[-1]} train untrained.mdl -d dataset.dat -s "\\t" -o trained.mdl + Import untrained.mdl, train it with dataset.dat which has tab delimited data, output resulting model to trained.mdl\n + + {__file__.split("/")[-1]} generate trained.mdl -n 500 -w output.txt + Import trained.mdl, and generate 500 lines to output.txt + + {__file__.split("/")[-1]} combine untrained.mdl -d dataset.dat -s "\\t" -n 500 -w output.txt + Train and immediately generate 500 lines to output.txt. Do not export trained model. + + {__file__.split("/")[-1]} combine untrained.mdl -d dataset.dat -s "\\t" -n 500 -w output.txt -o trained.mdl + Train and immediately generate 500 lines to output.txt. Export trained model. + """, add_help=add_help, formatter_class=argparse.RawTextHelpFormatter) + self.print_help = self.parser.print_help + + @abstractmethod + def add_arguments(self): + "Add command line arguements to the parser" + self.parser.add_argument("mode", help="Process mode. Either 'Train', 'Generate', or 'Combine'.") + self.parser.add_argument("-t", "--threads",default=10, help="Number of lines to generate. Ignored in training mode.") + self.parser.add_argument("-v", "--verbosity",action="count", help="Output verbosity.") + self.parser.add_argument("-b", "--bulk",action="store_true", help="Bulk generate or bulk train every corpus/model in the folder.") + + @abstractmethod + def help(self): + "Handle help strings. Defaults to argparse's help" + self.print_help() + + def parse(self): + "add, parse and hook arguements" + self.add_arguments() + self.parse_arguments() + self.init_post_arguments() + + @abstractmethod + def init_post_arguments(self): + "set up stuff that is collected from command line arguements" + logging.VERBOSITY = 0 + try: + if self.args.verbosity: + logging.VERBOSITY = self.args.verbosity + logging.pprint(f"Verbosity set to {self.args.verbosity}.", 2) + except: + pass + + @abstractmethod + def parse_arguments(self): + "trigger parser" + self.args = self.parser.parse_known_args()[0] + + def import_model(self, filename): + "Import a model file" + logging.pprint("Importing model file.", 1) + + if not self.check_import_path(filename): + logging.pprint(f"Model file at {filename} not found. Check the file path, or working directory") + return False + + self.model.Import(filename) + logging.pprint("Model imported successfully.", 2) + return True + + + + def train(self, dataset : str, seperator : str, output : str, output_forced : bool=False, bulk : bool=False): + """ Train a model via CLI parameters + @param model Model instance + @param dataset filename for the dataset + @param seperator seperator used with the dataset + @param output output filename + @param output_forced force overwrite + @param bulk marks bulk operation with directories + """ + logging.pprint("Training.") + + if not (dataset and seperator and (output or not output_forced)): + logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.") + return False + + if not bulk and not self.check_corpus_path(dataset): + logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory") + return False + + if not self.check_export_path(output): + logging.pprint(f"Cannot create output at {output}") + return False + + if(seperator == '\\t'): + logging.pprint("Escaping seperator.", 3) + seperator = '\t' + + if(len(seperator)!=1): + logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.') + exit(4) + + logging.pprint(f'Starting training.', 3) + self.model.Train(dataset,seperator, int(self.args.threads)) + logging.pprint(f'Training completed.', 2) + + if(output): + logging.pprint(f'Exporting model to {output}', 2) + self.export(output) + else: + logging.pprint(f'Model will not be exported.', 1) + + return True + + def export(self, filename): + "Export model to a file" + self.model.Export(filename) + + def generate(self, wordlist : str, bulk : bool=False): + """ Generate strings from the model + @param model: model instance + @param wordlist wordlist filename + @param bulk marks bulk operation with directories + """ + if not (wordlist or self.args.count): + logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.") + return False + + if(bulk and os.path.isfile(wordlist)): + logging.pprint(f"{wordlist} exists and will be overwritten.", 1) + self._generate(wordlist) + + @abstractmethod + def _generate(self, wordlist): + self.model.Generate(int(self.args.count), wordlist, int(self.args.min), int(self.args.max), int(self.args.threads)) + + @staticmethod + def check_import_path(filename): + "Check given import path for validity" + if(not os.path.isfile(filename)): + return False + else: + return True + + @staticmethod + def check_corpus_path(filename): + "Check given corpus path for validity" + if(not os.path.isfile(filename)): + return False + return True + + @staticmethod + def check_export_path(filename): + if(filename and os.path.isfile(filename)): + return True + return True + + def process(self): + if(self.args.bulk): + logging.pprint(f"Bulk mode operation chosen.", 4) + if (self.args.mode.lower() == "train"): + if (os.path.isdir(self.args.output) and not os.path.isfile(self.args.output)) and (os.path.isdir(self.args.dataset) and not os.path.isfile(self.args.dataset)): + corpus_list = os.listdir(self.args.dataset) + for corpus in corpus_list: + self.import_model(self.args.input) + logging.pprint(f"Training {self.args.input} with {corpus}", 2) + output_file_name = corpus + model_extension = "" + if "." in self.args.input: + model_extension = self.args.input.split(".")[-1] + self.train(f"{self.args.dataset}/{corpus}", self.args.seperator, f"{self.args.output}/{corpus}.{model_extension}", output_forced=True, bulk=True) + else: + logging.pprint("In bulk training, output and dataset should be a directory.") + exit(1) + + elif (self.args.mode.lower() == "generate"): + if (os.path.isdir(self.args.wordlist) and not os.path.isfile(self.args.wordlist)) and (os.path.isdir(self.args.input) and not os.path.isfile(self.args.input)): + model_list = os.listdir(self.args.input) + print(model_list) + for input in model_list: + logging.pprint(f"Generating from {self.args.input}/{input} to {self.args.wordlist}/{input}.txt", 2) + self.import_model(f"{self.args.input}/{input}") + model_base = input + if "." in self.args.input: + model_base = input.split(".")[1] + self.generate(f"{self.args.wordlist}/{model_base}.txt", bulk=True) + else: + logging.pprint("In bulk generation, input and wordlist should be directory.") + + else: + self.import_model(self.args.input) + if (self.args.mode.lower() == "generate"): + self.generate(self.args.wordlist) + + + elif (self.args.mode.lower() == "train"): + self.train(self.args.dataset, self.args.seperator, self.args.output, output_forced=True) + + + elif(self.args.mode.lower() == "combine"): + self.train(self.args.dataset, self.args.seperator, self.args.output) + self.generate(self.args.wordlist) + + + else: + logging.pprint("Invalid mode arguement given.") + logging.pprint("Accepted modes: 'Generate', 'Train', 'Combine'") + exit(5) + +class AbstractGenerationModelCLI(BaseCLI): + @abstractmethod + def add_arguments(self): + "Add command line arguements to the parser" + super().add_arguments() + self.parser.add_argument("input", help="Input model file. This model will be imported before starting operation.") + self.parser.add_argument("-w", "--wordlist", help="Wordlist file path to export generation results to. Will be ignored for training mode") + self.parser.add_argument("--min", default=6, help="Minimum length that is allowed during generation") + self.parser.add_argument("--max", default=12, help="Maximum length that is allowed during generation") + self.parser.add_argument("-n", "--count", help="Number of lines to generate. Ignored in training mode.") + + +class AbstractTrainingModelCLI(AbstractGenerationModelCLI, BaseCLI): + @abstractmethod + def add_arguments(self): + "Add command line arguements to the parser" + self.parser.add_argument("-o", "--output", help="Output model file. This model will be exported when done. Will be ignored for generation mode.") + self.parser.add_argument("-d", "--dataset", help="Dataset file to read input from for training. Will be ignored for generation mode.") + self.parser.add_argument("-s", "--seperator", help="Seperator character to use with training data.(character between occurrence and value)") + super().add_arguments() diff --git a/Markopy/src/CLI/markopy.py b/Markopy/src/CLI/markopy.py new file mode 100644 index 00000000..e1a8cc52 --- /dev/null +++ b/Markopy/src/CLI/markopy.py @@ -0,0 +1,124 @@ +""" @package markopy + @file markopy_cli.py + @namespace Python::Markopy::ModelMatrix + @brief Command line class for ModelMatrix + @authors Ata Hakçıl +""" + +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader, ExtensionFileLoader +import os +import sys + +ext = "so" +if os.name == 'nt': + ext="pyd" +try: + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) +except ImportError as e: + print(f"({__file__}) Working in development mode. Trying to load markopy.{ext} from ../../../out/") + if(os.path.exists("../../../out/lib/markopy.so")): + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"../../../out/lib/markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) + else: + raise e + +try: + from base import BaseCLI + from mp import MarkovPasswordsCLI + from mmx import ModelMatrixCLI + +except ModuleNotFoundError as e: + print("Working in development mode. Trying to load markopy.py from ../../../Markopy/") + if(os.path.exists("../../../Markopy/src/CLI/base.py")): + sys.path.insert(1, '../../../Markopy/src/CLI/') + from base import BaseCLI + from mp import MarkovPasswordsCLI + from mmx import ModelMatrixCLI + else: + raise e + + +from termcolor import colored +from abc import abstractmethod + +class MarkopyCLI(BaseCLI): + def __init__(self, add_help=False): + super().__init__(add_help) + self.args = None + self.parser.epilog = f""" + {colored("Sample runs:", "yellow")} + {__file__.split("/")[-1]} -mt MP generate trained.mdl -n 500 -w output.txt + Import trained.mdl, and generate 500 lines to output.txt + + {__file__.split("/")[-1]} -mt MMX generate trained.mdl -n 500 -w output.txt + Import trained.mdl, and generate 500 lines to output.txt + """ + + def add_arguments(self): + self.parser.add_argument("-mt", "--model_type", default="_MMX", help="Model type to use. Accepted values: MP, MMX") + self.parser.add_argument("-h", "--help", action="store_true", help="Model type to use. Accepted values: MP, MMX") + self.parser.print_help = self.help + + @abstractmethod + def help(self): + self.parser.print_help = self.stub + self.args = self.parser.parse_known_args()[0] + if(self.args.model_type!="_MMX"): + if(self.args.model_type=="MP"): + mp = MarkovPasswordsCLI() + mp.add_arguments() + mp.parser.print_help() + elif(self.args.model_type=="MMX"): + mp = ModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + else: + print(colored("Model Mode selection choices:", "green")) + self.print_help() + print(colored("Following are applicable for -mt MP mode:", "green")) + mp = MarkovPasswordsCLI() + mp.add_arguments() + mp.parser.print_help() + print(colored("Following are applicable for -mt MMX mode:", "green")) + mp = ModelMatrixCLI() + mp.add_arguments() + mp.parser.print_help() + + exit() + + + @abstractmethod + def parse(self): + self.add_arguments() + self.parse_arguments() + self.init_post_arguments() + if(self.args.model_type == "MP"): + self.cli = MarkovPasswordsCLI() + elif(self.args.model_type == "MMX" or self.args.model_type == "_MMX"): + self.cli = ModelMatrixCLI() + else: + self.parse_fail() + + if(self.args.help): return self.help() + self.cli.parse() + + @abstractmethod + def parse_fail(self): + print("Unrecognized model type.") + exit() + + def process(self): + return self.cli.process() + + def stub(self): + return + + +if __name__ == "__main__": + mp = MarkopyCLI() + mp.parse() + mp.process() \ No newline at end of file diff --git a/Markopy/src/CLI/markopy_cli.py b/Markopy/src/CLI/markopy_cli.py deleted file mode 100644 index 0f51010e..00000000 --- a/Markopy/src/CLI/markopy_cli.py +++ /dev/null @@ -1,149 +0,0 @@ -import markopy -import argparse -import allogate as logging -import re -import os - -parser = argparse.ArgumentParser(description="Python wrapper for MarkovPasswords.", -epilog=f"""Sample runs: -{__file__} train untrained.mdl -d dataset.dat -s "\\t" -o trained.mdl - Import untrained.mdl, train it with dataset.dat which has tab delimited data, output resulting model to trained.mdl\n - -{__file__} generate trained.mdl -n 500 -w output.txt - Import trained.mdl, and generate 500 lines to output.txt - -{__file__} combine untrained.mdl -d dataset.dat -s "\\t" -n 500 -w output.txt - Train and immediately generate 500 lines to output.txt. Do not export trained model. - -{__file__} combine untrained.mdl -d dataset.dat -s "\\t" -n 500 -w output.txt -o trained.mdl - Train and immediately generate 500 lines to output.txt. Export trained model. -""", formatter_class=argparse.RawTextHelpFormatter) -parser.add_argument("mode", help="Operation mode, supported modes: \"generate\", \"train\" and \"combine\".") -parser.add_argument("input", help="Input model file. This model will be imported before starting operation.") -parser.add_argument("-o", "--output", help="Output model file. This model will be exported when done. Will be ignored for generation mode.") -parser.add_argument("-d", "--dataset", help="Dataset file to read input from for training. Will be ignored for generation mode.") -parser.add_argument("-s", "--seperator", help="Seperator character to use with training data.(character between occurrence and value)") -parser.add_argument("-w", "--wordlist", help="Wordlist file path to export generation results to. Will be ignored for training mode") -parser.add_argument("--min", default=6, help="Minimum length that is allowed during generation") -parser.add_argument("--max", default=12, help="Maximum length that is allowed during generation") -parser.add_argument("-n", "--count", help="Number of lines to generate. Ignored in training mode.") -parser.add_argument("-t", "--threads",default=10, help="Number of lines to generate. Ignored in training mode.") -parser.add_argument("-v", "--verbosity",action="count", help="Output verbosity.") -parser.add_argument("-b", "--bulk",action="store_true", help="Bulk generate or bulk train every corpus/model in the folder.") -args = parser.parse_args() - - - - -def cli_init(input_model): - logging.VERBOSITY = 0 - if args.verbosity: - logging.VERBOSITY = args.verbosity - logging.pprint(f"Verbosity set to {args.verbosity}.", 2) - - logging.pprint("Initializing model.", 1) - model = markopy.ModelMatrix() - logging.pprint("Model initialized.", 2) - - logging.pprint("Importing model file.", 1) - - if(not os.path.isfile(input_model)): - logging.pprint(f"Model file at {input_model} not found. Check the file path, or working directory") - exit(1) - - model.Import(input_model) - logging.pprint("Model imported successfully.", 2) - return model - -def cli_train(model, dataset, seperator, output, output_forced=False, bulk=False): - if not (dataset and seperator and (output or not output_forced)): - logging.pprint(f"Training mode requires -d/--dataset{', -o/--output' if output_forced else''} and -s/--seperator parameters. Exiting.") - exit(2) - - if(not bulk and not os.path.isfile(dataset)): - logging.pprint(f"{dataset} doesn't exists. Check the file path, or working directory") - exit(3) - - if(output and os.path.isfile(output)): - logging.pprint(f"{output} exists and will be overwritten.",1 ) - - if(seperator == '\\t'): - logging.pprint("Escaping seperator.", 3) - seperator = '\t' - - if(len(seperator)!=1): - logging.pprint(f'Delimiter must be a single character, and "{seperator}" is not accepted.') - exit(4) - - logging.pprint(f'Starting training.', 3) - model.Train(dataset,seperator, int(args.threads)) - logging.pprint(f'Training completed.', 2) - - if(output): - logging.pprint(f'Exporting model to {output}', 2) - model.Export(output) - else: - logging.pprint(f'Model will not be exported.', 1) - -def cli_generate(model, wordlist, bulk=False): - if not (wordlist or args.count): - logging.pprint("Generation mode requires -w/--wordlist and -n/--count parameters. Exiting.") - exit(2) - - if(bulk and os.path.isfile(wordlist)): - logging.pprint(f"{wordlist} exists and will be overwritten.", 1) - model.Generate(int(args.count), wordlist, int(args.min), int(args.max), int(args.threads)) - - -if(args.bulk): - logging.pprint(f"Bulk mode operation chosen.", 4) - - if (args.mode.lower() == "train"): - if (os.path.isdir(args.output) and not os.path.isfile(args.output)) and (os.path.isdir(args.dataset) and not os.path.isfile(args.dataset)): - corpus_list = os.listdir(args.dataset) - for corpus in corpus_list: - model = cli_init(args.input) - logging.pprint(f"Training {args.input} with {corpus}", 2) - output_file_name = corpus - model_extension = "" - if "." in args.input: - model_extension = args.input.split(".")[-1] - cli_train(model, f"{args.dataset}/{corpus}", args.seperator, f"{args.output}/{corpus}.{model_extension}", output_forced=True, bulk=True) - else: - logging.pprint("In bulk training, output and dataset should be a directory.") - exit(1) - - elif (args.mode.lower() == "generate"): - if (os.path.isdir(args.wordlist) and not os.path.isfile(args.wordlist)) and (os.path.isdir(args.input) and not os.path.isfile(args.input)): - model_list = os.listdir(args.input) - print(model_list) - for input in model_list: - logging.pprint(f"Generating from {args.input}/{input} to {args.wordlist}/{input}.txt", 2) - - model = cli_init(f"{args.input}/{input}") - model_base = input - if "." in args.input: - model_base = input.split(".")[1] - cli_generate(model, f"{args.wordlist}/{model_base}.txt", bulk=True) - else: - logging.pprint("In bulk generation, input and wordlist should be directory.") - -else: - model = cli_init(args.input) - if (args.mode.lower() == "generate"): - cli_generate(model, args.wordlist) - - - elif (args.mode.lower() == "train"): - cli_train(model, args.dataset, args.seperator, args.output, output_forced=True) - - - elif(args.mode.lower() == "combine"): - cli_train(model, args.dataset, args.seperator, args.output) - cli_generate(model, args.wordlist) - - - else: - logging.pprint("Invalid mode arguement given.") - logging.pprint("Accepted modes: 'Generate', 'Train', 'Combine'") - exit(5) \ No newline at end of file diff --git a/Markopy/src/CLI/mmx.py b/Markopy/src/CLI/mmx.py new file mode 100644 index 00000000..b12c0d93 --- /dev/null +++ b/Markopy/src/CLI/mmx.py @@ -0,0 +1,50 @@ +""" @package markopy + @file mmx_cli.py + @namespace Python::Markopy::ModelMatrix + @brief Command line class for ModelMatrix + @authors Ata Hakçıl +""" + +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader, ExtensionFileLoader +import os +ext = "so" +if os.name == 'nt': + ext="pyd" +try: + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) +except ImportError as e: + print(f"({__file__}) Working in development mode. Trying to load markopy.{ext} from ../../../out/") + if(os.path.exists(f"../../../out/lib/markopy.{ext}")): + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"../../../out/lib/markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) + else: + raise e + +from base import BaseCLI, AbstractGenerationModelCLI +import os +import allogate as logging + +class ModelMatrixCLI(AbstractGenerationModelCLI): + def __init__(self): + super().__init__() + self.model = markopy.ModelMatrix() + + def add_arguments(self): + super().add_arguments() + self.parser.add_argument("-st", "--stdout", action="store_true", help="Stdout mode") + + def init_post_arguments(self): + super().init_post_arguments() + self.fileIO = not self.args.stdout + + def _generate(self, wordlist : str, ): + self.model.FastRandomWalk(int(self.args.count), wordlist, int(self.args.min), int(self.args.max), int(self.args.threads), self.fileIO) + +if __name__ == "__main__": + mp = ModelMatrixCLI() + mp.parse() + mp.process() \ No newline at end of file diff --git a/Markopy/src/CLI/mp.py b/Markopy/src/CLI/mp.py new file mode 100644 index 00000000..1150dffe --- /dev/null +++ b/Markopy/src/CLI/mp.py @@ -0,0 +1,41 @@ +""" @package markopy + @file mp_cli.py + @namespace Python::Markopy::MarkovPasswords + @brief Command line class for MarkovPasswords + @authors Ata Hakçıl +""" +from importlib.util import spec_from_loader, module_from_spec +from importlib.machinery import SourceFileLoader, ExtensionFileLoader +import os +ext = "so" +if os.name == 'nt': + ext="pyd" +try: + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) +except ImportError as e: + print(f"({__file__}) Working in development mode. Trying to load markopy.{ext} from ../../../out/") + if(os.path.exists(f"../../../out/lib/markopy.{ext}")): + spec = spec_from_loader("markopy", ExtensionFileLoader("markopy", os.path.abspath(f"../../../out/lib/markopy.{ext}"))) + markopy = module_from_spec(spec) + spec.loader.exec_module(markopy) + else: + raise e + +from base import BaseCLI,AbstractGenerationModelCLI, AbstractTrainingModelCLI + + + +class MarkovPasswordsCLI(AbstractTrainingModelCLI): + def __init__(self): + super().__init__() + self.model = markopy.MarkovPasswords() + + def _generate(self, wordlist): + self.model.Generate(int(self.args.count), wordlist, int(self.args.min), int(self.args.max), int(self.args.threads)) + +if __name__ == "__main__": + mp = MarkovPasswordsCLI() + mp.parse() + mp.process() \ No newline at end of file diff --git a/Markopy/src/CLI/sample_models/2gram-trained.mdl b/Markopy/src/CLI/sample_models/2gram-trained.mdl deleted file mode 100644 index f33c21e8..00000000 Binary files a/Markopy/src/CLI/sample_models/2gram-trained.mdl and /dev/null differ diff --git a/Markopy/src/Module/markopy.cpp b/Markopy/src/Module/markopy.cpp index 38d4a1d7..7b518d9d 100644 --- a/Markopy/src/Module/markopy.cpp +++ b/Markopy/src/Module/markopy.cpp @@ -1,10 +1,32 @@ -#pragma once -#include "../../../MarkovPasswords/src/markovPasswords.h" +/** @file markopy.cpp + * @brief CPython wrapper for libmarkov utils. + * @authors Ata Hakçıl, Celal Sahir Çetiner + * + * This file is a wrapper for libmarkov utilities, exposing: + * - MarkovPasswords + * - Import + * - Export + * - Train + * - Generate + * - ModelMatrix + * - Import + * - Export + * - Train + * - ConstructMatrix + * - DumpJSON + * - FastRandomWalk + * + * @copydoc Markov::API::MarkovPasswords + * @copydoc Markov::API::ModelMatrix + * +*/ -#define BOOST_PYTHON_STATIC_LIB +#define BOOST_ALL_STATIC_LIB 1 +#define BOOST_PYTHON_STATIC_LIB 1 #include #include -#include +#include + using namespace boost::python; diff --git a/MarkovAPI/CMakeLists.txt b/MarkovAPI/CMakeLists.txt new file mode 100644 index 00000000..52fcb6b8 --- /dev/null +++ b/MarkovAPI/CMakeLists.txt @@ -0,0 +1,38 @@ +# CMakeList.txt : CMake project for MarkovAPI, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.8) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include_directories(${PROJECT_SOURCE_DIR}) +link_directories(${PROJECT_SOURCE_DIR}/out/lib) + + + +file(GLOB_RECURSE MPLIB_FILES + "src/*.h" + "src/*.cpp" + "../MarkovModel/src/*.h" +) +if (WIN32) + add_library(markov STATIC ${MPLIB_FILES} ) +else() + add_library(markov SHARED ${MPLIB_FILES} ) +endif() + +set(MPLIB_CPP_FLAGS "${MPLIB_C_FLAGS} -std=c++17") +if(WIN32) +set(MPLIB_LINK_FLAGS "${SGX_COMMON_CFLAGS}") +else() +set(MPLIB_LINK_FLAGS "${SGX_COMMON_CFLAGS} -Wl,-rpath='${ORIGIN}'") +endif() + +set_target_properties(markov PROPERTIES COMPILE_FLAGS "${MPLIB_CPP_FLAGS}") +set_target_properties(markov PROPERTIES LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPLIB_LINK_FLAGS}") +set_target_properties(markov PROPERTIES LINKER_LANGUAGE CXX) diff --git a/MarkovPasswords/src/markovPasswords.cpp b/MarkovAPI/src/markovPasswords.cpp similarity index 93% rename from MarkovPasswords/src/markovPasswords.cpp rename to MarkovAPI/src/markovPasswords.cpp index 162d9c1d..9219d6b5 100644 --- a/MarkovPasswords/src/markovPasswords.cpp +++ b/MarkovAPI/src/markovPasswords.cpp @@ -1,4 +1,12 @@ -#pragma once +/** @file markovPasswords.cpp + * @brief Wrapper for Markov::Model to use with char represented models. + * @authors Ata Hakçıl, Osman Ömer Yıldıztugay + * + * This file contains the implementation for Markov::API::MarkovPasswords class. + * + * @copydoc Markov::API::MarkovPasswords + */ + #include "markovPasswords.h" #include #include diff --git a/MarkovPasswords/src/markovPasswords.h b/MarkovAPI/src/markovPasswords.h similarity index 94% rename from MarkovPasswords/src/markovPasswords.h rename to MarkovAPI/src/markovPasswords.h index fd1370e9..dde2505a 100644 --- a/MarkovPasswords/src/markovPasswords.h +++ b/MarkovAPI/src/markovPasswords.h @@ -1,3 +1,12 @@ +/** @file markovPasswords.h + * @brief Wrapper for Markov::Model to use with char represented models. + * @authors Ata Hakçıl, Osman Ömer Yıldıztugay + * + * This file contains the declerations for Markov::API::MarkovPasswords class. + * + * @copydoc Markov::API::MarkovPasswords + */ + #pragma once #include "threadSharedListHandler.h" #include "MarkovModel/src/model.h" diff --git a/MarkovPasswords/src/modelMatrix.cpp b/MarkovAPI/src/modelMatrix.cpp similarity index 96% rename from MarkovPasswords/src/modelMatrix.cpp rename to MarkovAPI/src/modelMatrix.cpp index 5702eabe..cffab3d9 100644 --- a/MarkovPasswords/src/modelMatrix.cpp +++ b/MarkovAPI/src/modelMatrix.cpp @@ -1,3 +1,12 @@ +/** @file modelMatrix.cpp + * @brief An extension of Markov::API::MarkovPasswords + * @authors Ata Hakçıl + * + * This class shows superior performance compared to the traditional model at Markov::API::MarkovPasswords + * + * @copydoc Markov::API::ModelMatrix + */ + #include "modelMatrix.h" #include #include diff --git a/MarkovPasswords/src/modelMatrix.h b/MarkovAPI/src/modelMatrix.h similarity index 96% rename from MarkovPasswords/src/modelMatrix.h rename to MarkovAPI/src/modelMatrix.h index 7cdc8756..24164a2e 100644 --- a/MarkovPasswords/src/modelMatrix.h +++ b/MarkovAPI/src/modelMatrix.h @@ -1,3 +1,13 @@ +/** @file modelMatrix.h + * @brief An extension of Markov::API::MarkovPasswords + * @authors Ata Hakçıl + * + * This class shows superior performance compared to the traditional model at Markov::API::MarkovPasswords + * + * @copydoc Markov::API::ModelMatrix + * + */ + #include "markovPasswords.h" #include diff --git a/MarkovPasswords/src/threadSharedListHandler.cpp b/MarkovAPI/src/threadSharedListHandler.cpp similarity index 71% rename from MarkovPasswords/src/threadSharedListHandler.cpp rename to MarkovAPI/src/threadSharedListHandler.cpp index 2f2a5086..9a45660e 100644 --- a/MarkovPasswords/src/threadSharedListHandler.cpp +++ b/MarkovAPI/src/threadSharedListHandler.cpp @@ -1,3 +1,11 @@ +/** @file threadSharedListHandler.cpp + * @brief Thread-safe wrapper for std::ifstream + * @authors Ata Hakçıl + * + * @copydoc Markov::API::Concurrency::ThreadSharedListHandler + * + */ + #include "threadSharedListHandler.h" diff --git a/MarkovPasswords/src/threadSharedListHandler.h b/MarkovAPI/src/threadSharedListHandler.h similarity index 94% rename from MarkovPasswords/src/threadSharedListHandler.h rename to MarkovAPI/src/threadSharedListHandler.h index 65f55bc3..6895d19f 100644 --- a/MarkovPasswords/src/threadSharedListHandler.h +++ b/MarkovAPI/src/threadSharedListHandler.h @@ -1,3 +1,10 @@ +/** @file threadSharedListHandler.h + * @brief Thread-safe wrapper for std::ifstream + * @authors Ata Hakçıl + * + * @copydoc Markov::API::Concurrency::ThreadSharedListHandler + */ + #include #include #include diff --git a/MarkovAPICLI/CMakeLists.txt b/MarkovAPICLI/CMakeLists.txt new file mode 100644 index 00000000..c7886b53 --- /dev/null +++ b/MarkovAPICLI/CMakeLists.txt @@ -0,0 +1,54 @@ +# CMakeList.txt : CMake project for MarkovAPICLI, include source and define +# project specific logic here. +# +cmake_minimum_required (VERSION 3.8) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/bin) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include_directories(${PROJECT_SOURCE_DIR}) +link_directories(${PROJECT_SOURCE_DIR}/out/lib) + + +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) + +set(THREADS_PREFER_PTHREAD_FLAG ON) + +file(GLOB_RECURSE MP_FILES + "src/*.h" + "src/*.cpp" +) + +if(WIN32) + link_directories( $ENV{BOOST_ROOT}/stage/lib/) +endif() + +add_executable(markovp ${MP_FILES} ) + +add_dependencies (markovp markov) + +set(MP_CPP_FLAGS "${MP_C_FLAGS} -std=c++17") + +set(MP_LINK_FLAGS "${SGX_COMMON_CFLAGS}") + +set_target_properties(markovp PROPERTIES COMPILE_FLAGS "${MP_CPP_FLAGS}") +set_target_properties(markovp PROPERTIES LINK_FLAGS "${MP_LINK_FLAGS}") + +set_target_properties(markovp PROPERTIES LINKER_LANGUAGE CXX) +find_package(Threads REQUIRED) +if(BOOST_VER) + find_package(Boost ${BOOST_VER} COMPONENTS program_options REQUIRED) +else() +find_package(Boost COMPONENTS program_options REQUIRED) +endif() +target_link_libraries(markovp Boost::program_options) +target_link_libraries(markovp Threads::Threads) +target_link_libraries(markovp markov) + + diff --git a/MarkovPasswords/src/argparse.cpp b/MarkovAPICLI/src/argparse.cpp similarity index 84% rename from MarkovPasswords/src/argparse.cpp rename to MarkovAPICLI/src/argparse.cpp index 6c51891d..35321826 100644 --- a/MarkovPasswords/src/argparse.cpp +++ b/MarkovAPICLI/src/argparse.cpp @@ -1,3 +1,10 @@ +/** @file argparse.cpp + * @brief Arguement handler class for native CPP cli + * @authors Celal Sahir Çetiner + * + * @copydoc Markov::API::CLI::Argparse + */ + #include "argparse.h" #include "color/term.h" diff --git a/MarkovPasswords/src/argparse.h b/MarkovAPICLI/src/argparse.h similarity index 96% rename from MarkovPasswords/src/argparse.h rename to MarkovAPICLI/src/argparse.h index efb632df..121c8539 100644 --- a/MarkovPasswords/src/argparse.h +++ b/MarkovAPICLI/src/argparse.h @@ -1,7 +1,15 @@ +/** @file argparse.h + * @brief Arguement handler class for native CPP cli + * @authors Celal Sahir Çetiner + * + * @copydoc Markov::API::CLI::Argparse: + */ + #include #include -#define BOOST_ALL_DYN_LINK 1 +#define BOOST_ALL_STATIC_LIB 1 +#define BOOST_PROGRAM_OPTIONS_STATIC_LIB 1 #include diff --git a/MarkovPasswords/datasets/.gitkeep b/MarkovAPICLI/src/color/.gitkeep similarity index 100% rename from MarkovPasswords/datasets/.gitkeep rename to MarkovAPICLI/src/color/.gitkeep diff --git a/MarkovPasswords/src/color/term.cpp b/MarkovAPICLI/src/color/term.cpp similarity index 91% rename from MarkovPasswords/src/color/term.cpp rename to MarkovAPICLI/src/color/term.cpp index a3b2c6c8..64537caa 100644 --- a/MarkovPasswords/src/color/term.cpp +++ b/MarkovAPICLI/src/color/term.cpp @@ -1,4 +1,10 @@ -#pragma once +/** @file term.cpp + * @brief Terminal handler for pretty stuff like colors + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CLI::Terminal + */ + #include "term.h" #include diff --git a/MarkovPasswords/src/color/term.h b/MarkovAPICLI/src/color/term.h similarity index 89% rename from MarkovPasswords/src/color/term.h rename to MarkovAPICLI/src/color/term.h index 3765ef82..1db19715 100644 --- a/MarkovPasswords/src/color/term.h +++ b/MarkovAPICLI/src/color/term.h @@ -1,3 +1,10 @@ +/** @file term.h + * @brief Terminal handler for pretty stuff like colors + * @authors Ata Hakçıl + * + * @copydoc Markov::API::CLI::Terminal + */ + #pragma once #ifdef _WIN32 diff --git a/MarkovPasswords/src/main.cpp b/MarkovAPICLI/src/main.cpp similarity index 79% rename from MarkovPasswords/src/main.cpp rename to MarkovAPICLI/src/main.cpp index b51f1227..18103ba4 100644 --- a/MarkovPasswords/src/main.cpp +++ b/MarkovAPICLI/src/main.cpp @@ -1,3 +1,12 @@ +/** @file main.cpp + * @brief Test cases for Markov::API::ModelMatrix + * @authors Ata Hakçıl, Celal Sahir Çetiner + * + * @copydoc Markov::API::CLI::Argparse + * @copydoc Markov::API::ModelMatrix + * @copydoc Markov::API::MarkovPasswords + */ + #pragma once #include #include "color/term.h" @@ -5,8 +14,8 @@ #include #include #include -#include "markovPasswords.h" -#include "modelMatrix.h" +#include "MarkovAPI/src/markovPasswords.h" +#include "MarkovAPI/src/modelMatrix.h" #include /** @brief Launch CLI tool. diff --git a/MarkovPasswords/src/color/.gitkeep b/MarkovAPICLI/src/model/.gitkeep similarity index 100% rename from MarkovPasswords/src/color/.gitkeep rename to MarkovAPICLI/src/model/.gitkeep diff --git a/MarkovPasswords/src/scripts/model_2gram.py b/MarkovAPICLI/src/scripts/model_2gram.py similarity index 100% rename from MarkovPasswords/src/scripts/model_2gram.py rename to MarkovAPICLI/src/scripts/model_2gram.py diff --git a/MarkovPasswords/src/scripts/random-model.py b/MarkovAPICLI/src/scripts/random-model.py similarity index 100% rename from MarkovPasswords/src/scripts/random-model.py rename to MarkovAPICLI/src/scripts/random-model.py diff --git a/MarkovPasswords/src/model/.gitkeep b/MarkovModel/CMakeLists.txt similarity index 100% rename from MarkovPasswords/src/model/.gitkeep rename to MarkovModel/CMakeLists.txt diff --git a/MarkovModel/MarkovModel.vcxproj b/MarkovModel/MarkovModel.vcxproj deleted file mode 100644 index f166e3c2..00000000 --- a/MarkovModel/MarkovModel.vcxproj +++ /dev/null @@ -1,258 +0,0 @@ - - - - - Debug - Win32 - - - DLL Model - Win32 - - - DLL Model - x64 - - - Lib Model - Win32 - - - Lib Model - x64 - - - Debug - x64 - - - - 16.0 - Win32Proj - {a5d3fa06-3885-41f2-ad3d-f3d8fbc4c048} - MarkovModel - 10.0 - - - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - StaticLibrary - false - v142 - true - Unicode - - - DynamicLibrary - true - v142 - Unicode - - - DynamicLibrary - false - v142 - true - Unicode - - - StaticLibrary - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - - - - - true - - - false - - - false - - - true - - - false - $(SolutionDir)$(Platform)\Release\ - $(SolutionDir)$(Platform)\intermediate\MarkovModel\ - - - false - $(SolutionDir)$(Platform)\lib\ - $(Platform)\lib\ - - - - Level3 - true - WIN32;_DEBUG;MARKOVMODEL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - %(AdditionalIncludeDirectories);$(SolutionDir); - - - Windows - true - false - - - - - Level3 - true - true - true - WIN32;NDEBUG;MARKOVMODEL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - %(AdditionalIncludeDirectories);$(SolutionDir); - - - Windows - true - true - true - false - - - - - Level3 - true - true - true - WIN32;NDEBUG;MARKOVMODEL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - Use - pch.h - %(AdditionalIncludeDirectories);$(SolutionDir); - - - Windows - true - true - true - false - - - - - Level3 - true - _DEBUG;MARKOVMODEL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - NotUsing - pch.h - stdcpp17 - %(AdditionalIncludeDirectories);$(SolutionDir); - - - Windows - true - false - - - - - Level3 - true - true - true - NDEBUG;MARKOVMODEL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - NotUsing - pch.h - stdcpp17 - %(AdditionalIncludeDirectories);$(SolutionDir); - - - Windows - true - true - true - false - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - $(IntDir)$(TargetName).device-link.obj - - - - - Level3 - true - true - true - NDEBUG;MARKOVMODEL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - NotUsing - pch.h - %(AdditionalIncludeDirectories);$(SolutionDir); - stdcpp17 - - - Windows - true - true - true - false - - - $(IntDir)$(TargetName).device-link.obj - cudart.lib - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MarkovModel/MarkovModel.vcxproj.filters b/MarkovModel/MarkovModel.vcxproj.filters deleted file mode 100644 index 212cb18f..00000000 --- a/MarkovModel/MarkovModel.vcxproj.filters +++ /dev/null @@ -1,42 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/MarkovModel/src/dllmain.cpp b/MarkovModel/src/dllmain.cpp index 64afc084..f375ee84 100644 --- a/MarkovModel/src/dllmain.cpp +++ b/MarkovModel/src/dllmain.cpp @@ -1,3 +1,10 @@ +/** @file dllmain.cpp + * @brief DLLMain for dynamic windows library + * @authors Ata Hakçıl + * + * @copydoc Markov::Model + */ + #include "pch.h" #include "model.h" #include diff --git a/MarkovModel/src/edge.h b/MarkovModel/src/edge.h index 291c24dd..58e2a319 100644 --- a/MarkovModel/src/edge.h +++ b/MarkovModel/src/edge.h @@ -1,3 +1,10 @@ +/** @file edge.h + * @brief Edge class template + * @authors Ata Hakçıl, Osman Ömer Yıldıztugay + * + * @copydoc Markov::Edge + */ + #pragma once #include #include diff --git a/MarkovModel/src/framework.h b/MarkovModel/src/framework.h index 9c786581..60e45053 100644 --- a/MarkovModel/src/framework.h +++ b/MarkovModel/src/framework.h @@ -1,3 +1,9 @@ +/** @file framework.h + * @brief for windows dynamic library + * @authors Ata Hakçıl + * + */ + #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers diff --git a/MarkovModel/src/model.h b/MarkovModel/src/model.h index c93f1b85..141bfb00 100644 --- a/MarkovModel/src/model.h +++ b/MarkovModel/src/model.h @@ -1,8 +1,12 @@ -/** @dir Model.h - * +/** @file model.h + * @brief Model class template + * @authors Ata Hakçıl, Osman Ömer Yıldıztugay + * + * @copydoc Markov::Model */ + #pragma once #include #include diff --git a/MarkovModel/src/node.h b/MarkovModel/src/node.h index b57af18c..ff8ebe87 100644 --- a/MarkovModel/src/node.h +++ b/MarkovModel/src/node.h @@ -1,3 +1,11 @@ +/** @file node.h + * @brief Node class template + * @authors Ata Hakçıl, Osman Ömer Yıldıztugay + * + * @copydoc Markov::Node + */ + + #pragma once #include #include diff --git a/MarkovModel/src/pch.cpp b/MarkovModel/src/pch.cpp index 836643d9..f2198816 100644 --- a/MarkovModel/src/pch.cpp +++ b/MarkovModel/src/pch.cpp @@ -1,3 +1,9 @@ +/** @file pch.cpp + * @brief For windows dynamic library + * @authors Ata Hakçıl + * + */ + // pch.cpp: source file corresponding to the pre-compiled header #include "pch.h" diff --git a/MarkovModel/src/pch.h b/MarkovModel/src/pch.h index 01de5b8e..4d881b80 100644 --- a/MarkovModel/src/pch.h +++ b/MarkovModel/src/pch.h @@ -1,3 +1,8 @@ +/** @file pch.h + * @brief For windows dynamic library + * @authors Ata Hakçıl + * + */ // pch.h: This is a precompiled header file. // Files listed below are compiled only once, improving build performance for future builds. // This also affects IntelliSense performance, including code completion and many code browsing features. diff --git a/MarkovModel/src/random.h b/MarkovModel/src/random.h index c99a37fe..4886e2ce 100644 --- a/MarkovModel/src/random.h +++ b/MarkovModel/src/random.h @@ -1,4 +1,13 @@ +/** @file random.h + * @brief Random engine implementations for Markov + * @authors Ata Hakçıl + * + * @copydoc Markov::Random::RandomEngine + * @copydoc Markov::Random::DefaultRandomEngine + * @copydoc Markov::Random::Marsaglia + */ + #pragma once #include #include diff --git a/MarkovPasswords.sln b/MarkovPasswords.sln deleted file mode 100644 index ad7764f8..00000000 --- a/MarkovPasswords.sln +++ /dev/null @@ -1,133 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29806.167 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MarkovPasswords", "MarkovPasswords\MarkovPasswords.vcxproj", "{B356D85A-CAC3-4EF2-824B-59E3E49110CB}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MarkovModel", "MarkovModel\MarkovModel.vcxproj", "{A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MarkovPasswordsGUI", "MarkovPasswordsGUI\MarkovPasswordsGUI.vcxproj", "{A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{51EF2F95-7DD3-451E-A6FC-209FAE4ECB43}" - ProjectSection(SolutionItems) = preProject - ..\documentation\Doxyfile = ..\documentation\Doxyfile - ..\documentation\Doxyfile-mcss = ..\documentation\Doxyfile-mcss - ..\documentation\mcss.conf.py = ..\documentation\mcss.conf.py - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests\UnitTests.vcxproj", "{26260E27-B240-4E67-AE52-A6919A8DBF5C}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflows", "Workflows", "{AEB3CC8A-A675-4CCA-BF3C-DA486B448C1C}" - ProjectSection(SolutionItems) = preProject - ..\.github\workflows\msbuild.yml = ..\.github\workflows\msbuild.yml - ..\.github\workflows\Sonar-scan.yml = ..\.github\workflows\Sonar-scan.yml - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "markopy", "Markopy\Markopy.vcxproj", "{B3B712C9-FE83-4A38-ADF1-61B01370FF95}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CudaMarkovPasswords", "CudaMarkovPasswords\CudaMarkovPasswords.vcxproj", "{ACCAF49C-AED2-4977-AE26-90B72C960779}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - DLL Model|x64 = DLL Model|x64 - DLL Model|x86 = DLL Model|x86 - Lib Model|x64 = Lib Model|x64 - Lib Model|x86 = Lib Model|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Debug|x64.ActiveCfg = Debug|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Debug|x64.Build.0 = Debug|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Debug|x86.ActiveCfg = Debug|Win32 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Debug|x86.Build.0 = Debug|Win32 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.DLL Model|x64.ActiveCfg = Debug|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.DLL Model|x64.Build.0 = Debug|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.DLL Model|x86.ActiveCfg = Debug|Win32 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Lib Model|x64.ActiveCfg = Release|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Lib Model|x64.Build.0 = Release|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Lib Model|x86.ActiveCfg = Release|Win32 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Release|x64.ActiveCfg = Release|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Release|x64.Build.0 = Release|x64 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Release|x86.ActiveCfg = Release|Win32 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB}.Release|x86.Build.0 = Release|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Debug|x64.ActiveCfg = Debug|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Debug|x64.Build.0 = Debug|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Debug|x86.ActiveCfg = Debug|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Debug|x86.Build.0 = Debug|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.DLL Model|x64.ActiveCfg = DLL Model|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.DLL Model|x64.Build.0 = DLL Model|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.DLL Model|x86.ActiveCfg = DLL Model|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.DLL Model|x86.Build.0 = DLL Model|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Lib Model|x64.ActiveCfg = Lib Model|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Lib Model|x64.Build.0 = Lib Model|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Lib Model|x86.ActiveCfg = Lib Model|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Lib Model|x86.Build.0 = Lib Model|Win32 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Release|x64.ActiveCfg = DLL Model|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Release|x64.Build.0 = DLL Model|x64 - {A5D3FA06-3885-41F2-AD3D-F3D8FBC4C048}.Release|x86.ActiveCfg = Release|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Debug|x64.ActiveCfg = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Debug|x86.ActiveCfg = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.DLL Model|x64.ActiveCfg = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.DLL Model|x86.ActiveCfg = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.DLL Model|x86.Build.0 = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Lib Model|x64.ActiveCfg = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Lib Model|x86.ActiveCfg = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Lib Model|x86.Build.0 = Debug|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Release|x64.ActiveCfg = Release|x64 - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114}.Release|x86.ActiveCfg = Release|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Debug|x64.ActiveCfg = Debug|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Debug|x64.Build.0 = Debug|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Debug|x86.ActiveCfg = Debug|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Debug|x86.Build.0 = Debug|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.DLL Model|x64.ActiveCfg = Debug|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.DLL Model|x64.Build.0 = Debug|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.DLL Model|x86.ActiveCfg = Debug|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.DLL Model|x86.Build.0 = Debug|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Lib Model|x64.ActiveCfg = Debug|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Lib Model|x64.Build.0 = Debug|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Lib Model|x86.ActiveCfg = Debug|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Lib Model|x86.Build.0 = Debug|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Release|x64.ActiveCfg = Release|x64 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Release|x86.ActiveCfg = Release|Win32 - {26260E27-B240-4E67-AE52-A6919A8DBF5C}.Release|x86.Build.0 = Release|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Debug|x64.ActiveCfg = Debug|x64 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Debug|x86.ActiveCfg = Debug|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Debug|x86.Build.0 = Debug|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.DLL Model|x64.ActiveCfg = Debug|x64 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.DLL Model|x86.ActiveCfg = Debug|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.DLL Model|x86.Build.0 = Debug|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Lib Model|x64.ActiveCfg = Debug|x64 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Lib Model|x86.ActiveCfg = Debug|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Lib Model|x86.Build.0 = Debug|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Release|x64.ActiveCfg = Release|x64 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Release|x64.Build.0 = Release|x64 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Release|x86.ActiveCfg = Release|Win32 - {B3B712C9-FE83-4A38-ADF1-61B01370FF95}.Release|x86.Build.0 = Release|Win32 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Debug|x64.ActiveCfg = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Debug|x64.Build.0 = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Debug|x86.ActiveCfg = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.DLL Model|x64.ActiveCfg = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.DLL Model|x64.Build.0 = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.DLL Model|x86.ActiveCfg = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.DLL Model|x86.Build.0 = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Lib Model|x64.ActiveCfg = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Lib Model|x64.Build.0 = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Lib Model|x86.ActiveCfg = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Lib Model|x86.Build.0 = Debug|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Release|x64.ActiveCfg = Release|x64 - {ACCAF49C-AED2-4977-AE26-90B72C960779}.Release|x86.ActiveCfg = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {AEB3CC8A-A675-4CCA-BF3C-DA486B448C1C} = {51EF2F95-7DD3-451E-A6FC-209FAE4ECB43} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {B06B8420-E171-4605-81F1-86DF1D0075A3} - EndGlobalSection -EndGlobal diff --git a/MarkovPasswords/MarkovPasswords.vcxproj b/MarkovPasswords/MarkovPasswords.vcxproj deleted file mode 100644 index 357f24d4..00000000 --- a/MarkovPasswords/MarkovPasswords.vcxproj +++ /dev/null @@ -1,175 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {B356D85A-CAC3-4EF2-824B-59E3E49110CB} - MarkovPasswordsVS - 10.0 - - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - Application - true - v142 - Unicode - - - Application - false - v142 - true - Unicode - - - - - - - - - - - - - - - - - - - - true - - - true - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(SolutionDir)x64/lib/; - - - false - - - false - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(SolutionDir)x64/lib/; - $(SolutionDir)$(Platform)\intermediate\MarkovPasswords\ - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - $(BOOST_ROOT); - stdcpp17 - - - Console - true - $(BOOST_ROOT)\stage\lib - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions); - true - $(BOOST_ROOT);$(SolutionDir)MarkovModel/src/;$(SolutionDir) - stdcpp17 - - - - - Console - true - true - true - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);libboost_program_options-*.lib - $(BOOST_ROOT)\stage\lib - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MarkovPasswords/MarkovPasswords.vcxproj.filters b/MarkovPasswords/MarkovPasswords.vcxproj.filters deleted file mode 100644 index 536f9b22..00000000 --- a/MarkovPasswords/MarkovPasswords.vcxproj.filters +++ /dev/null @@ -1,76 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {eeec6f5d-9d3b-4b79-a294-d546052f4c0d} - - - {cde31620-4999-4a0a-bff7-9f82eeedc2bf} - - - {f32c89b1-88f7-47e3-91a3-18b2f45dd01a} - - - {53549677-4457-4e63-9e1b-ba68ca41324d} - - - - - Source Files - - - Header Files\termcolor - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files\termcolor - - - Header Files - - - Header Files - - - Header Files - - Header Files\model - - - Header Files\model - - - Header Files\model - - - - - models - - - scripts - - - \ No newline at end of file diff --git a/MarkovPasswords/models/2gram-built.mdl b/MarkovPasswords/models/2gram-built.mdl deleted file mode 100644 index ea66d84a..00000000 Binary files a/MarkovPasswords/models/2gram-built.mdl and /dev/null differ diff --git a/MarkovPasswords/models/2gram.mdl b/MarkovPasswords/models/2gram.mdl deleted file mode 100644 index 300ab501..00000000 Binary files a/MarkovPasswords/models/2gram.mdl and /dev/null differ diff --git a/MarkovPasswordsGUI/CMakeLists.txt b/MarkovPasswordsGUI/CMakeLists.txt new file mode 100644 index 00000000..2c974048 --- /dev/null +++ b/MarkovPasswordsGUI/CMakeLists.txt @@ -0,0 +1,57 @@ +# CMakeList.txt : CMake project for MarkovPasswordsGUI, include source and define +# project specific logic here. +# + +cmake_minimum_required (VERSION 3.8) + +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/out/bin) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include_directories(${PROJECT_SOURCE_DIR}) +include_directories(${CMAKE_CURRENT_BINARY_DIR}) +link_directories( ${PROJECT_SOURCE_DIR}/out/lib) + + + +file(GLOB_RECURSE MPGUI_UI + "*.ui" + "src/*.ui" +) + + +find_package(Qt5 COMPONENTS Widgets REQUIRED) +find_package(Qt5 COMPONENTS WebEngineWidgets REQUIRED) +find_package(Qt5 COMPONENTS Core REQUIRED) + +qt5_wrap_ui(UIS_HDRS ${MPGUI_UI}) + +file(GLOB_RECURSE MPGUI_FILES + "src/*.cpp" + "src/*.h" +) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + + + +add_executable(MPGUI ${MPGUI_FILES} ${UIS_HDRS}) + +add_dependencies (MPGUI markov) + +target_link_libraries(MPGUI markov) +target_link_libraries(MPGUI Qt5::Widgets) +target_link_libraries(MPGUI Qt5::Core) +target_link_libraries(MPGUI Qt5::WebEngineWidgets ) + + + + + + + + diff --git a/MarkovPasswordsGUI/MarkovPasswordsGUI.vcxproj b/MarkovPasswordsGUI/MarkovPasswordsGUI.vcxproj deleted file mode 100644 index afc50c9d..00000000 --- a/MarkovPasswordsGUI/MarkovPasswordsGUI.vcxproj +++ /dev/null @@ -1,168 +0,0 @@ - - - - - Debug - x64 - - - Release - x64 - - - - {A9ECF03B-D971-47D9-B0A9-D0B4A3DBB114} - QtVS_v303 - $(MSBuildProjectDirectory)\QtMsBuild - - - - Application - v142 - - - Application - v142 - - - - - - - - - - - - - - - - - - - - - - - - stdcpp17 - $(Qt_INCLUDEPATH_);%(AdditionalIncludeDirectories);$(SolutionDir); - - - - - stdcpp17 - $(Qt_INCLUDEPATH_);%(AdditionalIncludeDirectories);$(SolutionDir); - - - - core;gui;widgets;webenginewidgets; - debug - 5.15.2_msvc2019_64 - - - core;gui;widgets;webenginewidgets; - release - 5.15.2_msvc2019_64 - - - - - - - true - true - ProgramDatabase - Disabled - MultiThreadedDebugDLL - - - Windows - true - - - - - true - true - None - MaxSpeed - MultiThreadedDLL - - - Windows - false - - - - - - - - - - - - - - - true - - - - - - - - - true - - - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MarkovPasswordsGUI/MarkovPasswordsGUI.vcxproj.filters b/MarkovPasswordsGUI/MarkovPasswordsGUI.vcxproj.filters deleted file mode 100644 index 1508b21a..00000000 --- a/MarkovPasswordsGUI/MarkovPasswordsGUI.vcxproj.filters +++ /dev/null @@ -1,158 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {99349809-55BA-4b9d-BF79-8FDBB0286EB3} - ui - - - {D9D6E242-F8AF-46E4-B9FD-80ECBC20BA3E} - qrc;* - false - - - {3c3f933a-cec8-4731-b7a0-77b5b4b2e1cb} - - - {a16bc5c3-bf52-491c-ab24-3439caad494e} - - - - - Resource Files - - - Resource Files - - - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - Source Files\views - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files\dependencies - - - Source Files - - - - - Header Files - - - Header Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - - - Source Files\views - - - Source Files\views - - - \ No newline at end of file diff --git a/MarkovPasswordsGUI/conf.vcxproj b/MarkovPasswordsGUI/conf.vcxproj deleted file mode 100644 index a1be0e91..00000000 --- a/MarkovPasswordsGUI/conf.vcxproj +++ /dev/null @@ -1,328 +0,0 @@ - - - - - Debug - x64 - - - Release - Win32 - - - Debug - Win32 - - - Release - x64 - - - - {FEBBD490-6FC2-3600-A4FE-7B4CDCE06A84} - conf - QtVS_v303 - 10.0 - $(MSBuildProjectDirectory)\QtMsBuild - - - - v142 - release\ - false - NotSet - Application - release\ - conf - - - v142 - release\ - false - NotSet - Application - release\ - conf - - - v142 - debug\ - false - NotSet - Application - debug\ - conf - - - v142 - debug\ - false - NotSet - Application - debug\ - conf - - - - - - - - - - - - - - - - - - - - - - - - debug\ - debug\ - conf - true - - - conf - true - - - release\ - release\ - conf - true - false - - - conf - true - false - - - 5.12.10 - core;gui - - - 5.12.10 - core;gui - - - 5.12.10 - core;gui - - - 5.12.10 - core;gui - - - - - - - .\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;release;/include;%(AdditionalIncludeDirectories) - -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions) - release\ - false - None - 4577;4467;%(DisableSpecificWarnings) - Sync - release\ - MaxSpeed - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_NO_DEBUG;NDEBUG;%(PreprocessorDefinitions) - false - - - MultiThreadedDLL - true - true - Level3 - true - - - shell32.lib;%(AdditionalDependencies) - C:\openssl\lib;C:\Utils\my_sql\mysql-5.6.11-winx64\lib;C:\Utils\postgresql\pgsql\lib;%(AdditionalLibraryDirectories) - "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) - true - false - true - false - $(OutDir)\conf.exe - true - Windows - true - - - Unsigned - None - 0 - - - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_NO_DEBUG;QT_GUI_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) - - - - - .\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;release;/include;%(AdditionalIncludeDirectories) - -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions) - release\ - false - None - 4577;4467;%(DisableSpecificWarnings) - Sync - release\ - MaxSpeed - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_NO_DEBUG;NDEBUG;WIN64;%(PreprocessorDefinitions) - false - - - MultiThreadedDLL - true - true - Level3 - true - - - shell32.lib;%(AdditionalDependencies) - C:\openssl\lib;C:\Utils\my_sql\mysql-5.6.11-winx64\lib;C:\Utils\postgresql\pgsql\lib;%(AdditionalLibraryDirectories) - "/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" /SUBSYSTEM:WINDOWS %(AdditionalOptions) - true - false - true - false - $(OutDir)\conf.exe - true - Windows - true - MachineX64 - - - Unsigned - None - 0 - - - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_NO_DEBUG;QT_GUI_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) - - - - - .\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;debug;/include;%(AdditionalIncludeDirectories) - -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions) - debug\ - false - ProgramDatabase - 4577;4467;%(DisableSpecificWarnings) - Sync - debug\ - Disabled - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;%(PreprocessorDefinitions) - false - MultiThreadedDebugDLL - true - true - Level3 - true - - - shell32.lib;%(AdditionalDependencies) - C:\openssl\lib;C:\Utils\my_sql\mysql-5.6.11-winx64\lib;C:\Utils\postgresql\pgsql\lib;%(AdditionalLibraryDirectories) - "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) - true - true - true - $(OutDir)\conf.exe - true - Windows - true - - - Unsigned - None - 0 - - - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_GUI_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) - - - - - .\GeneratedFiles\$(ConfigurationName);.\GeneratedFiles;.;debug;/include;%(AdditionalIncludeDirectories) - -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 %(AdditionalOptions) - debug\ - false - ProgramDatabase - 4577;4467;%(DisableSpecificWarnings) - Sync - debug\ - Disabled - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;WIN64;%(PreprocessorDefinitions) - false - MultiThreadedDebugDLL - true - true - Level3 - true - - - shell32.lib;%(AdditionalDependencies) - C:\openssl\lib;C:\Utils\my_sql\mysql-5.6.11-winx64\lib;C:\Utils\postgresql\pgsql\lib;%(AdditionalLibraryDirectories) - "/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" /SUBSYSTEM:WINDOWS %(AdditionalOptions) - true - true - true - $(OutDir)\conf.exe - true - Windows - true - MachineX64 - - - Unsigned - None - 0 - - - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_GUI_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) - - - - - Document - true - true - $(QTDIR)\mkspecs\features\data\dummy.cpp;%(AdditionalInputs) - $(QTDIR)\mkspecs\features\data\dummy.cpp;%(AdditionalInputs) - cl -Bx"$(QTDIR)\bin\qmake.exe" -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -Zi -MDd -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -E $(QTDIR)\mkspecs\features\data\dummy.cpp 2>NUL >debug\moc_predefs.h - cl -Bx"$(QTDIR)\bin\qmake.exe" -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -Zi -MDd -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -E $(QTDIR)\mkspecs\features\data\dummy.cpp 2>NUL >debug\moc_predefs.h - Generate moc_predefs.h - Generate moc_predefs.h - debug\moc_predefs.h;%(Outputs) - debug\moc_predefs.h;%(Outputs) - - - Document - $(QTDIR)\mkspecs\features\data\dummy.cpp;%(AdditionalInputs) - $(QTDIR)\mkspecs\features\data\dummy.cpp;%(AdditionalInputs) - cl -Bx"$(QTDIR)\bin\qmake.exe" -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -E $(QTDIR)\mkspecs\features\data\dummy.cpp 2>NUL >release\moc_predefs.h - cl -Bx"$(QTDIR)\bin\qmake.exe" -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -E $(QTDIR)\mkspecs\features\data\dummy.cpp 2>NUL >release\moc_predefs.h - Generate moc_predefs.h - Generate moc_predefs.h - release\moc_predefs.h;%(Outputs) - release\moc_predefs.h;%(Outputs) - true - true - - - - - - - - \ No newline at end of file diff --git a/MarkovPasswordsGUI/conf.vcxproj.filters b/MarkovPasswordsGUI/conf.vcxproj.filters deleted file mode 100644 index 9e6c81fb..00000000 --- a/MarkovPasswordsGUI/conf.vcxproj.filters +++ /dev/null @@ -1,21 +0,0 @@ - - - - - {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} - cpp;c;cxx;moc;h;def;odl;idl;res; - - - {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} - cpp;c;cxx;moc;h;def;odl;idl;res; - - - - - Generated Files - - - Generated Files - - - \ No newline at end of file diff --git a/MarkovPasswordsGUI/CLI.cpp b/MarkovPasswordsGUI/src/CLI.cpp similarity index 67% rename from MarkovPasswordsGUI/CLI.cpp rename to MarkovPasswordsGUI/src/CLI.cpp index 1dc459c9..73ce25be 100644 --- a/MarkovPasswordsGUI/CLI.cpp +++ b/MarkovPasswordsGUI/src/CLI.cpp @@ -1,12 +1,18 @@ -#include "src\CLI.h" +/** @file cli.cpp + * @brief CLI page + * @authors Yunus Emre Yılmaz + * + */ + +#include "CLI.h" #include -#include "src/Train.h" +#include "Train.h" using namespace Markov::GUI; -CLI::CLI(QWidget* parent) +Markov::GUI::CLI::CLI(QWidget* parent) : QMainWindow(parent) { ui.setupUi(this); @@ -17,17 +23,17 @@ CLI::CLI(QWidget* parent) } -void CLI::start() { +void Markov::GUI::CLI::start() { Train* w = new Train; w->show(); this->close(); } -void CLI::statistics() { +void Markov::GUI::CLI::statistics() { /* statistic will show */ } -void CLI::about() { +void Markov::GUI::CLI::about() { /* about button */ diff --git a/MarkovPasswordsGUI/src/CLI.h b/MarkovPasswordsGUI/src/CLI.h index 7eb579c0..b12c75b8 100644 --- a/MarkovPasswordsGUI/src/CLI.h +++ b/MarkovPasswordsGUI/src/CLI.h @@ -1,3 +1,9 @@ +/** @file cli.h + * @brief CLI page + * @authors Yunus Emre Yılmaz + * + */ + #pragma once #include #include "ui_CLI.h" diff --git a/MarkovPasswordsGUI/CLI.ui b/MarkovPasswordsGUI/src/CLI.ui similarity index 100% rename from MarkovPasswordsGUI/CLI.ui rename to MarkovPasswordsGUI/src/CLI.ui diff --git a/MarkovPasswordsGUI/Comparison.ui b/MarkovPasswordsGUI/src/Comparison.ui similarity index 100% rename from MarkovPasswordsGUI/Comparison.ui rename to MarkovPasswordsGUI/src/Comparison.ui diff --git a/MarkovPasswordsGUI/Generate.cpp b/MarkovPasswordsGUI/src/Generate.cpp similarity index 91% rename from MarkovPasswordsGUI/Generate.cpp rename to MarkovPasswordsGUI/src/Generate.cpp index 2565f622..de149998 100644 --- a/MarkovPasswordsGUI/Generate.cpp +++ b/MarkovPasswordsGUI/src/Generate.cpp @@ -1,13 +1,19 @@ +/** @file Generate.cpp + * @brief Generation Page + * @authors Yunus Emre Yılmaz + * + */ + #include "Generate.h" #include #include #include #include #include -#include "src/CLI.h" -#include "../MarkovPasswords/src/markovPasswords.h" +#include "CLI.h" +#include "MarkovAPI/src/markovPasswords.h" #include -#include "src/MarkovPasswordsGUI.h" +#include "MarkovPasswordsGUI.h" using namespace Markov::GUI; @@ -53,7 +59,7 @@ void Generate::generation() { ui.label_6->setText("GENERATING!"); - MarkovPasswords mp; + Markov::API::MarkovPasswords mp; mp.Import("src\\CLI\\sample_models\\2gram-trained.mdl"); mp.Generate(numberPass,cstr,minLen,maxLen); @@ -92,7 +98,7 @@ void Generate::train() { char a = ','; - MarkovPasswords mp; + Markov::API::MarkovPasswords mp; mp.Import("models\\2gram.mdl"); mp.Train(cstr, a,10); mp.Export("models\\finished.mdl"); diff --git a/MarkovPasswordsGUI/Generate.h b/MarkovPasswordsGUI/src/Generate.h similarity index 80% rename from MarkovPasswordsGUI/Generate.h rename to MarkovPasswordsGUI/src/Generate.h index cb25056c..baca0f35 100644 --- a/MarkovPasswordsGUI/Generate.h +++ b/MarkovPasswordsGUI/src/Generate.h @@ -1,3 +1,9 @@ +/** @file Generate.h + * @brief Generation Page + * @authors Yunus Emre Yılmaz + * + */ + #pragma once #include #include "ui_Generate.h" diff --git a/MarkovPasswordsGUI/Generate.ui b/MarkovPasswordsGUI/src/Generate.ui similarity index 100% rename from MarkovPasswordsGUI/Generate.ui rename to MarkovPasswordsGUI/src/Generate.ui diff --git a/MarkovPasswordsGUI/MainWindow.ui b/MarkovPasswordsGUI/src/MainWindow.ui similarity index 100% rename from MarkovPasswordsGUI/MainWindow.ui rename to MarkovPasswordsGUI/src/MainWindow.ui diff --git a/MarkovPasswordsGUI/src/MarkovPasswordsGUI.cpp b/MarkovPasswordsGUI/src/MarkovPasswordsGUI.cpp index ab910529..ca78428c 100644 --- a/MarkovPasswordsGUI/src/MarkovPasswordsGUI.cpp +++ b/MarkovPasswordsGUI/src/MarkovPasswordsGUI.cpp @@ -1,14 +1,17 @@ +/** @file MarkovPasswordsGUI.cpp + * @brief Main activity page for GUI + * @authors Yunus Emre Yılmaz + * + */ + #include "MarkovPasswordsGUI.h" #include #include -#include #include "CLI.h" using namespace Markov::GUI; -MarkovPasswordsGUI::MarkovPasswordsGUI(QWidget *parent) - : QMainWindow(parent) -{ +Markov::GUI::MarkovPasswordsGUI::MarkovPasswordsGUI(QWidget *parent) : QMainWindow(parent){ ui.setupUi(this); diff --git a/MarkovPasswordsGUI/src/MarkovPasswordsGUI.h b/MarkovPasswordsGUI/src/MarkovPasswordsGUI.h index 73a78b1b..1b37b449 100644 --- a/MarkovPasswordsGUI/src/MarkovPasswordsGUI.h +++ b/MarkovPasswordsGUI/src/MarkovPasswordsGUI.h @@ -1,3 +1,9 @@ +/** @file MarkovPasswordsGUI.h + * @brief Main activity page for GUI + * @authors Yunus Emre Yılmaz + * + */ + #pragma once #include @@ -12,6 +18,8 @@ namespace Markov::GUI{ */ class MarkovPasswordsGUI : public QMainWindow { Q_OBJECT + public: + MarkovPasswordsGUI(QWidget* parent = Q_NULLPTR); private: Ui::MarkovPasswordsGUIClass ui; @@ -20,17 +28,17 @@ namespace Markov::GUI{ //Slots for buttons in GUI. public slots: - void MarkovPasswordsGUI::benchmarkSelected(); - void MarkovPasswordsGUI::modelvisSelected(); - void MarkovPasswordsGUI::visualDebugSelected(); - void MarkovPasswordsGUI::comparisonSelected(); + void benchmarkSelected(); + //void MarkovPasswordsGUI::modelvisSelected(); + //void MarkovPasswordsGUI::visualDebugSelected(); + //void MarkovPasswordsGUI::comparisonSelected(); public slots: - void MarkovPasswordsGUI::home(); - void MarkovPasswordsGUI :: pass(); - void MarkovPasswordsGUI::model(); + void home(); + void pass(); + void model(); }; }; diff --git a/MarkovPasswordsGUI/MarkovPasswordsGUI.ui b/MarkovPasswordsGUI/src/MarkovPasswordsGUI.ui similarity index 100% rename from MarkovPasswordsGUI/MarkovPasswordsGUI.ui rename to MarkovPasswordsGUI/src/MarkovPasswordsGUI.ui diff --git a/MarkovPasswordsGUI/Train.cpp b/MarkovPasswordsGUI/src/Train.cpp similarity index 70% rename from MarkovPasswordsGUI/Train.cpp rename to MarkovPasswordsGUI/src/Train.cpp index 7d86bee5..92c10f91 100644 --- a/MarkovPasswordsGUI/Train.cpp +++ b/MarkovPasswordsGUI/src/Train.cpp @@ -1,11 +1,17 @@ -#include "src/Train.h" +/** @file Train.cpp + * @brief training page for GUI + * @authors Yunus Emre Yılmaz + * + */ + +#include "Train.h" #include #include #include #include #include -#include "src/CLI.h" -#include "MarkovPasswords/src/markovPasswords.h" +#include "CLI.h" +#include "MarkovAPI/src/markovPasswords.h" #include #include "Generate.h" @@ -13,7 +19,7 @@ using namespace Markov::GUI; -Train::Train(QWidget* parent) +Markov::GUI::Train::Train(QWidget* parent) : QMainWindow(parent) { ui.setupUi(this); @@ -22,14 +28,14 @@ Train::Train(QWidget* parent) QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {train(); }); QObject::connect(ui.pushButton_2, &QPushButton::clicked, this, [this] {home(); }); - QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {goGenerate(); }); + //QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {goGenerate(); }); - ui.pushButton_3->setVisible(false); + //ui.pushButton_3->setVisible(false); } -void Train::train() { +void Markov::GUI::Train::train() { @@ -52,25 +58,25 @@ void Train::train() { char a=','; - Markov::API::CLI::MarkovPasswords mp; + Markov::API::MarkovPasswords mp; mp.Import("models/2gram.mdl"); mp.Train(cstr, a, 10); //please parameterize this hardcoded 10 threads mp.Export("models/finished.mdl"); ui.label_2->setText("Training DONE!"); - ui.pushButton_3->setVisible(true); + //ui.pushButton_3->setVisible(true); file.close(); } -void Train::home() { +void Markov::GUI::Train::home() { CLI* w = new CLI; w->show(); this->close(); } -void Train::goGenerate() { +/*void Train::goGenerate() { Generate* w = new Generate; w->show(); this->close(); -} +}*/ diff --git a/MarkovPasswordsGUI/src/Train.h b/MarkovPasswordsGUI/src/Train.h index 2ac0a4f4..ffa7a629 100644 --- a/MarkovPasswordsGUI/src/Train.h +++ b/MarkovPasswordsGUI/src/Train.h @@ -1,3 +1,9 @@ +/** @file Train.h + * @brief training page for GUI + * @authors Yunus Emre Yılmaz + * + */ + #pragma once #include #include "ui_Train.h" diff --git a/MarkovPasswordsGUI/Train.ui b/MarkovPasswordsGUI/src/Train.ui similarity index 100% rename from MarkovPasswordsGUI/Train.ui rename to MarkovPasswordsGUI/src/Train.ui diff --git a/MarkovPasswordsGUI/about.cpp b/MarkovPasswordsGUI/src/about.cpp similarity index 62% rename from MarkovPasswordsGUI/about.cpp rename to MarkovPasswordsGUI/src/about.cpp index 70ec8024..acfd047b 100644 --- a/MarkovPasswordsGUI/about.cpp +++ b/MarkovPasswordsGUI/src/about.cpp @@ -1,6 +1,13 @@ + +/** @file about.cpp + * @brief About page + * @authors Yunus Emre Yılmaz + * + */ + #include #include -#include "src\about.h" +#include "about.h" using namespace Markov::GUI; diff --git a/MarkovPasswordsGUI/src/about.h b/MarkovPasswordsGUI/src/about.h index 690bd26c..8d20bfaf 100644 --- a/MarkovPasswordsGUI/src/about.h +++ b/MarkovPasswordsGUI/src/about.h @@ -1,3 +1,9 @@ +/** @file about.h + * @brief About page + * @authors Yunus Emre Yılmaz + * + */ + #pragma once #include #include "ui_about.h" diff --git a/MarkovPasswordsGUI/about.ui b/MarkovPasswordsGUI/src/about.ui similarity index 100% rename from MarkovPasswordsGUI/about.ui rename to MarkovPasswordsGUI/src/about.ui diff --git a/MarkovPasswordsGUI/src/main.cpp b/MarkovPasswordsGUI/src/main.cpp index ec497b57..c5674c65 100644 --- a/MarkovPasswordsGUI/src/main.cpp +++ b/MarkovPasswordsGUI/src/main.cpp @@ -1,3 +1,9 @@ +/** @file main.cpp + * @brief Entry point for GUI + * @authors Yunus Emre Yılmaz + * + */ + //#include "MarkovPasswordsGUI.h" #include "menu.h" #include diff --git a/MarkovPasswordsGUI/src/menu.cpp b/MarkovPasswordsGUI/src/menu.cpp index fa99bdff..69bd3c47 100644 --- a/MarkovPasswordsGUI/src/menu.cpp +++ b/MarkovPasswordsGUI/src/menu.cpp @@ -1,3 +1,9 @@ +/** @file menu.cpp + * @brief menu page + * @authors Yunus Emre Yılmaz + * + */ + #include "menu.h" #include #include "MarkovPasswordsGUI.h" diff --git a/MarkovPasswordsGUI/src/menu.h b/MarkovPasswordsGUI/src/menu.h index 3dab2580..a29f1e49 100644 --- a/MarkovPasswordsGUI/src/menu.h +++ b/MarkovPasswordsGUI/src/menu.h @@ -1,3 +1,9 @@ +/** @file menu.h + * @brief menu page + * @authors Yunus Emre Yılmaz + * + */ + #pragma once #include #include "ui_menu.h" diff --git a/MarkovPasswordsGUI/menu.ui b/MarkovPasswordsGUI/src/menu.ui similarity index 100% rename from MarkovPasswordsGUI/menu.ui rename to MarkovPasswordsGUI/src/menu.ui diff --git a/README.md b/README.md index e45c63a2..176d7081 100644 --- a/README.md +++ b/README.md @@ -1,253 +1,415 @@ -# Markov Passwords +# Markopy [![Contributors][contributors-shield]][contributors-url] [![Forks][forks-shield]][forks-url] [![Stargazers][stars-shield]][stars-url] [![Issues][issues-shield]][issues-url] -![GitHub](https://img.shields.io/github/license/FlameOfIgnis/MarkovPasswords?style=for-the-badge) +![GitHub](https://img.shields.io/github/license/ignis-sec/Markopy?style=for-the-badge)
-

- -

Markov Passwords

- -

+

+

Markopy

+
Generate wordlists with markov models.
- Wiki + HTML documentation · - Complete documentation + PDF documentation · - Report Bug + Github Page · - Add a Bug -

-

- - - - -
- Table of Contents -
    -
  1. - About The Project - -
  2. -
  3. - Getting Started - -
  4. -
  5. Contributing
  6. -
  7. Contact
  8. -
-
- + Report Bug + · + Add a Bug +
+
+ + + + --- - + ## About The Project +
-This project aims to generate wordlists using markov models. +This projects primary goal is to create a comfortable development environment for working with Markov Models, +as well as creating an end product which can be used for generating password wordlists using Markov Models. -### Built With +This project contains following sub-projects: -* CPP, with dependecies: boost, python3-dev, QT-5. +- MarkovModel + - A versatile header-only template library for basic Markov Model structure. +- MarkovAPI + - A static/dynamic library built on MarkovModel, specialized to generate single-word lines. +- MarkovAPICLI + - A command line interface built on top of MarkovAPI +- Markopy + - A CPython extension wrapper for MarkovAPI, along with its own command line interface. +- MarkovPasswordsGUI + - A graphical user interface for MarkovAPI +- CudaMarkovAPI + - GPU-accelerated wrapper for MarkovAPI +- CudaMarkopy + - GPU-accelereted wrapper for CudaMarkovAPI -## Getting Started +### Possible Use Cases +
-If you'd just like to use the project without contributing, check out the releases page. If you want to build, check out wiki for building the project. +While main focus of the development has been towards random walk performance and password generation, underlying libraries could be used for other applications such as specific use cases of hidden markov models in bioinformatics and gene research. ---- -### Prerequisites +### Getting Started +
-##### MarkovModel -- Make for linux, Visual Studio/MSBuild for Windows. +If you'd just like to use the project without contributing, check out the releases page. +Latest minor release (0.8.x, 0.9.x) is even with main branch, and latest patch release (0.8.1, 0.8.2) is even with development branch. -##### MarkovPasswords -- Boost.ProgramOptions (tested on 1.76.0) -##### Markopy -- Boost.Python (tested on 1.76.0) -- Python development package (tested on python 3.8) +### Releases +
-##### MarkovPasswordsGUI -- QT development environment. +Releases are maintained automatically via github actions. Each push to the main branch will trigger a minor version release, while each accepted pull request into the development branch will trigger a patch version release. +Pull requests to the development branch will also trigger a draft release only visible to the maintainers. + +Release files contain: +- libmarkov-{version}-{platform}.zip + - Depending on the platform, contains the libmarkov.so or markov.lib from that version. +- libcudamarkov-{version}-{platform}.zip + - Depending on the platform, contains the libcudamarkov.so or cudamarkov.lib from that version. +- markopy-{version}-{platform}-py{ver}.{extension}.zip + - Depending on the paltform, contains markopy.so or markopy.pyd. CPython extensions are compiled for specific versions. + If your python version is not supported by the releases, you can create an issue, or build it yourself using the python3.x-dev package. +- cudamarkopy-{version}-{platform}-py{ver}.{extension}.zip + - Depending on the paltform, contains cudamarkopy.so or cudamarkopy.pyd. CPython extensions are compiled for specific versions. + If your python version is not supported by the releases, you can create an issue, or build it yourself using the python3.x-dev package. +- models-{version}.zip + - Contains the latest models with the release version. + Contains base models (untrained), trained models, and language-specific models. + + --- +## Building +
+You can build the project using cmake with g++ & nvcc on linux, and msbuild & nvcc on windows. -### Installing Dependencies -##### Windows -- QT: Install [QT For Windows](https://doc.qt.io/qt-5/windows.html) -- Boost: - - Download Boost from [its website](https://www.boost.org/users/download/) - - Unzip the contents. - - Launch "Visual Studio Developer Command Prompt" - - Move to the boost installation directory. Run `bootstrap.bat` - - Run `b2`. -- Python: You can use the windows app store to download python runtime and libraries. +## Prerequisites +
+You can find a list of the dependencies below. If you have any missing, check out the setting up prequisites part. -##### Linux -- QT: Follow [this guide](https://wiki.qt.io/Install_Qt_5_on_Ubuntu) to install QT on Linux. -- Boost: run `sudo apt-get install libboost-all-dev` -- Python: run `sudo apt-get install python3` +### General prequisites +
---- +To build the simple core of this project, you'll need: +#### Linux +- CMake, preferably one of the latest versions. +- CXX compiler, preferably g++ or clang++ (LLVM 3.9+). -### Installation +#### Windows +- CMake, preferably one of the latest versions. +- CXX compiler, preferably msbuild(cl.exe) or clang++ (LLVM 3.9+). + Please note that mingw is not recommended as it is not officially supported by the nvcc.exe, and might not be linkable if you are building the CUDA components too. -See the Wiki Page ---- -### Building -Building process can be fairly complicated depending on the environment. +### MarkovModel +
+This project does not have any extra dependencies, and it can be compiled with general dependencies without anything extra. -## Linux -If you've set up the dependencies, you can just build the project with make. -List of directives is below. +### MarkovAPI +
+This project does not have any extra dependencies, and it can be compiled with general dependencies without anything extra. -```makefile -.PHONY: all -all: model mp +### MarkovAPICLI +
-model: $(INCLUDE)/$(MM_LIB) +- Boost.program_options (tested on 1.71.0-1.76.0) -mp: $(BIN)/$(MP_EXEC) +### Markopy +
-markopy: $(BIN)/$(MPY_SO) +- Boost.Python (tested on 1.71.0-1.76.0) +- Python development package (tested on python 36-39) -.PHONY: clean -clean: - $(RM) -r $(BIN)/* +### CudaMarkovAPI +
-``` +- CUDA toolkit (11.0+, c++17 support required) -## Windows -Set up correct environment variables for %BOOST_ROOT% (folder containing boost, libs, stage, tools) and %PYTHON_PATH% (folder containing include, lib, libs, Tools, python.exe/python3.exe). +### CudaMarkopy +
-If you've set up the dependencies and environment variables correctly, you can open the solution with Visual Studio and build with that. +- CUDA toolkit (11.0+, c++17 support required) +- Boost.Python (tested on 1.71.0-1.76.0) +- Python development package (tested on python 36-39) ---- +### MarkovPasswordsGUI +
-# Known Common issues -## Linux -### Markopy - Python.h - Not found -Make sure you have the development version of python package, which includes the required header files. -Check if header files exist: `/usr/include/python*` +- QT5 development environment. (qt5-qmake on ubuntu apt-get) +- QTWebEngine5 plugin. (qtwebengine5-dev on ubuntu apt-get) -If it doesn't, run `sudo apt-get install python3-dev` -### Markopy/MarkovPasswords - *.so not found, or other library related issues when building -Run `ls /usr/lib/x86_64-linux-gnu/ | grep boost` and check the shared object filenames. A common issue is that lboost is required but filenames are formatted as llibboost, or vice versa. +### CMake Configuration +
-Do the same for python related library issues, run: `ls /usr/lib/x86_64-linux-gnu/ | grep python` to verify filename format is as required. +You can build this project with cmake. -If not, you can modify the makefile, or create symlinks such as: -`ln -s /usr/lib/x86_64-linux-gnu/libboost_python38.so /usr/lib/x86_64-linux-gnu/boost_python38.so` +If you don't have prequisites for some of the projects set up, you can use the partial set up configuration to ignore those projects when setting the project up. -## Windows -### Boost - Bootstrap.bat "ctype.h" not found -- Make sure you are working in the "Visual Studio Developer Command Prompt" terminal. -- Make sure you have Windows 10 SDK installed. -- From VS developer terminal, run echo %INCLUDE%. If result does not have the windows sdk folders, run the following before running bootstrap (change your sdk version instead of 10.0.19041.0): -```bat -set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt +If you do not meet the prequisites, you'll have to partially set up the CMake file (you cant use --target to build some of the targets, because configuration phase will fail too). + +Some examples for partially setting up and building the project are below. + +#### Build everything +
-set LIB=%LIB%;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64 +``` +$ cmake . -DPYTHON_VER=38 && cmake --build . ``` -### Cannot open file "*.lib" -Make sure you have set the BOOST_ROOT environment variable correctly. Make sure you ran `b2` to build library files from boost sources. +This will build all the libraries and executables. Requires python-dev, CUDA, QT5, QT5-Webview -### Python.h not found -Make sure you have python installed, and make sure you set PYTHON_PATH environment variable. +#### Build libraries only +
---- +``` +$ cmake . -DPARTIAL=1 -DB_LIBS=1 && cmake --build . +``` + +Only build basic libraries. Requires only CXX compiler. + +#### Build CUDA-accelerated libraries +
+ +``` +$ cmake . -DPARTIAL=1 -DB_CUDA=1 && cmake --build . +``` + +Build libraries along with cuda accelerated ones. -### Simplified Theory -##### What is a markov model +#### Build python module & libraries +
-Below, is the example Markov Model which can generate strings with the alphabet "a,b,c" +``` +$ cmake . -DPARTIAL=1 -DPYTHON_VER=39 && cmake --build . +``` -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/empty_model.png) +Will build basic libraries and python modules. +#### Build CUDA accelerated python module +
-##### Iteration 1 +``` +$ cmake . -DPARTIAL=1 -DPYTHON_VER=39 -DB_CUDA=1 && cmake --build . +``` -Below is a demonstration of how training will be done. For this example, we are going to adjust the model with string "ab", and our occurrence will be "3" -From MarkovPasswords, inside the train function, Model::adjust is called with "ab" and "3" parameters. +Will build cudamarkopy. -Now, Model::adjust will iteratively adjust the edge weights accordingly. It starts by adjusting weight between start and "a" node. This is done by calling Edge::adjust of the edge between the nodes. +#### Build CUDA accelerated python module and the GUI +
-![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_1.png) +``` +$ cmake . -DPARTIAL=1 -DPYTHON_VER=39 -DB_CUDA=1 -DB_GUI && cmake --build . +``` -After adjustment, ajust function iterates to the next character, "b", and does the same thing. +Combine methods -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_2.png) -As this string is finished, it will adjust the final weight, b->"end" +--- -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_3.png) +### Installing Dependencies +
-##### Iteration 2 +##### Windows +
-This time, same procedure will be applied for "bacb" string, with occurrence value of 12. +- QT: Install [QT For Windows](https://doc.qt.io/qt-5/windows.html) +- Boost (program_options and python): + - Download Boost from [its website](https://www.boost.org/users/download/). Prefer one of the tested versions, 1.71.0 to 1.76.0 + - Unzip the contents. + - Launch "Visual Studio Developer Command Prompt" (If you don't have this, properly set up the %PATH% variable for cl.exe) + - Move to the boost installation directory. Bootstrap libraries with your python version: + ``` + .\bootstrap.bat --with-python=$(which python3.6) --with-python-version=3.6; + ``` + + - Run `b2` to build the libraries. + ``` + .\b2.exe --layout=system address-model=64 variant=release link=static runtime-link=shared threading=multi --with-program_options --with-python stage; + ``` +- Python: You can use the windows app store to download python runtime and libraries. -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_21.png) -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_22.png) +##### Linux +
-![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_23.png) +- QT: Follow [this guide](https://wiki.qt.io/Install_Qt_5_on_Ubuntu) to install QT on Linux. + Alternatively, on ubuntu you can `sudo apt-get install qt5-qmake qtwebengine5-dev` +- Boost (program options and python): + - Download Boost from [its website](https://www.boost.org/users/download/). Prefer one of the tested versions, 1.71.0 to 1.76.0 + - Unzip the contents. + - Move to the boost installation directory. Bootstrap libraries with your python version: + ``` + ./bootstrap.sh --with-python=$(which python3.6) --with-python-version=3.6; + ``` + + - Run `b2` to build the libraries. + ``` + ./b2 variant=release link=static threading=multi --with-program_options install; + ./b2 --with-python --buildid=3.6 install; + ``` + +- Boost (alternative) + - Use a package manager to install boost + ``` + sudo apt-get install libboost-all-dev + ``` + +- Python: + ``` + sudo apt-get install python3-dev + ``` -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_24.png) +--- -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_25.png) +## Known Common issues +
+ +### Linux +#### Markopy - Python.h - Not found +Make sure you have the development version of python package, which includes the required header files. +Check if header files exist: `/usr/include/python*` or `locate Python.h`. +If it doesn't, run `sudo apt-get install python3-dev` -##### Iteration 38271 +#### Markopy/MarkovAPI - *.so not found, or other library related issues when building +Run: +``` +ls /usr/lib/x86_64-linux-gnu/ | grep boost +``` -As the model is trained, hidden linguistical patterns start to appear, and our model looks like this -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_30.png) +and check the shared object filenames. A common issue is that lboost is required but filenames are formatted as libboost, or vice versa. -With our dataset, without doing any kind of linugistic analysis ourselves, our Markov Model has highlighted that strings are more likely to start with a, b tends to follow a, and a is likely to be repeated in the string. -![](https://raw.githubusercontent.com/FlameOfIgnis/MarkovPasswords/main/docs/images/model_31.png) +Do the same for python related library issues, run: +``` +ls /usr/lib/x86_64-linux-gnu/ | grep python +``` + +to verify filename format is as required. + +If not, you can modify the makefile, or create symlinks such as: +``` +ln -s /usr/lib/x86_64-linux-gnu/libboost_python38.so /usr/lib/x86_64-linux-gnu/boost_python38.so +``` + +### Windows +#### Boost - Bootstrap.bat "ctype.h" not found +- Make sure you are working in the "Visual Studio Developer Command Prompt" terminal. +- Make sure you have Windows 10 SDK installed. +- From VS developer terminal, run echo %INCLUDE%. If result does not have the windows sdk folders, run the following before running bootstrap (change your sdk version instead of 10.0.19041.0): +```bat +set INCLUDE=%INCLUDE%;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt + +set LIB=%LIB%;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64 +``` + +#### Cannot open file "*.lib" +Make sure you have set the BOOST_ROOT environment variable correctly. Make sure you ran `b2` to build library files from boost sources. + +#### Python.h not found +Make sure you have python installed, and make sure you set PYTHON_PATH environment variable. --- ## Contributing -Feel free to contribute. +
+ +Feel free to contribute. We welcome all the issues and pull requests. ## Contact +
+ Twitter - [@ahakcil](https://twitter.com/ahakcil) -[contributors-shield]: https://img.shields.io/github/contributors/FlameOfIgnis/MarkovPasswords.svg?style=for-the-badge -[contributors-url]: https://github.com/FlameOfIgnis/MarkovPasswords/graphs/contributors -[forks-shield]: https://img.shields.io/github/forks/FlameOfIgnis/MarkovPasswords.svg?style=for-the-badge -[forks-url]: https://github.com/FlameOfIgnis/MarkovPasswords/network/members -[stars-shield]: https://img.shields.io/github/stars/FlameOfIgnis/MarkovPasswords.svg?style=for-the-badge -[stars-url]: https://github.com/FlameOfIgnis/MarkovPasswords/stargazers -[issues-shield]: https://img.shields.io/github/issues/FlameOfIgnis/MarkovPasswords.svg?style=for-the-badge -[issues-url]: https://github.com/FlameOfIgnis/MarkovPasswords/issues -[license-shield]: https://img.shields.io/github/license/FlameOfIgnis/MarkovPasswords.svg?style=for-the-badge -[license-url]: https://github.com/FlameOfIgnis/MarkovPasswords/LICENSE +[contributors-shield]: https://img.shields.io/github/contributors/ignis-sec/Markopy.svg?style=for-the-badge +[contributors-url]: https://github.com/ignis-sec/Markopy/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/ignis-sec/Markopy.svg?style=for-the-badge +[forks-url]: https://github.com/ignis-sec/Markopy/network/members +[stars-shield]: https://img.shields.io/github/stars/ignis-sec/Markopy.svg?style=for-the-badge +[stars-url]: https://github.com/ignis-sec/Markopy/stargazers +[issues-shield]: https://img.shields.io/github/issues/ignis-sec/Markopy.svg?style=for-the-badge +[issues-url]: https://github.com/ignis-sec/Markopy/issues +[license-shield]: https://img.shields.io/github/license/ignis-sec/Markopy.svg?style=for-the-badge +[license-url]: https://github.com/ignis-sec/Markopy/LICENSE diff --git a/UnitTests/UnitTests.cpp b/UnitTests/UnitTests.cpp index b07e27dd..9ed2f7fe 100644 --- a/UnitTests/UnitTests.cpp +++ b/UnitTests/UnitTests.cpp @@ -1,3 +1,9 @@ +/** @file UnitTests.cpp + * @brief Unit tests with Microsoft::VisualStudio::CppUnitTestFramework + * @authors Ata Hakçıl, Osman Ömer Yıldıztugay, Yunus Emre Yılmaz + * + */ + #include "pch.h" #include "CppUnitTest.h" #include "MarkovModel/src/model.h" diff --git a/UnitTests/UnitTests.vcxproj b/UnitTests/UnitTests.vcxproj deleted file mode 100644 index b4904512..00000000 --- a/UnitTests/UnitTests.vcxproj +++ /dev/null @@ -1,180 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {26260E27-B240-4E67-AE52-A6919A8DBF5C} - Win32Proj - UnitTests - 10.0 - NativeUnitTestProject - - - - DynamicLibrary - true - v142 - Unicode - false - - - DynamicLibrary - false - v142 - true - Unicode - false - - - DynamicLibrary - true - v142 - Unicode - false - - - DynamicLibrary - false - v142 - true - Unicode - false - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(SolutionDir)x64/lib/; - - - - Use - Level3 - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(SolutionDir); - _DEBUG;%(PreprocessorDefinitions) - true - pch.h - stdcpp17 - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies); - - - - - Use - Level3 - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(SolutionDir); - WIN32;_DEBUG;%(PreprocessorDefinitions) - true - pch.h - - - Windows - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);MarkovModel.lib; - - - - - Use - Level3 - true - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(SolutionDir); - WIN32;NDEBUG;%(PreprocessorDefinitions) - true - pch.h - - - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);MarkovModel.lib; - - - - - Use - Level3 - true - true - true - $(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories);$(SolutionDir); - NDEBUG;%(PreprocessorDefinitions) - true - pch.h - stdcpp17 - - - Windows - true - true - $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories) - kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies); - - - - - Create - Create - Create - Create - - - - - - - - - - \ No newline at end of file diff --git a/UnitTests/UnitTests.vcxproj.filters b/UnitTests/UnitTests.vcxproj.filters deleted file mode 100644 index 264bee87..00000000 --- a/UnitTests/UnitTests.vcxproj.filters +++ /dev/null @@ -1,30 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - Source Files - - - - - Header Files - - - \ No newline at end of file diff --git a/UnitTests/pch.cpp b/UnitTests/pch.cpp index 71836195..d6c1c56b 100644 --- a/UnitTests/pch.cpp +++ b/UnitTests/pch.cpp @@ -1,3 +1,8 @@ +/** @file pch.cpp + * @brief For windows dynamic library + * @authors Ata Hakçıl + * + */ // pch.cpp: source file corresponding to the pre-compiled header #include "pch.h" diff --git a/UnitTests/pch.h b/UnitTests/pch.h index 802cb5b5..26af0160 100644 --- a/UnitTests/pch.h +++ b/UnitTests/pch.h @@ -1,3 +1,8 @@ +/** @file pch.h + * @brief For windows dynamic library + * @authors Ata Hakçıl + * + */ // pch.h: This is a precompiled header file. // Files listed below are compiled only once, improving build performance for future builds. // This also affects IntelliSense performance, including code completion and many code browsing features. diff --git a/build-documentation.sh b/build-documentation.sh index 59415e9b..4929a3ca 100644 --- a/build-documentation.sh +++ b/build-documentation.sh @@ -1,6 +1,6 @@ #!/bin/bash -export CPLUS_INCLUDE_PATH="${CPLUS_INCLUDE_PATH:+${CPLUS_INCLUDE_PATH}:}/usr/include/python3.8:/usr/lib/cuda11.0/include:$(pwd)" +export CPLUS_INCLUDE_PATH="${CPLUS_INCLUDE_PATH:+${CPLUS_INCLUDE_PATH}:}/usr/include/python3.8:/usr/lib/cuda11.0/include:/usr/include/x86_64-linux-gnu/qt5/:$(pwd):$(pwd)/MarkovPasswordsGUI/" export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib #cleanup old documentations rm -r docs/* @@ -23,7 +23,10 @@ cat Doxyfile-Latex.comp > Doxyfile-Latex cat Doxyfile-Base.comp >> Doxyfile-Latex doxygen Doxyfile-Latex +#cp -r NVSight/* includes/latex/ cp -r includes/latex/* latex/ cd latex make -cp refman.pdf ../../docs/documentation.pdf \ No newline at end of file +cp refman.pdf ../../docs/documentation.pdf + +#cp -r ../NVSight/* docs/ \ No newline at end of file diff --git a/docs/.html b/docs/.html new file mode 100644 index 00000000..72f5fd9d --- /dev/null +++ b/docs/.html @@ -0,0 +1,747 @@ + + + + + + + +Markopy: UnitTests.cpp Source File + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Markopy +
+
Utilizing Markov Models for brute forcing attacks
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
UnitTests.cpp
+
+
+Go to the documentation of this file.
1 #include "pch.h"
+
2 #include "CppUnitTest.h"
+
3 #include "MarkovModel/src/model.h"
+
4 
+
5 using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
6 
+
7 
+
8 /** @brief Namespace for Microsoft Native Unit Testing Classes
+
9 */
+
10 namespace Testing {
+
11 
+
12  /** @brief Testing Namespace for Minimal Viable Product
+
13  */
+
14  namespace MVP {
+
15  /** @brief Testing Namespace for MVP MarkovModel
+
16  */
+
17  namespace MarkovModel
+
18  {
+
19  /** @brief Test class for minimal viable Edge
+
20  */
+ +
22  {
+
23  public:
+
24 
+
25  /** @brief test default constructor
+
26  */
+ +
28  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>;
+
29  Assert::IsNull(e->LeftNode());
+
30  Assert::IsNull(e->RightNode());
+
31  delete e;
+
32  }
+
33 
+
34  /** @brief test linked constructor with two nodes
+
35  */
+ +
37  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
38  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
39  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+ + +
42  delete LeftNode;
+
43  delete RightNode;
+
44  delete e;
+
45  }
+
46 
+
47  /** @brief test AdjustEdge function
+
48  */
+ +
50  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
51  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
52  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
53  e->AdjustEdge(15);
+
54  Assert::AreEqual(15ull, e->EdgeWeight());
+
55  e->AdjustEdge(15);
+
56  Assert::AreEqual(30ull, e->EdgeWeight());
+
57  delete LeftNode;
+
58  delete RightNode;
+
59  delete e;
+
60  }
+
61 
+
62  /** @brief test TraverseNode returning RightNode
+
63  */
+ +
65  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
66  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
67  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+ +
69  delete LeftNode;
+
70  delete RightNode;
+
71  delete e;
+
72  }
+
73 
+
74  /** @brief test LeftNode/RightNode setter
+
75  */
+ +
77  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
78  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
79  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
80 
+
81  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>;
+ + +
84 
+
85  Assert::IsTrue(e1->LeftNode() == e2->LeftNode());
+
86  Assert::IsTrue(e1->RightNode() == e2->RightNode());
+
87  delete LeftNode;
+
88  delete RightNode;
+
89  delete e1;
+
90  delete e2;
+
91  }
+
92 
+
93  /** @brief test negative adjustments
+
94  */
+ +
96  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
97  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
98  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
99  e->AdjustEdge(15);
+
100  Assert::AreEqual(15ull, e->EdgeWeight());
+
101  e->AdjustEdge(-15);
+
102  Assert::AreEqual(0ull, e->EdgeWeight());
+
103  delete LeftNode;
+
104  delete RightNode;
+
105  delete e;
+
106  }
+
107  };
+
108 
+
109  /** @brief Test class for minimal viable Node
+
110  */
+ +
112  {
+
113  public:
+
114 
+
115  /** @brief test default constructor
+
116  */
+ +
118  Markov::Node<unsigned char>* n = new Markov::Node<unsigned char>();
+
119  Assert::AreEqual((unsigned char)0, n->NodeValue());
+
120  delete n;
+
121  }
+
122 
+
123  /** @brief test custom constructor with unsigned char
+
124  */
+ +
126  Markov::Node<unsigned char>* n = NULL;
+
127  unsigned char test_cases[] = { 'c', 0x00, 0xff, -32 };
+
128  for (unsigned char tcase : test_cases) {
+
129  n = new Markov::Node<unsigned char>(tcase);
+ +
131  delete n;
+
132  }
+
133  }
+
134 
+
135  /** @brief test link function
+
136  */
+ +
138  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
139  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
140 
+
141  Markov::Edge<unsigned char>* e = LeftNode->Link(RightNode);
+
142  delete LeftNode;
+
143  delete RightNode;
+
144  delete e;
+
145  }
+
146 
+
147  /** @brief test link function
+
148  */
+ +
150  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
151  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
152 
+
153  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(NULL, RightNode);
+
154  LeftNode->Link(e);
+
155  Assert::IsTrue(LeftNode == e->LeftNode());
+ +
157  delete LeftNode;
+
158  delete RightNode;
+
159  delete e;
+
160  }
+
161 
+
162  /** @brief test RandomNext with low values
+
163  */
+ + +
166  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
167  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
168  Markov::Edge<unsigned char>* e = src->Link(target1);
+
169  e->AdjustEdge(15);
+
170  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
171  Assert::IsTrue(res == target1);
+
172  delete src;
+
173  delete target1;
+
174  delete e;
+
175 
+
176  }
+
177 
+
178  /** @brief test RandomNext with 32 bit high values
+
179  */
+ + +
182  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
183  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
184  Markov::Edge<unsigned char>* e = src->Link(target1);
+
185  e->AdjustEdge(1 << 31);
+
186  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
187  Assert::IsTrue(res == target1);
+
188  delete src;
+
189  delete target1;
+
190  delete e;
+
191 
+
192  }
+
193 
+
194  /** @brief random next on a node with no follow-ups
+
195  */
+ + +
198  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
199  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
200  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
201  Markov::Edge<unsigned char>* e1 = src->Link(target1);
+
202  Markov::Edge<unsigned char>* e2 = src->Link(target2);
+
203  e1->AdjustEdge(1);
+
204  e2->AdjustEdge((unsigned long)(1ull << 31));
+
205  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
206  Assert::IsNotNull(res);
+
207  Assert::IsTrue(res == target2);
+
208  delete src;
+
209  delete target1;
+
210  delete e1;
+
211  delete e2;
+
212  }
+
213 
+
214  /** @brief random next on a node with no follow-ups
+
215  */
+ + +
218  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
219  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
220  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
221  Markov::Edge<unsigned char>* e1 = src->Link(target1);
+
222  Markov::Edge<unsigned char>* e2 = src->Link(target2);
+
223  e2->AdjustEdge(1);
+
224  e1->AdjustEdge((unsigned long)(1ull << 31));
+
225  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
226  Assert::IsNotNull(res);
+
227  Assert::IsTrue(res == target1);
+
228  delete src;
+
229  delete target1;
+
230  delete e1;
+
231  delete e2;
+
232  }
+
233 
+
234 
+
235  /** @brief test updateEdges
+
236  */
+ +
238 
+
239  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
240  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
241  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
242  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
+
243  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target2);
+
244  e1->AdjustEdge(25);
+
245  src->UpdateEdges(e1);
+
246  e2->AdjustEdge(30);
+
247  src->UpdateEdges(e2);
+
248 
+
249  Assert::AreEqual((size_t)2, src->Edges()->size());
+
250 
+
251  delete src;
+
252  delete target1;
+
253  delete e1;
+
254  delete e2;
+
255 
+
256  }
+
257 
+
258  /** @brief test updateEdges
+
259  */
+ +
261 
+
262  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
263  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
264  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
+
265  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target1);
+
266  e1->AdjustEdge(25);
+
267  src->UpdateEdges(e1);
+
268  e2->AdjustEdge(30);
+
269  src->UpdateEdges(e2);
+
270 
+
271  //Assert::AreEqual(55ull, src->TotalEdgeWeights());
+
272 
+
273  delete src;
+
274  delete target1;
+
275  delete e1;
+
276  delete e2;
+
277  }
+
278 
+
279 
+
280  /** @brief test FindVertice
+
281  */
+ +
283 
+
284  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
285  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
286  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
287  Markov::Edge<unsigned char>* res = NULL;
+
288  src->Link(target1);
+
289  src->Link(target2);
+
290 
+
291 
+
292  res = src->FindEdge('b');
+
293  Assert::IsNotNull(res);
+
294  Assert::AreEqual((unsigned char)'b', res->TraverseNode()->NodeValue());
+
295  res = src->FindEdge('c');
+
296  Assert::IsNotNull(res);
+
297  Assert::AreEqual((unsigned char)'c', res->TraverseNode()->NodeValue());
+
298 
+
299  delete src;
+
300  delete target1;
+
301  delete target2;
+
302 
+
303 
+
304  }
+
305 
+
306 
+
307  /** @brief test FindVertice
+
308  */
+ +
310 
+
311  auto _invalid_next = [] {
+
312  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
313  Markov::Edge<unsigned char>* res = NULL;
+
314 
+
315  res = src->FindEdge('b');
+
316  Assert::IsNull(res);
+
317 
+
318  delete src;
+
319  };
+
320 
+
321  //Assert::ExpectException<std::logic_error>(_invalid_next);
+
322  }
+
323 
+
324  /** @brief test FindVertice
+
325  */
+ +
327 
+
328  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
329  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
330  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
331  Markov::Edge<unsigned char>* res = NULL;
+
332  src->Link(target1);
+
333  src->Link(target2);
+
334 
+
335  res = src->FindEdge('D');
+
336  Assert::IsNull(res);
+
337 
+
338  delete src;
+
339  delete target1;
+
340  delete target2;
+
341 
+
342  }
+
343  };
+
344 
+
345  /** @brief Test class for minimal viable Model
+
346  */
+ +
348  {
+
349  public:
+
350  /** @brief test model constructor for starter node
+
351  */
+ +
353  Markov::Model<unsigned char> m;
+
354  Assert::AreEqual((unsigned char)'\0', m.StarterNode()->NodeValue());
+
355  }
+
356 
+
357  /** @brief test import
+
358  */
+ +
360  Markov::Model<unsigned char> m;
+
361  Assert::IsTrue(m.Import("../MarkovPasswords/Models/2gram.mdl"));
+
362  }
+
363 
+
364  /** @brief test export
+
365  */
+ +
367  Markov::Model<unsigned char> m;
+
368  Assert::IsTrue(m.Export("../MarkovPasswords/Models/testcase.mdl"));
+
369  }
+
370 
+
371  /** @brief test random walk
+
372  */
+ +
374  unsigned char* res = new unsigned char[12 + 5];
+ +
376  Markov::Model<unsigned char> m;
+
377  Assert::IsTrue(m.Import("../Models/finished2.mdl"));
+ +
379  }
+
380  };
+
381  }
+
382 
+
383  /** @brief Testing namespace for MVP MarkovPasswords
+
384  */
+
385  namespace MarkovPasswords
+
386  {
+
387  /** @brief Test Class for Argparse class
+
388  */
+ +
390  {
+
391  public:
+
392  /** @brief test basic generate
+
393  */
+ +
395  int argc = 8;
+
396  char *argv[] = {"markov.exe", "generate", "-if", "model.mdl", "-of", "passwords.txt", "-n", "100"};
+
397 
+
398  /*ProgramOptions *p = Argparse::parse(argc, argv);
+
399  Assert::IsNotNull(p);
+
400 
+
401  Assert::AreEqual(p->bImport, true);
+
402  Assert::AreEqual(p->bExport, false);
+
403  Assert::AreEqual(p->importname, "model.mdl");
+
404  Assert::AreEqual(p->outputfilename, "passwords.txt");
+
405  Assert::AreEqual(p->generateN, 100); */
+
406 
+
407  }
+
408 
+
409  /** @brief test basic generate reordered params
+
410  */
+ +
412  int argc = 8;
+
413  char *argv[] = { "markov.exe", "generate", "-n", "100", "-if", "model.mdl", "-of", "passwords.txt" };
+
414 
+
415  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
416  Assert::IsNotNull(p);
+
417 
+
418  Assert::AreEqual(p->bImport, true);
+
419  Assert::AreEqual(p->bExport, false);
+
420  Assert::AreEqual(p->importname, "model.mdl");
+
421  Assert::AreEqual(p->outputfilename, "passwords.txt");
+
422  Assert::AreEqual(p->generateN, 100);*/
+
423  }
+
424 
+
425  /** @brief test basic generate param longnames
+
426  */
+ +
428  int argc = 8;
+
429  char *argv[] = { "markov.exe", "generate", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
+
430 
+
431  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
432  Assert::IsNotNull(p);
+
433 
+
434  Assert::AreEqual(p->bImport, true);
+
435  Assert::AreEqual(p->bExport, false);
+
436  Assert::AreEqual(p->importname, "model.mdl");
+
437  Assert::AreEqual(p->outputfilename, "passwords.txt");
+
438  Assert::AreEqual(p->generateN, 100); */
+
439  }
+
440 
+
441  /** @brief test basic generate
+
442  */
+ +
444  int argc = 8;
+
445  char *argv[] = { "markov.exe", "junk", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
+
446 
+
447  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
448  Assert::IsNull(p); */
+
449  }
+
450 
+
451  /** @brief test basic train
+
452  */
+ +
454  int argc = 4;
+
455  char *argv[] = { "markov.exe", "train", "-ef", "model.mdl" };
+
456 
+
457  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
458  Assert::IsNotNull(p);
+
459 
+
460  Assert::AreEqual(p->bImport, false);
+
461  Assert::AreEqual(p->bExport, true);
+
462  Assert::AreEqual(p->exportname, "model.mdl"); */
+
463 
+
464  }
+
465 
+
466  /** @brief test basic generate
+
467  */
+ +
469  int argc = 4;
+
470  char *argv[] = { "markov.exe", "train", "--exportfilename", "model.mdl" };
+
471 
+
472  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
473  Assert::IsNotNull(p);
+
474 
+
475  Assert::AreEqual(p->bImport, false);
+
476  Assert::AreEqual(p->bExport, true);
+
477  Assert::AreEqual(p->exportname, "model.mdl"); */
+
478  }
+
479 
+
480 
+
481 
+
482  };
+
483 
+
484  }
+
485  }
+
486 
+
487 
+
488  /** @brief Testing namespace for MarkovModel
+
489  */
+
490  namespace MarkovModel {
+
491 
+
492  /** @brief Test class for rest of Edge cases
+
493  */
+ +
495  {
+
496  public:
+
497  /** @brief send exception on integer underflow
+
498  */
+ +
500  auto _underflow_adjust = [] {
+
501  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
502  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
503  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
504  e->AdjustEdge(15);
+
505  e->AdjustEdge(-30);
+
506  delete LeftNode;
+
507  delete RightNode;
+
508  delete e;
+
509  };
+ +
511  }
+
512 
+
513  /** @brief test integer overflows
+
514  */
+ +
516  auto _overflow_adjust = [] {
+
517  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
518  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
519  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
520  e->AdjustEdge(~0ull);
+
521  e->AdjustEdge(1);
+
522  delete LeftNode;
+
523  delete RightNode;
+
524  delete e;
+
525  };
+ +
527  }
+
528  };
+
529 
+
530  /** @brief Test class for rest of Node cases
+
531  */
+ +
533  {
+
534  public:
+
535 
+
536  /** @brief test RandomNext with 64 bit high values
+
537  */
+ + +
540  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
541  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
542  Markov::Edge<unsigned char>* e = src->Link(target1);
+
543  e->AdjustEdge((unsigned long)(1ull << 63));
+
544  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
545  Assert::IsTrue(res == target1);
+
546  delete src;
+
547  delete target1;
+
548  delete e;
+
549 
+
550  }
+
551 
+
552  /** @brief test RandomNext with 64 bit high values
+
553  */
+ + +
556  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
557  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
558  Markov::Edge<unsigned char>* e = src->Link(target1);
+
559  e->AdjustEdge((0xffffFFFF));
+
560  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
561  Assert::IsTrue(res == target1);
+
562  delete src;
+
563  delete target1;
+
564  delete e;
+
565 
+
566  }
+
567 
+
568  /** @brief randomNext when no edges are present
+
569  */
+ +
571 
+
572  auto _invalid_next = [] {
+ +
574  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
575  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
576  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(src, target1);
+
577  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
578 
+
579  delete src;
+
580  delete target1;
+
581  delete e;
+
582  };
+
583 
+ +
585  }
+
586 
+
587 
+
588  };
+
589 
+
590  /** @brief Test class for rest of model cases
+
591  */
+ +
593  {
+
594  public:
+ +
596  unsigned char* res2 = new unsigned char[12 + 5];
+ +
598  Markov::Model<unsigned char> m;
+
599  Markov::Node<unsigned char>* starter = m.StarterNode();
+
600  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
+
601  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
+
602  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
+
603  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
+
604  starter->Link(a)->AdjustEdge(1);
+
605  a->Link(b)->AdjustEdge(1);
+
606  b->Link(c)->AdjustEdge(1);
+
607  c->Link(end)->AdjustEdge(1);
+
608 
+
609  char* res = (char*)m.RandomWalk(&MarsagliaRandomEngine,1,12,res2);
+
610  Assert::IsFalse(strcmp(res, "abc"));
+
611  }
+ +
613  Markov::Model<unsigned char> m;
+
614  Markov::Node<unsigned char>* starter = m.StarterNode();
+
615  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
+
616  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
+
617  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
+
618  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
+
619  Markov::Edge<unsigned char>* res = NULL;
+
620  starter->Link(a)->AdjustEdge(1);
+
621  a->Link(b)->AdjustEdge(1);
+
622  b->Link(c)->AdjustEdge(1);
+
623  c->Link(end)->AdjustEdge(1);
+
624 
+
625  res = starter->FindEdge('D');
+
626  Assert::IsNull(res);
+
627 
+
628  }
+
629  };
+
630 
+
631  }
+
632 
+
633  /** @brief Testing namespace for MarkovPasswords
+
634  */
+
635  namespace MarkovPasswords {
+
636 
+
637  };
+
638 
+
639 }
+
+
+
TEST_CLASS(ArgParser)
Test Class for Argparse class.
Definition: UnitTests.cpp:389
+
Testing namespace for MarkovPasswords.
Definition: UnitTests.cpp:635
+
Testing Namespace for Minimal Viable Product.
Definition: UnitTests.cpp:14
+
Namespace for Microsoft Native Unit Testing Classes.
Definition: UnitTests.cpp:10
+
TEST_CLASS(Model)
Test class for rest of model cases.
Definition: UnitTests.cpp:592
+
TEST_CLASS(Model)
Test class for minimal viable Model.
Definition: UnitTests.cpp:347
+ + + + diff --git a/docs/_c_l_i_8cpp.html b/docs/_c_l_i_8cpp.html new file mode 100644 index 00000000..46022e9c --- /dev/null +++ b/docs/_c_l_i_8cpp.html @@ -0,0 +1,121 @@ + + + + + + + +Markopy: CLI.cpp File Reference + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Markopy +
+
Utilizing Markov Models for brute forcing attacks
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
CLI.cpp File Reference
+
+
+ +

CLI page. +More...

+
#include "CLI.h"
+#include <fstream>
+#include "Train.h"
+
+Include dependency graph for CLI.cpp:
+
+
+
+
+
+

Go to the source code of this file.

+

Detailed Description

+

CLI page.

+
Authors
Yunus Emre Yılmaz
+ +

Definition in file CLI.cpp.

+
+
+ + + + diff --git a/docs/_c_l_i_8cpp__incl.map b/docs/_c_l_i_8cpp__incl.map new file mode 100644 index 00000000..b1c5aa82 --- /dev/null +++ b/docs/_c_l_i_8cpp__incl.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/docs/_c_l_i_8cpp__incl.md5 b/docs/_c_l_i_8cpp__incl.md5 new file mode 100644 index 00000000..cba37329 --- /dev/null +++ b/docs/_c_l_i_8cpp__incl.md5 @@ -0,0 +1 @@ +a0afc6ed7ae440ab5762db0fe6f98f48 \ No newline at end of file diff --git a/docs/_c_l_i_8cpp__incl.svg b/docs/_c_l_i_8cpp__incl.svg new file mode 100644 index 00000000..a9742331 --- /dev/null +++ b/docs/_c_l_i_8cpp__incl.svg @@ -0,0 +1,117 @@ + + + + + + +CLI.cpp + + +Node1 + + +CLI.cpp + + + + + +Node2 + + +CLI.h + + + + + +Node1->Node2 + + + + + +Node5 + + +fstream + + + + + +Node1->Node5 + + + + + +Node6 + + +Train.h + + + + + +Node1->Node6 + + + + + +Node3 + + +QtWidgets/QMainWindow + + + + + +Node2->Node3 + + + + + +Node4 + + +ui_CLI.h + + + + + +Node2->Node4 + + + + + +Node6->Node3 + + + + + +Node7 + + +ui_Train.h + + + + + +Node6->Node7 + + + + + diff --git a/docs/_c_l_i_8cpp_source.html b/docs/_c_l_i_8cpp_source.html new file mode 100644 index 00000000..a2bd5b31 --- /dev/null +++ b/docs/_c_l_i_8cpp_source.html @@ -0,0 +1,151 @@ + + + + + + + +Markopy: CLI.cpp Source File + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Markopy +
+
Utilizing Markov Models for brute forcing attacks
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
CLI.cpp
+
+
+Go to the documentation of this file.
1 /** @file cli.cpp
+
2  * @brief CLI page
+
3  * @authors Yunus Emre Yılmaz
+
4  *
+
5  */
+
6 
+
7 #include "CLI.h"
+
8 #include <fstream>
+
9 #include "Train.h"
+
10 
+
11 
+
12 
+
13 using namespace Markov::GUI;
+
14 
+
15 Markov::GUI::CLI::CLI(QWidget* parent)
+
16  : QMainWindow(parent)
+
17 {
+
18  ui.setupUi(this);
+
19 
+
20  QObject::connect(ui.startButton, &QPushButton::clicked, this, [this] {start(); });
+
21  QObject::connect(ui.commandLinkButton_2, &QPushButton::clicked, this, [this] {statistics(); });
+
22  QObject::connect(ui.commandLinkButton, &QPushButton::clicked, this, [this] {about(); });
+
23 
+
24 }
+
25 
+
26 void Markov::GUI::CLI::start() {
+
27  Train* w = new Train;
+
28  w->show();
+
29  this->close();
+
30 }
+
31 void Markov::GUI::CLI::statistics() {
+
32  /*
+
33  statistic will show
+
34  */
+
35 }
+
36 void Markov::GUI::CLI::about() {
+
37  /*
+
38  about button
+
39  */
+
40 }
+
+
+
void about()
Definition: CLI.cpp:36
+
namespace for MarkovPasswords API GUI wrapper
Definition: about.h:14
+
void start()
Definition: CLI.cpp:26
+
void statistics()
Definition: CLI.cpp:31
+
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+
QT CLI Class.
Definition: CLI.h:14
+
QT Training page class.
Definition: Train.h:15
+
Ui::CLI ui
Definition: CLI.h:20
+
CLI(QWidget *parent=Q_NULLPTR)
Definition: CLI.cpp:15
+ + + + diff --git a/docs/_c_l_i_8h.html b/docs/_c_l_i_8h.html index d37ca312..f3a1d31a 100644 --- a/docs/_c_l_i_8h.html +++ b/docs/_c_l_i_8h.html @@ -17,7 +17,7 @@ - +
@@ -90,6 +90,9 @@
CLI.h File Reference
+ +

CLI page. +More...

#include <QtWidgets/QMainWindow>
#include "ui_CLI.h"
@@ -101,7 +104,7 @@
This graph shows which files directly or indirectly include this file:
-
+
@@ -122,13 +125,18 @@  namespace for MarkovPasswords API GUI wrapper
  -
+

Detailed Description

+

CLI page.

+
Authors
Yunus Emre Yılmaz
+ +

Definition in file CLI.h.

+
-Go to the documentation of this file.
1 #pragma once
-
2 #include <QtWidgets/QMainWindow>
-
3 #include "ui_CLI.h"
-
4 
-
5 namespace Markov::GUI{
-
6  /** @brief QT CLI Class
-
7  */
-
8  class CLI :public QMainWindow {
- -
10  public:
- -
12 
-
13  private:
-
14  Ui::CLI ui;
-
15 
-
16  public slots:
-
17  void start();
-
18  void statistics();
-
19  void about();
-
20  };
-
21 };
+Go to the documentation of this file.
1 /** @file cli.h
+
2  * @brief CLI page
+
3  * @authors Yunus Emre Yılmaz
+
4  *
+
5  */
+
6 
+
7 #pragma once
+
8 #include <QtWidgets/QMainWindow>
+
9 #include "ui_CLI.h"
+
10 
+
11 namespace Markov::GUI{
+
12  /** @brief QT CLI Class
+
13  */
+
14  class CLI :public QMainWindow {
+
15  Q_OBJECT
+
16  public:
+
17  CLI(QWidget* parent = Q_NULLPTR);
+
18 
+
19  private:
+
20  Ui::CLI ui;
+
21 
+
22  public slots:
+
23  void start();
+
24  void statistics();
+
25  void about();
+
26  };
+
27 };
- -
namespace for MarkovPasswords API GUI wrapper
Definition: menu.h:6
- - -
Ui::CLI ui
Definition: CLI.h:14
+
void about()
Definition: CLI.cpp:36
+
namespace for MarkovPasswords API GUI wrapper
Definition: about.h:14
+
void start()
Definition: CLI.cpp:26
+
void statistics()
Definition: CLI.cpp:31
+
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+
QT CLI Class.
Definition: CLI.h:14
+
Ui::CLI ui
Definition: CLI.h:20
+
CLI(QWidget *parent=Q_NULLPTR)
Definition: CLI.cpp:15
+ +

Test cases for Markov::API::ModelMatrix. +More...

#include <iostream>
#include "color/term.h"
#include "argparse.h"
#include <string>
#include <cstring>
#include <sstream>
-#include "markovPasswords.h"
-#include "modelMatrix.h"
+#include "MarkovAPI/src/markovPasswords.h"
+#include "MarkovAPI/src/modelMatrix.h"
#include <chrono>
-Include dependency graph for src/main.cpp:
+Include dependency graph for MarkovAPICLI/src/main.cpp:
-
+
-

Go to the source code of this file.

+

Go to the source code of this file.

- - + +

Functions

int main (int argc, char **argv)
 Launch CLI tool. More...
int main (int argc, char **argv)
 Launch CLI tool. More...
 
-

Function Documentation

+

Detailed Description

+

Test cases for Markov::API::ModelMatrix.

+
Authors
Ata Hakçıl, Celal Sahir Çetiner
+

Parse command line arguements.

+

Class to flatten and reduce Markov::Model to a Matrix. Matrix level operations can be used for Generation events, with a significant performance optimization at the cost of O(N) memory complexity (O(1) memory space for slow mode)

+

To limit the maximum memory usage, each generation operation is partitioned into 50M chunks for allocation. Threads are sychronized and files are flushed every 50M operations.

+

Markov::Model with char represented nodes. Includes wrappers for Markov::Model and additional helper functions to handle file I/O

+

This class is an extension of Markov::Model<char>, with higher level abstractions such as train and generate.

+ +

Definition in file MarkovAPICLI/src/main.cpp.

+

Function Documentation

◆ main()

@@ -129,7 +142,7 @@

- char **  + char **  argv  @@ -142,43 +155,42 @@

Definition at line 14 of file src/main.cpp.

-
14  {
-
15 
- -
17  /*
-
18  ProgramOptions* p = Argparse::parse(argc, argv);
-
19 
-
20  if (p==0 || p->bFailure) {
-
21  std::cout << TERM_FAIL << "Arguments Failed to Parse" << std::endl;
-
22  Argparse::help();
-
23  }*/
-
24  Markov::API::CLI::Argparse a(argc,argv);
-
25 
- -
27 
-
28  mp.Import("Markopy/src/CLI/sample_models/2gram.mdl");
-
29  mp.Train("datasets/graduation.corpus", '\t', 1);
-
30  mp.Export("test.mdl");
-
31  return 0;/*
-
32  std::cerr << "Importing model.\n";
-
33  markovPass.Import("models/finished.mdl");
-
34  std::cerr << "Import done. \n";
-
35  markovPass.ConstructMatrix();
-
36  std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
-
37  //markovPass.FastRandomWalk(50000000,"/media/ignis/Stuff/wordlist.txt",6,12,25, true);
-
38  markovPass.FastRandomWalk(500000000,"/media/ignis/Stuff/wordlist2.txt",6,12,25, true);
-
39  std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
-
40 
-
41  std::cerr << "Finished in:" << std::chrono::duration_cast<std::chrono::milliseconds> (end - begin).count() << " milliseconds" << std::endl;*/
-
42  return 0;
-
43 }
+

Definition at line 23 of file MarkovAPICLI/src/main.cpp.

+
23  {
+
24 
+ +
26  /*
+
27  ProgramOptions* p = Argparse::parse(argc, argv);
+
28 
+
29  if (p==0 || p->bFailure) {
+
30  std::cout << TERM_FAIL << "Arguments Failed to Parse" << std::endl;
+
31  Argparse::help();
+
32  }*/
+
33  Markov::API::CLI::Argparse a(argc,argv);
+
34 
+
35  Markov::API::ModelMatrix markovPass;
+
36  std::cerr << "Importing model.\n";
+
37  markovPass.Import("models/finished.mdl");
+
38  std::cerr << "Import done. \n";
+
39 
+
40  markovPass.Buff("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", 100);
+
41 
+
42  markovPass.Export("models/buffed-symbols-100fold.mdl");
+
43  //markovPass.ConstructMatrix();
+
44  //std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
+
45  //markovPass.FastRandomWalk(50000000,"/media/ignis/Stuff/wordlist.txt",6,12,25, true);
+
46  //markovPass.FastRandomWalk(500000000,"/media/ignis/Stuff/wordlist2.txt",6,12,25, true);
+
47  //std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
+
48 
+
49  //std::cerr << "Finished in:" << std::chrono::duration_cast<std::chrono::milliseconds> (end - begin).count() << " milliseconds" << std::endl;
+
50  return 0;
+
51 }
-

References Markov::API::CLI::Argparse::Argparse(), Markov::Model< NodeStorageType >::Export(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

+

References Markov::API::CLI::Argparse::Argparse(), Markov::API::MarkovPasswords::Buff(), Markov::Model< NodeStorageType >::Export(), and Markov::API::ModelMatrix::Import().

Here is the call graph for this function:
-
+
@@ -186,17 +198,17 @@

void Import(const char *filename)
Open a file to import with filename, and call bool Model::Import with std::ifstream.
Definition: modelMatrix.cpp:10

-
Class to flatten and reduce Markov::Model to a Matrix.
Definition: modelMatrix.h:13
-
bool Export(std::ofstream *)
Export a file of the model.
Definition: model.h:274
-
pretty colors for Terminal. Windows Only.
Definition: term.h:18
-
Parse command line arguements.
Definition: argparse.h:74
-
void Train(const char *datasetFileName, char delimiter, int threads)
Train the model with the dataset file.
Definition: modelMatrix.cpp:16
+
void Import(const char *filename)
Open a file to import with filename, and call bool Model::Import with std::ifstream.
Definition: modelMatrix.cpp:19
+
Class to flatten and reduce Markov::Model to a Matrix.
Definition: modelMatrix.h:23
+
bool Export(std::ofstream *)
Export a file of the model.
Definition: model.h:288
+
pretty colors for Terminal. Windows Only.
Definition: term.h:25
+
Parse command line arguements.
Definition: argparse.h:82
+
void Buff(const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
Buff expression of some characters in the model.
+

Detailed Description

+

For windows dynamic library.

+
Authors
Ata Hakçıl
+ +

Definition in file MarkovModel/src/pch.cpp.

+

-Go to the documentation of this file.
1 // pch.cpp: source file corresponding to the pre-compiled header
-
2 
-
3 #include "pch.h"
-
4 
-
5 // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
+Go to the documentation of this file.
1 /** @file pch.cpp
+
2  * @brief For windows dynamic library
+
3  * @authors Ata Hakçıl
+
4  *
+
5  */
+
6 
+
7 // pch.cpp: source file corresponding to the pre-compiled header
+
8 
+
9 #include "pch.h"
+
10 
+
11 // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
+ +

For windows dynamic library. +More...

#include "framework.h"
Include dependency graph for MarkovModel/src/pch.h:
@@ -102,13 +105,18 @@

Go to the source code of this file.

- +

Detailed Description

+

For windows dynamic library.

+
Authors
Ata Hakçıl
+ +

Definition in file MarkovModel/src/pch.h.

+
-Go to the documentation of this file.
1 // pch.h: This is a precompiled header file.
-
2 // Files listed below are compiled only once, improving build performance for future builds.
-
3 // This also affects IntelliSense performance, including code completion and many code browsing features.
-
4 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
-
5 // Do not add files here that you will be updating frequently as this negates the performance advantage.
-
6 
-
7 #ifndef PCH_H
-
8 #define PCH_H
-
9 
-
10 // add headers that you want to pre-compile here
-
11 #include "framework.h"
-
12 
-
13 #endif //PCH_H
+Go to the documentation of this file.
1 /** @file pch.h
+
2  * @brief For windows dynamic library
+
3  * @authors Ata Hakçıl
+
4  *
+
5  */
+
6 // pch.h: This is a precompiled header file.
+
7 // Files listed below are compiled only once, improving build performance for future builds.
+
8 // This also affects IntelliSense performance, including code completion and many code browsing features.
+
9 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
+
10 // Do not add files here that you will be updating frequently as this negates the performance advantage.
+
11 
+
12 #ifndef PCH_H
+
13 #define PCH_H
+
14 
+
15 // add headers that you want to pre-compile here
+
16 #include "framework.h"
+
17 
+
18 #endif //PCH_H
+ +

Entry point for GUI. +More...

#include "menu.h"
#include <QtWidgets/QApplication>
#include <QSplashScreen>
#include <QDateTime>
#include "CLI.h"
-Include dependency graph for UI/src/main.cpp:
+Include dependency graph for MarkovPasswordsGUI/src/main.cpp:
-
+
-

Go to the source code of this file.

+

Go to the source code of this file.

- - + +

Functions

int main (int argc, char *argv[])
 Launch UI. More...
int main (int argc, char *argv[])
 Launch UI. More...
 
-

Function Documentation

+

Detailed Description

+

Entry point for GUI.

+
Authors
Yunus Emre Yılmaz
+ +

Definition in file MarkovPasswordsGUI/src/main.cpp.

+

Function Documentation

◆ main()

@@ -125,7 +133,7 @@

- char *  + charargv[]  @@ -138,49 +146,41 @@

Definition at line 12 of file UI/src/main.cpp.

-
13 {
-
14 
-
15 
-
16 
-
17  QApplication a(argc, argv);
-
18 
-
19  QPixmap loadingPix("views/startup.jpg");
-
20  QSplashScreen splash(loadingPix);
-
21  splash.show();
-
22  QDateTime time = QDateTime::currentDateTime();
-
23  QDateTime currentTime = QDateTime::currentDateTime(); //Record current time
-
24  while (time.secsTo(currentTime) <= 5) //5 is the number of seconds to delay
-
25  {
-
26  currentTime = QDateTime::currentDateTime();
-
27  a.processEvents();
-
28  };
-
29 
-
30 
-
31  CLI w;
-
32  w.show();
-
33  splash.finish(&w);
-
34  return a.exec();
-
35 }
+

Definition at line 18 of file MarkovPasswordsGUI/src/main.cpp.

+
19 {
+
20 
+
21 
+
22 
+
23  QApplication a(argc, argv);
+
24 
+
25  QPixmap loadingPix("views/startup.jpg");
+
26  QSplashScreen splash(loadingPix);
+
27  splash.show();
+
28  QDateTime time = QDateTime::currentDateTime();
+
29  QDateTime currentTime = QDateTime::currentDateTime(); //Record current time
+
30  while (time.secsTo(currentTime) <= 5) //5 is the number of seconds to delay
+
31  {
+
32  currentTime = QDateTime::currentDateTime();
+
33  a.processEvents();
+
34  };
+
35 
+
36 
+
37  CLI w;
+
38  w.show();
+
39  splash.finish(&w);
+
40  return a.exec();
+
41 }
-

References Markov::GUI::CLI::start().

-
-Here is the call graph for this function:
-
-
-
-
-

-
QT CLI Class.
Definition: CLI.h:8
+
QT CLI Class.
Definition: CLI.h:14
-Go to the documentation of this file.
-
2 #include <fstream>
-
3 #include <qwebengineview.h>
-
4 #include <Windows.h>
-
5 #include "CLI.h"
+Go to the documentation of this file.
1 /** @file MarkovPasswordsGUI.cpp
+
2  * @brief Main activity page for GUI
+
3  * @authors Yunus Emre Yılmaz
+
4  *
+
5  */
6 
-
7 using namespace Markov::GUI;
-
8 
-
9 MarkovPasswordsGUI::MarkovPasswordsGUI(QWidget *parent)
-
10  : QMainWindow(parent)
-
11 {
-
12  ui.setupUi(this);
+ +
8 #include <fstream>
+
9 #include <qwebengineview.h>
+
10 #include "CLI.h"
+
11 
+
12 using namespace Markov::GUI;
13 
-
14 
-
15  QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {home(); });
-
16  QObject::connect(ui.pushButton_2, &QPushButton::clicked, this, [this] {model(); });
-
17  QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {pass(); });
-
18 }
-
19 
-
20 
-
21 void MarkovPasswordsGUI::home() {
-
22  CLI* w = new CLI;
-
23  w->show();
-
24  this->close();
-
25 }
-
26 void MarkovPasswordsGUI::pass() {
-
27  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
-
28 
-
29  //get working directory
-
30  char path[255];
-
31  GetCurrentDirectoryA(255, path);
-
32 
-
33  //get absolute path to the layout html
-
34  std::string layout = "file:///" + std::string(path) + "\\views\\bar.html";
-
35  std::replace(layout.begin(), layout.end(), '\\', '/');
-
36  webkit->setUrl(QUrl(layout.c_str()));
-
37 }
-
38 
-
39 void MarkovPasswordsGUI::model() {
-
40  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
+
14 Markov::GUI::MarkovPasswordsGUI::MarkovPasswordsGUI(QWidget *parent) : QMainWindow(parent){
+
15  ui.setupUi(this);
+
16 
+
17 
+
18  QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {home(); });
+
19  QObject::connect(ui.pushButton_2, &QPushButton::clicked, this, [this] {model(); });
+
20  QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {pass(); });
+
21 }
+
22 
+
23 
+ +
25  CLI* w = new CLI;
+
26  w->show();
+
27  this->close();
+
28 }
+ +
30  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
+
31 
+
32  //get working directory
+
33  char path[255];
+
34  GetCurrentDirectoryA(255, path);
+
35 
+
36  //get absolute path to the layout html
+
37  std::string layout = "file:///" + std::string(path) + "\\views\\bar.html";
+
38  std::replace(layout.begin(), layout.end(), '\\', '/');
+
39  webkit->setUrl(QUrl(layout.c_str()));
+
40 }
41 
-
42  //get working directory
-
43  char path[255];
-
44  GetCurrentDirectoryA(255, path);
-
45 
-
46  //get absolute path to the layout html
-
47  std::string layout = "file:///" + std::string(path) + "\\views\\index.html";
-
48  std::replace(layout.begin(), layout.end(), '\\', '/');
-
49  webkit->setUrl(QUrl(layout.c_str()));
-
50 }
+ +
43  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
+
44 
+
45  //get working directory
+
46  char path[255];
+
47  GetCurrentDirectoryA(255, path);
+
48 
+
49  //get absolute path to the layout html
+
50  std::string layout = "file:///" + std::string(path) + "\\views\\index.html";
+
51  std::replace(layout.begin(), layout.end(), '\\', '/');
+
52  webkit->setUrl(QUrl(layout.c_str()));
+
53 }
-
namespace for MarkovPasswords API GUI wrapper
Definition: menu.h:6
+ +
namespace for MarkovPasswords API GUI wrapper
Definition: about.h:14
+ +
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+
QT CLI Class.
Definition: CLI.h:14
+ +
MarkovPasswordsGUI(QWidget *parent=Q_NULLPTR)
+
Ui::MarkovPasswordsGUIClass ui
+
+ +

Main activity page for GUI. +More...

#include <QtWidgets/QMainWindow>
#include "ui_MarkovPasswordsGUI.h"
@@ -101,7 +104,7 @@
This graph shows which files directly or indirectly include this file:
-
+
@@ -122,13 +125,18 @@  namespace for MarkovPasswords API GUI wrapper
  -
+

Detailed Description

+

Main activity page for GUI.

+
Authors
Yunus Emre Yılmaz
+ +

Definition in file MarkovPasswordsGUI.h.

+
-Go to the documentation of this file.
1 #pragma once
-
2 
-
3 #include <QtWidgets/QMainWindow>
-
4 #include "ui_MarkovPasswordsGUI.h"
-
5 
+Go to the documentation of this file.
1 /** @file MarkovPasswordsGUI.h
+
2  * @brief Main activity page for GUI
+
3  * @authors Yunus Emre Yılmaz
+
4  *
+
5  */
6 
-
7 
-
8 namespace Markov::GUI{
-
9  /** @brief Reporting UI.
-
10  *
-
11  * UI for reporting and debugging tools for MarkovPassword
-
12  */
- -
14  Q_OBJECT
-
15 
-
16  private:
- -
18 
-
19 
-
20  //Slots for buttons in GUI.
-
21  public slots:
-
22 
- - - - +
7 #pragma once
+
8 
+
9 #include <QtWidgets/QMainWindow>
+
10 #include "ui_MarkovPasswordsGUI.h"
+
11 
+
12 
+
13 
+
14 namespace Markov::GUI{
+
15  /** @brief Reporting UI.
+
16  *
+
17  * UI for reporting and debugging tools for MarkovPassword
+
18  */
+
19  class MarkovPasswordsGUI : public QMainWindow {
+
20  Q_OBJECT
+
21  public:
+
22  MarkovPasswordsGUI(QWidget* parent = Q_NULLPTR);
+
23 
+
24  private:
+
25  Ui::MarkovPasswordsGUIClass ui;
+
26 
27 
-
28 
-
29  public slots:
+
28  //Slots for buttons in GUI.
+
29  public slots:
30 
-
31  void MarkovPasswordsGUI::home();
-
32  void MarkovPasswordsGUI :: pass();
-
33  void MarkovPasswordsGUI::model();
-
34  };
-
35 };
+
31  void benchmarkSelected();
+
32  //void MarkovPasswordsGUI::modelvisSelected();
+
33  //void MarkovPasswordsGUI::visualDebugSelected();
+
34  //void MarkovPasswordsGUI::comparisonSelected();
+
35 
+
36 
+
37  public slots:
+
38 
+
39  void home();
+
40  void pass();
+
41  void model();
+
42  };
+
43 };
-
void MarkovPasswordsGUI::home()
-
namespace for MarkovPasswords API GUI wrapper
Definition: menu.h:6
-
void MarkovPasswordsGUI::comparisonSelected()
-
void MarkovPasswordsGUI ::pass()
-
void MarkovPasswordsGUI::visualDebugSelected()
-
void MarkovPasswordsGUI::modelvisSelected()
-
void MarkovPasswordsGUI::model()
+ +
namespace for MarkovPasswords API GUI wrapper
Definition: about.h:14
+ +
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+ +
MarkovPasswordsGUI(QWidget *parent=Q_NULLPTR)
+
Ui::MarkovPasswordsGUIClass ui
+ +
-Go to the documentation of this file.
1 #pragma once
-
2 #include <QtWidgets/QMainWindow>
-
3 #include "ui_Train.h"
-
4 
-
5 namespace Markov::GUI{
+Go to the documentation of this file.
1 /** @file Train.h
+
2  * @brief training page for GUI
+
3  * @authors Yunus Emre Yılmaz
+
4  *
+
5  */
6 
-
7  /** @brief QT Training page class
-
8  */
-
9  class Train :public QMainWindow {
-
10  Q_OBJECT
-
11  public:
- -
13 
-
14  private:
- -
16 
-
17  public slots:
-
18  void home();
-
19  void train();
-
20  };
-
21 };
+
7 #pragma once
+
8 #include <QtWidgets/QMainWindow>
+
9 #include "ui_Train.h"
+
10 
+
11 namespace Markov::GUI{
+
12 
+
13  /** @brief QT Training page class
+
14  */
+
15  class Train :public QMainWindow {
+
16  Q_OBJECT
+
17  public:
+
18  Train(QWidget* parent = Q_NULLPTR);
+
19 
+
20  private:
+
21  Ui::Train ui;
+
22 
+
23  public slots:
+
24  void home();
+
25  void train();
+
26  };
+
27 };
-
namespace for MarkovPasswords API GUI wrapper
Definition: menu.h:6
-
Ui::Train ui
Definition: Train.h:15
- - +
namespace for MarkovPasswords API GUI wrapper
Definition: about.h:14
+
Ui::Train ui
Definition: Train.h:21
+
Train(QWidget *parent=Q_NULLPTR)
Definition: Train.cpp:22
+
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+ +
QT Training page class.
Definition: Train.h:15
+
+ +

For windows dynamic library. +More...

#include "pch.h"
Include dependency graph for UnitTests/pch.cpp:
@@ -96,13 +99,18 @@

Go to the source code of this file.

- +

Detailed Description

+

For windows dynamic library.

+
Authors
Ata Hakçıl
+ +

Definition in file UnitTests/pch.cpp.

+
-Go to the documentation of this file.
1 // pch.cpp: source file corresponding to the pre-compiled header
-
2 
-
3 #include "pch.h"
-
4 
-
5 // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
+Go to the documentation of this file.
1 /** @file pch.cpp
+
2  * @brief For windows dynamic library
+
3  * @authors Ata Hakçıl
+
4  *
+
5  */
+
6 // pch.cpp: source file corresponding to the pre-compiled header
+
7 
+
8 #include "pch.h"
+
9 
+
10 // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
+ +

For windows dynamic library. +More...

This graph shows which files directly or indirectly include this file:
@@ -95,13 +98,18 @@

Go to the source code of this file.

-
+

Detailed Description

+

For windows dynamic library.

+
Authors
Ata Hakçıl
+ +

Definition in file UnitTests/pch.h.

+
-Go to the documentation of this file.
1 // pch.h: This is a precompiled header file.
-
2 // Files listed below are compiled only once, improving build performance for future builds.
-
3 // This also affects IntelliSense performance, including code completion and many code browsing features.
-
4 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
-
5 // Do not add files here that you will be updating frequently as this negates the performance advantage.
-
6 
-
7 #ifndef PCH_H
-
8 #define PCH_H
-
9 
-
10 // add headers that you want to pre-compile here
+Go to the documentation of this file.
1 /** @file pch.h
+
2  * @brief For windows dynamic library
+
3  * @authors Ata Hakçıl
+
4  *
+
5  */
+
6 // pch.h: This is a precompiled header file.
+
7 // Files listed below are compiled only once, improving build performance for future builds.
+
8 // This also affects IntelliSense performance, including code completion and many code browsing features.
+
9 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
+
10 // Do not add files here that you will be updating frequently as this negates the performance advantage.
11 
-
12 #endif //PCH_H
+
12 #ifndef PCH_H
+
13 #define PCH_H
+
14 
+
15 // add headers that you want to pre-compile here
+
16 
+
17 #endif //PCH_H
+ +

Unit tests with Microsoft::VisualStudio::CppUnitTestFramework. +More...

#include "pch.h"
#include "CppUnitTest.h"
#include "MarkovModel/src/model.h"
@@ -147,13 +150,18 @@  Test class for rest of model cases. More...
  -
+

Detailed Description

+

Unit tests with Microsoft::VisualStudio::CppUnitTestFramework.

+
Authors
Ata Hakçıl, Osman Ömer Yıldıztugay, Yunus Emre Yılmaz
+ +

Definition in file UnitTests.cpp.

+
-Go to the documentation of this file.
1 #include "pch.h"
-
2 #include "CppUnitTest.h"
-
3 #include "MarkovModel/src/model.h"
-
4 
-
5 using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+Go to the documentation of this file.
1 /** @file UnitTests.cpp
+
2  * @brief Unit tests with Microsoft::VisualStudio::CppUnitTestFramework
+
3  * @authors Ata Hakçıl, Osman Ömer Yıldıztugay, Yunus Emre Yılmaz
+
4  *
+
5  */
6 
-
7 
-
8 /** @brief Namespace for Microsoft Native Unit Testing Classes
-
9 */
-
10 namespace Testing {
-
11 
-
12  /** @brief Testing Namespace for Minimal Viable Product
-
13  */
-
14  namespace MVP {
-
15  /** @brief Testing Namespace for MVP MarkovModel
-
16  */
-
17  namespace MarkovModel
-
18  {
-
19  /** @brief Test class for minimal viable Edge
-
20  */
- -
22  {
-
23  public:
-
24 
-
25  /** @brief test default constructor
-
26  */
- -
28  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>;
-
29  Assert::IsNull(e->LeftNode());
-
30  Assert::IsNull(e->RightNode());
-
31  delete e;
-
32  }
-
33 
-
34  /** @brief test linked constructor with two nodes
-
35  */
- -
37  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
38  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
39  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
- - -
42  delete LeftNode;
-
43  delete RightNode;
-
44  delete e;
-
45  }
-
46 
-
47  /** @brief test AdjustEdge function
-
48  */
- -
50  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
51  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
52  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
-
53  e->AdjustEdge(15);
-
54  Assert::AreEqual(15ull, e->EdgeWeight());
-
55  e->AdjustEdge(15);
-
56  Assert::AreEqual(30ull, e->EdgeWeight());
-
57  delete LeftNode;
-
58  delete RightNode;
-
59  delete e;
-
60  }
-
61 
-
62  /** @brief test TraverseNode returning RightNode
-
63  */
- -
65  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
66  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
67  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
- -
69  delete LeftNode;
-
70  delete RightNode;
-
71  delete e;
-
72  }
-
73 
-
74  /** @brief test LeftNode/RightNode setter
-
75  */
- -
77  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
78  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
79  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(LeftNode, RightNode);
-
80 
-
81  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>;
- - -
84 
-
85  Assert::IsTrue(e1->LeftNode() == e2->LeftNode());
-
86  Assert::IsTrue(e1->RightNode() == e2->RightNode());
-
87  delete LeftNode;
-
88  delete RightNode;
-
89  delete e1;
-
90  delete e2;
-
91  }
-
92 
-
93  /** @brief test negative adjustments
-
94  */
- -
96  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
97  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
98  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
-
99  e->AdjustEdge(15);
-
100  Assert::AreEqual(15ull, e->EdgeWeight());
-
101  e->AdjustEdge(-15);
-
102  Assert::AreEqual(0ull, e->EdgeWeight());
-
103  delete LeftNode;
-
104  delete RightNode;
-
105  delete e;
-
106  }
-
107  };
-
108 
-
109  /** @brief Test class for minimal viable Node
-
110  */
- -
112  {
-
113  public:
+
7 #include "pch.h"
+
8 #include "CppUnitTest.h"
+
9 #include "MarkovModel/src/model.h"
+
10 
+
11 using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
12 
+
13 
+
14 /** @brief Namespace for Microsoft Native Unit Testing Classes
+
15 */
+
16 namespace Testing {
+
17 
+
18  /** @brief Testing Namespace for Minimal Viable Product
+
19  */
+
20  namespace MVP {
+
21  /** @brief Testing Namespace for MVP MarkovModel
+
22  */
+
23  namespace MarkovModel
+
24  {
+
25  /** @brief Test class for minimal viable Edge
+
26  */
+ +
28  {
+
29  public:
+
30 
+
31  /** @brief test default constructor
+
32  */
+ +
34  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>;
+
35  Assert::IsNull(e->LeftNode());
+
36  Assert::IsNull(e->RightNode());
+
37  delete e;
+
38  }
+
39 
+
40  /** @brief test linked constructor with two nodes
+
41  */
+ +
43  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
44  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
45  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+ + +
48  delete LeftNode;
+
49  delete RightNode;
+
50  delete e;
+
51  }
+
52 
+
53  /** @brief test AdjustEdge function
+
54  */
+ +
56  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
57  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
58  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
59  e->AdjustEdge(15);
+
60  Assert::AreEqual(15ull, e->EdgeWeight());
+
61  e->AdjustEdge(15);
+
62  Assert::AreEqual(30ull, e->EdgeWeight());
+
63  delete LeftNode;
+
64  delete RightNode;
+
65  delete e;
+
66  }
+
67 
+
68  /** @brief test TraverseNode returning RightNode
+
69  */
+ +
71  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
72  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
73  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+ +
75  delete LeftNode;
+
76  delete RightNode;
+
77  delete e;
+
78  }
+
79 
+
80  /** @brief test LeftNode/RightNode setter
+
81  */
+ +
83  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
84  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
85  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
86 
+
87  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>;
+ + +
90 
+
91  Assert::IsTrue(e1->LeftNode() == e2->LeftNode());
+
92  Assert::IsTrue(e1->RightNode() == e2->RightNode());
+
93  delete LeftNode;
+
94  delete RightNode;
+
95  delete e1;
+
96  delete e2;
+
97  }
+
98 
+
99  /** @brief test negative adjustments
+
100  */
+ +
102  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
103  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
104  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
105  e->AdjustEdge(15);
+
106  Assert::AreEqual(15ull, e->EdgeWeight());
+
107  e->AdjustEdge(-15);
+
108  Assert::AreEqual(0ull, e->EdgeWeight());
+
109  delete LeftNode;
+
110  delete RightNode;
+
111  delete e;
+
112  }
+
113  };
114 
-
115  /** @brief test default constructor
-
116  */
- -
118  Markov::Node<unsigned char>* n = new Markov::Node<unsigned char>();
-
119  Assert::AreEqual((unsigned char)0, n->NodeValue());
-
120  delete n;
-
121  }
-
122 
-
123  /** @brief test custom constructor with unsigned char
-
124  */
- -
126  Markov::Node<unsigned char>* n = NULL;
-
127  unsigned char test_cases[] = { 'c', 0x00, 0xff, -32 };
-
128  for (unsigned char tcase : test_cases) {
-
129  n = new Markov::Node<unsigned char>(tcase);
- -
131  delete n;
-
132  }
-
133  }
-
134 
-
135  /** @brief test link function
-
136  */
- -
138  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
139  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
115  /** @brief Test class for minimal viable Node
+
116  */
+ +
118  {
+
119  public:
+
120 
+
121  /** @brief test default constructor
+
122  */
+ +
124  Markov::Node<unsigned char>* n = new Markov::Node<unsigned char>();
+
125  Assert::AreEqual((unsigned char)0, n->NodeValue());
+
126  delete n;
+
127  }
+
128 
+
129  /** @brief test custom constructor with unsigned char
+
130  */
+ +
132  Markov::Node<unsigned char>* n = NULL;
+
133  unsigned char test_cases[] = { 'c', 0x00, 0xff, -32 };
+
134  for (unsigned char tcase : test_cases) {
+
135  n = new Markov::Node<unsigned char>(tcase);
+ +
137  delete n;
+
138  }
+
139  }
140 
-
141  Markov::Edge<unsigned char>* e = LeftNode->Link(RightNode);
-
142  delete LeftNode;
-
143  delete RightNode;
-
144  delete e;
-
145  }
+
141  /** @brief test link function
+
142  */
+ +
144  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
145  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
146 
-
147  /** @brief test link function
-
148  */
- -
150  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
151  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
147  Markov::Edge<unsigned char>* e = LeftNode->Link(RightNode);
+
148  delete LeftNode;
+
149  delete RightNode;
+
150  delete e;
+
151  }
152 
-
153  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(NULL, RightNode);
-
154  LeftNode->Link(e);
-
155  Assert::IsTrue(LeftNode == e->LeftNode());
- -
157  delete LeftNode;
-
158  delete RightNode;
-
159  delete e;
-
160  }
-
161 
-
162  /** @brief test RandomNext with low values
-
163  */
- - -
166  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
167  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
168  Markov::Edge<unsigned char>* e = src->Link(target1);
-
169  e->AdjustEdge(15);
-
170  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
171  Assert::IsTrue(res == target1);
-
172  delete src;
-
173  delete target1;
-
174  delete e;
-
175 
-
176  }
-
177 
-
178  /** @brief test RandomNext with 32 bit high values
-
179  */
- - -
182  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
183  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
184  Markov::Edge<unsigned char>* e = src->Link(target1);
-
185  e->AdjustEdge(1 << 31);
-
186  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
187  Assert::IsTrue(res == target1);
-
188  delete src;
-
189  delete target1;
-
190  delete e;
-
191 
-
192  }
-
193 
-
194  /** @brief random next on a node with no follow-ups
-
195  */
- - -
198  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
199  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
200  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
-
201  Markov::Edge<unsigned char>* e1 = src->Link(target1);
-
202  Markov::Edge<unsigned char>* e2 = src->Link(target2);
-
203  e1->AdjustEdge(1);
-
204  e2->AdjustEdge((unsigned long)(1ull << 31));
-
205  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
206  Assert::IsNotNull(res);
-
207  Assert::IsTrue(res == target2);
-
208  delete src;
-
209  delete target1;
-
210  delete e1;
-
211  delete e2;
-
212  }
-
213 
-
214  /** @brief random next on a node with no follow-ups
-
215  */
- - -
218  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
219  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
220  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
-
221  Markov::Edge<unsigned char>* e1 = src->Link(target1);
-
222  Markov::Edge<unsigned char>* e2 = src->Link(target2);
-
223  e2->AdjustEdge(1);
-
224  e1->AdjustEdge((unsigned long)(1ull << 31));
-
225  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
226  Assert::IsNotNull(res);
-
227  Assert::IsTrue(res == target1);
-
228  delete src;
-
229  delete target1;
-
230  delete e1;
-
231  delete e2;
-
232  }
-
233 
-
234 
-
235  /** @brief test updateEdges
-
236  */
- -
238 
-
239  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
240  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
241  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
-
242  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
-
243  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target2);
-
244  e1->AdjustEdge(25);
-
245  src->UpdateEdges(e1);
-
246  e2->AdjustEdge(30);
-
247  src->UpdateEdges(e2);
-
248 
-
249  Assert::AreEqual((size_t)2, src->Edges()->size());
-
250 
-
251  delete src;
-
252  delete target1;
-
253  delete e1;
-
254  delete e2;
-
255 
-
256  }
-
257 
-
258  /** @brief test updateEdges
-
259  */
- +
153  /** @brief test link function
+
154  */
+ +
156  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
157  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
158 
+
159  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(NULL, RightNode);
+
160  LeftNode->Link(e);
+
161  Assert::IsTrue(LeftNode == e->LeftNode());
+ +
163  delete LeftNode;
+
164  delete RightNode;
+
165  delete e;
+
166  }
+
167 
+
168  /** @brief test RandomNext with low values
+
169  */
+ + +
172  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
173  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
174  Markov::Edge<unsigned char>* e = src->Link(target1);
+
175  e->AdjustEdge(15);
+
176  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
177  Assert::IsTrue(res == target1);
+
178  delete src;
+
179  delete target1;
+
180  delete e;
+
181 
+
182  }
+
183 
+
184  /** @brief test RandomNext with 32 bit high values
+
185  */
+ + +
188  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
189  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
190  Markov::Edge<unsigned char>* e = src->Link(target1);
+
191  e->AdjustEdge(1 << 31);
+
192  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
193  Assert::IsTrue(res == target1);
+
194  delete src;
+
195  delete target1;
+
196  delete e;
+
197 
+
198  }
+
199 
+
200  /** @brief random next on a node with no follow-ups
+
201  */
+ + +
204  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
205  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
206  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
207  Markov::Edge<unsigned char>* e1 = src->Link(target1);
+
208  Markov::Edge<unsigned char>* e2 = src->Link(target2);
+
209  e1->AdjustEdge(1);
+
210  e2->AdjustEdge((unsigned long)(1ull << 31));
+
211  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
212  Assert::IsNotNull(res);
+
213  Assert::IsTrue(res == target2);
+
214  delete src;
+
215  delete target1;
+
216  delete e1;
+
217  delete e2;
+
218  }
+
219 
+
220  /** @brief random next on a node with no follow-ups
+
221  */
+ + +
224  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
225  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
226  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
227  Markov::Edge<unsigned char>* e1 = src->Link(target1);
+
228  Markov::Edge<unsigned char>* e2 = src->Link(target2);
+
229  e2->AdjustEdge(1);
+
230  e1->AdjustEdge((unsigned long)(1ull << 31));
+
231  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
232  Assert::IsNotNull(res);
+
233  Assert::IsTrue(res == target1);
+
234  delete src;
+
235  delete target1;
+
236  delete e1;
+
237  delete e2;
+
238  }
+
239 
+
240 
+
241  /** @brief test updateEdges
+
242  */
+ +
244 
+
245  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
246  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
247  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
248  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
+
249  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target2);
+
250  e1->AdjustEdge(25);
+
251  src->UpdateEdges(e1);
+
252  e2->AdjustEdge(30);
+
253  src->UpdateEdges(e2);
+
254 
+
255  Assert::AreEqual((size_t)2, src->Edges()->size());
+
256 
+
257  delete src;
+
258  delete target1;
+
259  delete e1;
+
260  delete e2;
261 
-
262  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
263  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
264  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
-
265  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target1);
-
266  e1->AdjustEdge(25);
-
267  src->UpdateEdges(e1);
-
268  e2->AdjustEdge(30);
-
269  src->UpdateEdges(e2);
-
270 
-
271  //Assert::AreEqual(55ull, src->TotalEdgeWeights());
-
272 
-
273  delete src;
-
274  delete target1;
-
275  delete e1;
-
276  delete e2;
-
277  }
+
262  }
+
263 
+
264  /** @brief test updateEdges
+
265  */
+ +
267 
+
268  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
269  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
270  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
+
271  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target1);
+
272  e1->AdjustEdge(25);
+
273  src->UpdateEdges(e1);
+
274  e2->AdjustEdge(30);
+
275  src->UpdateEdges(e2);
+
276 
+
277  //Assert::AreEqual(55ull, src->TotalEdgeWeights());
278 
-
279 
-
280  /** @brief test FindVertice
-
281  */
- -
283 
-
284  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
285  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
286  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
-
287  Markov::Edge<unsigned char>* res = NULL;
-
288  src->Link(target1);
-
289  src->Link(target2);
-
290 
-
291 
-
292  res = src->FindEdge('b');
-
293  Assert::IsNotNull(res);
-
294  Assert::AreEqual((unsigned char)'b', res->TraverseNode()->NodeValue());
-
295  res = src->FindEdge('c');
-
296  Assert::IsNotNull(res);
-
297  Assert::AreEqual((unsigned char)'c', res->TraverseNode()->NodeValue());
-
298 
-
299  delete src;
-
300  delete target1;
-
301  delete target2;
-
302 
-
303 
-
304  }
-
305 
-
306 
-
307  /** @brief test FindVertice
-
308  */
- -
310 
-
311  auto _invalid_next = [] {
-
312  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
313  Markov::Edge<unsigned char>* res = NULL;
-
314 
-
315  res = src->FindEdge('b');
-
316  Assert::IsNull(res);
-
317 
-
318  delete src;
-
319  };
+
279  delete src;
+
280  delete target1;
+
281  delete e1;
+
282  delete e2;
+
283  }
+
284 
+
285 
+
286  /** @brief test FindVertice
+
287  */
+ +
289 
+
290  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
291  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
292  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
293  Markov::Edge<unsigned char>* res = NULL;
+
294  src->Link(target1);
+
295  src->Link(target2);
+
296 
+
297 
+
298  res = src->FindEdge('b');
+
299  Assert::IsNotNull(res);
+
300  Assert::AreEqual((unsigned char)'b', res->TraverseNode()->NodeValue());
+
301  res = src->FindEdge('c');
+
302  Assert::IsNotNull(res);
+
303  Assert::AreEqual((unsigned char)'c', res->TraverseNode()->NodeValue());
+
304 
+
305  delete src;
+
306  delete target1;
+
307  delete target2;
+
308 
+
309 
+
310  }
+
311 
+
312 
+
313  /** @brief test FindVertice
+
314  */
+ +
316 
+
317  auto _invalid_next = [] {
+
318  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
319  Markov::Edge<unsigned char>* res = NULL;
320 
-
321  //Assert::ExpectException<std::logic_error>(_invalid_next);
-
322  }
+
321  res = src->FindEdge('b');
+
322  Assert::IsNull(res);
323 
-
324  /** @brief test FindVertice
-
325  */
- -
327 
-
328  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
329  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
330  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
-
331  Markov::Edge<unsigned char>* res = NULL;
-
332  src->Link(target1);
-
333  src->Link(target2);
-
334 
-
335  res = src->FindEdge('D');
-
336  Assert::IsNull(res);
-
337 
-
338  delete src;
-
339  delete target1;
-
340  delete target2;
-
341 
-
342  }
-
343  };
-
344 
-
345  /** @brief Test class for minimal viable Model
-
346  */
- -
348  {
-
349  public:
-
350  /** @brief test model constructor for starter node
-
351  */
- -
353  Markov::Model<unsigned char> m;
-
354  Assert::AreEqual((unsigned char)'\0', m.StarterNode()->NodeValue());
-
355  }
-
356 
-
357  /** @brief test import
-
358  */
- -
360  Markov::Model<unsigned char> m;
-
361  Assert::IsTrue(m.Import("../MarkovPasswords/Models/2gram.mdl"));
-
362  }
-
363 
-
364  /** @brief test export
-
365  */
- -
367  Markov::Model<unsigned char> m;
-
368  Assert::IsTrue(m.Export("../MarkovPasswords/Models/testcase.mdl"));
-
369  }
-
370 
-
371  /** @brief test random walk
-
372  */
- -
374  unsigned char* res = new unsigned char[12 + 5];
- -
376  Markov::Model<unsigned char> m;
-
377  Assert::IsTrue(m.Import("../Models/finished2.mdl"));
- -
379  }
-
380  };
-
381  }
-
382 
-
383  /** @brief Testing namespace for MVP MarkovPasswords
-
384  */
-
385  namespace MarkovPasswords
-
386  {
-
387  /** @brief Test Class for Argparse class
-
388  */
- -
390  {
-
391  public:
-
392  /** @brief test basic generate
-
393  */
- -
395  int argc = 8;
-
396  char *argv[] = {"markov.exe", "generate", "-if", "model.mdl", "-of", "passwords.txt", "-n", "100"};
-
397 
-
398  /*ProgramOptions *p = Argparse::parse(argc, argv);
-
399  Assert::IsNotNull(p);
-
400 
-
401  Assert::AreEqual(p->bImport, true);
-
402  Assert::AreEqual(p->bExport, false);
-
403  Assert::AreEqual(p->importname, "model.mdl");
-
404  Assert::AreEqual(p->outputfilename, "passwords.txt");
-
405  Assert::AreEqual(p->generateN, 100); */
-
406 
-
407  }
-
408 
-
409  /** @brief test basic generate reordered params
-
410  */
- -
412  int argc = 8;
-
413  char *argv[] = { "markov.exe", "generate", "-n", "100", "-if", "model.mdl", "-of", "passwords.txt" };
+
324  delete src;
+
325  };
+
326 
+
327  //Assert::ExpectException<std::logic_error>(_invalid_next);
+
328  }
+
329 
+
330  /** @brief test FindVertice
+
331  */
+ +
333 
+
334  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
335  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
336  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
+
337  Markov::Edge<unsigned char>* res = NULL;
+
338  src->Link(target1);
+
339  src->Link(target2);
+
340 
+
341  res = src->FindEdge('D');
+
342  Assert::IsNull(res);
+
343 
+
344  delete src;
+
345  delete target1;
+
346  delete target2;
+
347 
+
348  }
+
349  };
+
350 
+
351  /** @brief Test class for minimal viable Model
+
352  */
+ +
354  {
+
355  public:
+
356  /** @brief test model constructor for starter node
+
357  */
+ +
359  Markov::Model<unsigned char> m;
+
360  Assert::AreEqual((unsigned char)'\0', m.StarterNode()->NodeValue());
+
361  }
+
362 
+
363  /** @brief test import
+
364  */
+ +
366  Markov::Model<unsigned char> m;
+
367  Assert::IsTrue(m.Import("../MarkovPasswords/Models/2gram.mdl"));
+
368  }
+
369 
+
370  /** @brief test export
+
371  */
+ +
373  Markov::Model<unsigned char> m;
+
374  Assert::IsTrue(m.Export("../MarkovPasswords/Models/testcase.mdl"));
+
375  }
+
376 
+
377  /** @brief test random walk
+
378  */
+ +
380  unsigned char* res = new unsigned char[12 + 5];
+ +
382  Markov::Model<unsigned char> m;
+
383  Assert::IsTrue(m.Import("../Models/finished2.mdl"));
+ +
385  }
+
386  };
+
387  }
+
388 
+
389  /** @brief Testing namespace for MVP MarkovPasswords
+
390  */
+
391  namespace MarkovPasswords
+
392  {
+
393  /** @brief Test Class for Argparse class
+
394  */
+ +
396  {
+
397  public:
+
398  /** @brief test basic generate
+
399  */
+ +
401  int argc = 8;
+
402  char *argv[] = {"markov.exe", "generate", "-if", "model.mdl", "-of", "passwords.txt", "-n", "100"};
+
403 
+
404  /*ProgramOptions *p = Argparse::parse(argc, argv);
+
405  Assert::IsNotNull(p);
+
406 
+
407  Assert::AreEqual(p->bImport, true);
+
408  Assert::AreEqual(p->bExport, false);
+
409  Assert::AreEqual(p->importname, "model.mdl");
+
410  Assert::AreEqual(p->outputfilename, "passwords.txt");
+
411  Assert::AreEqual(p->generateN, 100); */
+
412 
+
413  }
414 
-
415  /*ProgramOptions* p = Argparse::parse(argc, argv);
-
416  Assert::IsNotNull(p);
-
417 
-
418  Assert::AreEqual(p->bImport, true);
-
419  Assert::AreEqual(p->bExport, false);
-
420  Assert::AreEqual(p->importname, "model.mdl");
-
421  Assert::AreEqual(p->outputfilename, "passwords.txt");
-
422  Assert::AreEqual(p->generateN, 100);*/
-
423  }
-
424 
-
425  /** @brief test basic generate param longnames
-
426  */
- -
428  int argc = 8;
-
429  char *argv[] = { "markov.exe", "generate", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
+
415  /** @brief test basic generate reordered params
+
416  */
+ +
418  int argc = 8;
+
419  char *argv[] = { "markov.exe", "generate", "-n", "100", "-if", "model.mdl", "-of", "passwords.txt" };
+
420 
+
421  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
422  Assert::IsNotNull(p);
+
423 
+
424  Assert::AreEqual(p->bImport, true);
+
425  Assert::AreEqual(p->bExport, false);
+
426  Assert::AreEqual(p->importname, "model.mdl");
+
427  Assert::AreEqual(p->outputfilename, "passwords.txt");
+
428  Assert::AreEqual(p->generateN, 100);*/
+
429  }
430 
-
431  /*ProgramOptions* p = Argparse::parse(argc, argv);
-
432  Assert::IsNotNull(p);
-
433 
-
434  Assert::AreEqual(p->bImport, true);
-
435  Assert::AreEqual(p->bExport, false);
-
436  Assert::AreEqual(p->importname, "model.mdl");
-
437  Assert::AreEqual(p->outputfilename, "passwords.txt");
-
438  Assert::AreEqual(p->generateN, 100); */
-
439  }
-
440 
-
441  /** @brief test basic generate
-
442  */
- -
444  int argc = 8;
-
445  char *argv[] = { "markov.exe", "junk", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
+
431  /** @brief test basic generate param longnames
+
432  */
+ +
434  int argc = 8;
+
435  char *argv[] = { "markov.exe", "generate", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
+
436 
+
437  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
438  Assert::IsNotNull(p);
+
439 
+
440  Assert::AreEqual(p->bImport, true);
+
441  Assert::AreEqual(p->bExport, false);
+
442  Assert::AreEqual(p->importname, "model.mdl");
+
443  Assert::AreEqual(p->outputfilename, "passwords.txt");
+
444  Assert::AreEqual(p->generateN, 100); */
+
445  }
446 
-
447  /*ProgramOptions* p = Argparse::parse(argc, argv);
-
448  Assert::IsNull(p); */
-
449  }
-
450 
-
451  /** @brief test basic train
-
452  */
- -
454  int argc = 4;
-
455  char *argv[] = { "markov.exe", "train", "-ef", "model.mdl" };
+
447  /** @brief test basic generate
+
448  */
+ +
450  int argc = 8;
+
451  char *argv[] = { "markov.exe", "junk", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
+
452 
+
453  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
454  Assert::IsNull(p); */
+
455  }
456 
-
457  /*ProgramOptions* p = Argparse::parse(argc, argv);
-
458  Assert::IsNotNull(p);
-
459 
-
460  Assert::AreEqual(p->bImport, false);
-
461  Assert::AreEqual(p->bExport, true);
-
462  Assert::AreEqual(p->exportname, "model.mdl"); */
-
463 
-
464  }
-
465 
-
466  /** @brief test basic generate
-
467  */
- -
469  int argc = 4;
-
470  char *argv[] = { "markov.exe", "train", "--exportfilename", "model.mdl" };
+
457  /** @brief test basic train
+
458  */
+ +
460  int argc = 4;
+
461  char *argv[] = { "markov.exe", "train", "-ef", "model.mdl" };
+
462 
+
463  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
464  Assert::IsNotNull(p);
+
465 
+
466  Assert::AreEqual(p->bImport, false);
+
467  Assert::AreEqual(p->bExport, true);
+
468  Assert::AreEqual(p->exportname, "model.mdl"); */
+
469 
+
470  }
471 
-
472  /*ProgramOptions* p = Argparse::parse(argc, argv);
-
473  Assert::IsNotNull(p);
-
474 
-
475  Assert::AreEqual(p->bImport, false);
-
476  Assert::AreEqual(p->bExport, true);
-
477  Assert::AreEqual(p->exportname, "model.mdl"); */
-
478  }
-
479 
-
480 
-
481 
-
482  };
-
483 
-
484  }
-
485  }
+
472  /** @brief test basic generate
+
473  */
+ +
475  int argc = 4;
+
476  char *argv[] = { "markov.exe", "train", "--exportfilename", "model.mdl" };
+
477 
+
478  /*ProgramOptions* p = Argparse::parse(argc, argv);
+
479  Assert::IsNotNull(p);
+
480 
+
481  Assert::AreEqual(p->bImport, false);
+
482  Assert::AreEqual(p->bExport, true);
+
483  Assert::AreEqual(p->exportname, "model.mdl"); */
+
484  }
+
485 
486 
487 
-
488  /** @brief Testing namespace for MarkovModel
-
489  */
-
490  namespace MarkovModel {
-
491 
-
492  /** @brief Test class for rest of Edge cases
-
493  */
- -
495  {
-
496  public:
-
497  /** @brief send exception on integer underflow
-
498  */
- -
500  auto _underflow_adjust = [] {
-
501  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
502  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
503  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
-
504  e->AdjustEdge(15);
-
505  e->AdjustEdge(-30);
-
506  delete LeftNode;
-
507  delete RightNode;
-
508  delete e;
-
509  };
- -
511  }
-
512 
-
513  /** @brief test integer overflows
-
514  */
- -
516  auto _overflow_adjust = [] {
-
517  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
-
518  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
-
519  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
-
520  e->AdjustEdge(~0ull);
-
521  e->AdjustEdge(1);
-
522  delete LeftNode;
-
523  delete RightNode;
-
524  delete e;
-
525  };
- -
527  }
-
528  };
-
529 
-
530  /** @brief Test class for rest of Node cases
-
531  */
- -
533  {
-
534  public:
+
488  };
+
489 
+
490  }
+
491  }
+
492 
+
493 
+
494  /** @brief Testing namespace for MarkovModel
+
495  */
+
496  namespace MarkovModel {
+
497 
+
498  /** @brief Test class for rest of Edge cases
+
499  */
+ +
501  {
+
502  public:
+
503  /** @brief send exception on integer underflow
+
504  */
+ +
506  auto _underflow_adjust = [] {
+
507  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
508  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
509  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
510  e->AdjustEdge(15);
+
511  e->AdjustEdge(-30);
+
512  delete LeftNode;
+
513  delete RightNode;
+
514  delete e;
+
515  };
+ +
517  }
+
518 
+
519  /** @brief test integer overflows
+
520  */
+ +
522  auto _overflow_adjust = [] {
+
523  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
+
524  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
+
525  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
+
526  e->AdjustEdge(~0ull);
+
527  e->AdjustEdge(1);
+
528  delete LeftNode;
+
529  delete RightNode;
+
530  delete e;
+
531  };
+ +
533  }
+
534  };
535 
-
536  /** @brief test RandomNext with 64 bit high values
-
537  */
- - -
540  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
541  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
542  Markov::Edge<unsigned char>* e = src->Link(target1);
-
543  e->AdjustEdge((unsigned long)(1ull << 63));
-
544  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
545  Assert::IsTrue(res == target1);
-
546  delete src;
-
547  delete target1;
-
548  delete e;
-
549 
-
550  }
-
551 
-
552  /** @brief test RandomNext with 64 bit high values
-
553  */
- - -
556  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
557  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
558  Markov::Edge<unsigned char>* e = src->Link(target1);
-
559  e->AdjustEdge((0xffffFFFF));
-
560  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
561  Assert::IsTrue(res == target1);
-
562  delete src;
-
563  delete target1;
-
564  delete e;
-
565 
-
566  }
-
567 
-
568  /** @brief randomNext when no edges are present
-
569  */
- +
536  /** @brief Test class for rest of Node cases
+
537  */
+ +
539  {
+
540  public:
+
541 
+
542  /** @brief test RandomNext with 64 bit high values
+
543  */
+ + +
546  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
547  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
548  Markov::Edge<unsigned char>* e = src->Link(target1);
+
549  e->AdjustEdge((unsigned long)(1ull << 63));
+
550  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
551  Assert::IsTrue(res == target1);
+
552  delete src;
+
553  delete target1;
+
554  delete e;
+
555 
+
556  }
+
557 
+
558  /** @brief test RandomNext with 64 bit high values
+
559  */
+ + +
562  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
563  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
564  Markov::Edge<unsigned char>* e = src->Link(target1);
+
565  e->AdjustEdge((0xffffFFFF));
+
566  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
567  Assert::IsTrue(res == target1);
+
568  delete src;
+
569  delete target1;
+
570  delete e;
571 
-
572  auto _invalid_next = [] {
- -
574  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
-
575  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
-
576  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(src, target1);
-
577  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
-
578 
-
579  delete src;
-
580  delete target1;
-
581  delete e;
-
582  };
-
583 
- -
585  }
-
586 
-
587 
-
588  };
+
572  }
+
573 
+
574  /** @brief randomNext when no edges are present
+
575  */
+ +
577 
+
578  auto _invalid_next = [] {
+ +
580  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
+
581  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
+
582  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(src, target1);
+
583  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
+
584 
+
585  delete src;
+
586  delete target1;
+
587  delete e;
+
588  };
589 
-
590  /** @brief Test class for rest of model cases
-
591  */
- -
593  {
-
594  public:
- -
596  unsigned char* res2 = new unsigned char[12 + 5];
- -
598  Markov::Model<unsigned char> m;
-
599  Markov::Node<unsigned char>* starter = m.StarterNode();
-
600  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
-
601  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
-
602  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
-
603  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
-
604  starter->Link(a)->AdjustEdge(1);
-
605  a->Link(b)->AdjustEdge(1);
-
606  b->Link(c)->AdjustEdge(1);
-
607  c->Link(end)->AdjustEdge(1);
-
608 
-
609  char* res = (char*)m.RandomWalk(&MarsagliaRandomEngine,1,12,res2);
-
610  Assert::IsFalse(strcmp(res, "abc"));
-
611  }
- -
613  Markov::Model<unsigned char> m;
-
614  Markov::Node<unsigned char>* starter = m.StarterNode();
-
615  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
-
616  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
-
617  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
-
618  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
-
619  Markov::Edge<unsigned char>* res = NULL;
-
620  starter->Link(a)->AdjustEdge(1);
-
621  a->Link(b)->AdjustEdge(1);
-
622  b->Link(c)->AdjustEdge(1);
-
623  c->Link(end)->AdjustEdge(1);
-
624 
-
625  res = starter->FindEdge('D');
-
626  Assert::IsNull(res);
-
627 
-
628  }
-
629  };
+ +
591  }
+
592 
+
593 
+
594  };
+
595 
+
596  /** @brief Test class for rest of model cases
+
597  */
+ +
599  {
+
600  public:
+ +
602  unsigned char* res2 = new unsigned char[12 + 5];
+ +
604  Markov::Model<unsigned char> m;
+
605  Markov::Node<unsigned char>* starter = m.StarterNode();
+
606  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
+
607  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
+
608  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
+
609  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
+
610  starter->Link(a)->AdjustEdge(1);
+
611  a->Link(b)->AdjustEdge(1);
+
612  b->Link(c)->AdjustEdge(1);
+
613  c->Link(end)->AdjustEdge(1);
+
614 
+
615  char* res = (char*)m.RandomWalk(&MarsagliaRandomEngine,1,12,res2);
+
616  Assert::IsFalse(strcmp(res, "abc"));
+
617  }
+ +
619  Markov::Model<unsigned char> m;
+
620  Markov::Node<unsigned char>* starter = m.StarterNode();
+
621  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
+
622  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
+
623  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
+
624  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
+
625  Markov::Edge<unsigned char>* res = NULL;
+
626  starter->Link(a)->AdjustEdge(1);
+
627  a->Link(b)->AdjustEdge(1);
+
628  b->Link(c)->AdjustEdge(1);
+
629  c->Link(end)->AdjustEdge(1);
630 
-
631  }
-
632 
-
633  /** @brief Testing namespace for MarkovPasswords
-
634  */
-
635  namespace MarkovPasswords {
+
631  res = starter->FindEdge('D');
+
632  Assert::IsNull(res);
+
633 
+
634  }
+
635  };
636 
-
637  };
+
637  }
638 
-
639 }
+
639  /** @brief Testing namespace for MarkovPasswords
+
640  */
+
641  namespace MarkovPasswords {
+
642 
+
643  };
+
644 
+
645 }
-
TEST_CLASS(ArgParser)
Test Class for Argparse class.
Definition: UnitTests.cpp:389
-
Testing namespace for MarkovPasswords.
Definition: UnitTests.cpp:635
-
Testing Namespace for Minimal Viable Product.
Definition: UnitTests.cpp:14
-
Namespace for Microsoft Native Unit Testing Classes.
Definition: UnitTests.cpp:10
-
TEST_CLASS(Model)
Test class for rest of model cases.
Definition: UnitTests.cpp:592
-
TEST_CLASS(Model)
Test class for minimal viable Model.
Definition: UnitTests.cpp:347
+
TEST_CLASS(ArgParser)
Test Class for Argparse class.
Definition: UnitTests.cpp:395
+
Testing namespace for MarkovPasswords.
Definition: UnitTests.cpp:641
+
Testing Namespace for Minimal Viable Product.
Definition: UnitTests.cpp:20
+
Namespace for Microsoft Native Unit Testing Classes.
Definition: UnitTests.cpp:16
+
TEST_CLASS(Model)
Test class for rest of model cases.
Definition: UnitTests.cpp:598
+
TEST_CLASS(Model)
Test class for minimal viable Model.
Definition: UnitTests.cpp:353
+ +

About page. +More...

#include <QtWidgets/QMainWindow>
#include "ui_about.h"
#include <ui_menu.h>
@@ -99,6 +102,12 @@
+
+This graph shows which files directly or indirectly include this file:
+
+
+
+

Go to the source code of this file.

@@ -117,13 +126,18 @@
 namespace for MarkovPasswords API GUI wrapper
 
- +

Detailed Description

+

About page.

+
Authors
Yunus Emre Yılmaz
+ +

Definition in file about.h.

+
-Go to the documentation of this file.
1 #pragma once
-
2 #include <QtWidgets/QMainWindow>
-
3 #include "ui_about.h"
-
4 #include <ui_menu.h>
-
5 
-
6 /** @brief namespace for MarkovPasswords API GUI wrapper
-
7 */
-
8 namespace Markov::GUI{
-
9 
-
10  /** @brief QT Class for about page
-
11  */
-
12  class about :public QMainWindow {
-
13  Q_OBJECT
-
14  public:
- -
16 
-
17  private:
-
18  Ui:: main ui;
-
19 
-
20 
-
21  };
-
22 };
+Go to the documentation of this file.
1 /** @file about.h
+
2  * @brief About page
+
3  * @authors Yunus Emre Yılmaz
+
4  *
+
5  */
+
6 
+
7 #pragma once
+
8 #include <QtWidgets/QMainWindow>
+
9 #include "ui_about.h"
+
10 #include <ui_menu.h>
+
11 
+
12 /** @brief namespace for MarkovPasswords API GUI wrapper
+
13 */
+
14 namespace Markov::GUI{
+
15 
+
16  /** @brief QT Class for about page
+
17  */
+
18  class about :public QMainWindow {
+
19  Q_OBJECT
+
20  public:
+
21  about(QWidget* parent = Q_NULLPTR);
+
22 
+
23  private:
+
24  Ui:: main ui;
+
25 
+
26 
+
27  };
+
28 };
-
namespace for MarkovPasswords API GUI wrapper
Definition: menu.h:6
-
about(QWidget *parent=Q_NULLPTR)
-
Ui::main ui
Definition: about.h:18
+
QT Class for about page.
Definition: about.h:18
+
namespace for MarkovPasswords API GUI wrapper
Definition: about.h:14
+
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+
about(QWidget *parent=Q_NULLPTR)
Definition: about.cpp:14
+
Ui::main ui
Definition: about.h:24
@@ -127,7 +129,7 @@
+ +

Arguement handler class for native CPP cli. +More...

#include "argparse.h"
#include "color/term.h"
@@ -97,13 +100,19 @@

Go to the source code of this file.

-
+

Detailed Description

+

Arguement handler class for native CPP cli.

+
Authors
Celal Sahir Çetiner
+

Parse command line arguements.

+ +

Definition in file argparse.cpp.

+
-Go to the documentation of this file.
1 #include "argparse.h"
-
2 #include "color/term.h"
-
3 
-
4 Markov::API::CLI::ProgramOptions* Markov::API::CLI::Argparse::parse(int argc, char** argv) { return 0; }
-
5 
-
6 
+Go to the documentation of this file.
1 /** @file argparse.cpp
+
2  * @brief Arguement handler class for native CPP cli
+
3  * @authors Celal Sahir Çetiner
+
4  *
+
5  * @copydoc Markov::API::CLI::Argparse
+
6  */
7 
-
8 void Markov::API::CLI::Argparse::help() {
-
9  std::cout <<
-
10  "Markov Passwords - Help\n"
-
11  "Options:\n"
-
12  " \n"
-
13  " -of --outputfilename\n"
-
14  " Filename to output the generation results\n"
-
15  " -ef --exportfilename\n"
-
16  " filename to export built model to\n"
-
17  " -if --importfilename\n"
-
18  " filename to import model from\n"
-
19  " -n (generate count)\n"
-
20  " Number of lines to generate\n"
-
21  " \n"
-
22  "Usage: \n"
-
23  " markov.exe -if empty_model.mdl -ef model.mdl\n"
-
24  " import empty_model.mdl and train it with data from stdin. When done, output the model to model.mdl\n"
-
25  "\n"
-
26  " markov.exe -if empty_model.mdl -n 15000 -of wordlist.txt\n"
-
27  " import empty_model.mdl and generate 15000 words to wordlist.txt\n"
-
28 
-
29  << std::endl;
-
30 }
+
8 #include "argparse.h"
+
9 #include "color/term.h"
+
10 
+
11 Markov::API::CLI::ProgramOptions* Markov::API::CLI::Argparse::parse(int argc, char** argv) { return 0; }
+
12 
+
13 
+
14 
+
15 void Markov::API::CLI::Argparse::help() {
+
16  std::cout <<
+
17  "Markov Passwords - Help\n"
+
18  "Options:\n"
+
19  " \n"
+
20  " -of --outputfilename\n"
+
21  " Filename to output the generation results\n"
+
22  " -ef --exportfilename\n"
+
23  " filename to export built model to\n"
+
24  " -if --importfilename\n"
+
25  " filename to import model from\n"
+
26  " -n (generate count)\n"
+
27  " Number of lines to generate\n"
+
28  " \n"
+
29  "Usage: \n"
+
30  " markov.exe -if empty_model.mdl -ef model.mdl\n"
+
31  " import empty_model.mdl and train it with data from stdin. When done, output the model to model.mdl\n"
+
32  "\n"
+
33  " markov.exe -if empty_model.mdl -n 15000 -of wordlist.txt\n"
+
34  " import empty_model.mdl and generate 15000 words to wordlist.txt\n"
+
35 
+
36  << std::endl;
+
37 }
-
Parse command line arguements.
Definition: argparse.h:74
-
static void help()
Print help string.
Definition: argparse.cpp:8
-
static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
parse cli commands and return
Definition: argparse.cpp:4
-
Structure to hold parsed cli arguements.
Definition: argparse.h:15
+
Namespace for the MarkovPasswords API.
+
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+
Parse command line arguements.
Definition: argparse.h:82
+
static void help()
Print help string.
Definition: argparse.cpp:15
+
static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
parse cli commands and return
Definition: argparse.cpp:11
+
Structure to hold parsed cli arguements.
Definition: argparse.h:23
+ +

Arguement handler class for native CPP cli. +More...

#include <string>
#include <iostream>
#include <boost/program_options.hpp>
@@ -133,8 +136,10 @@ - - + + + +

Macros

#define BOOST_ALL_DYN_LINK   1
 
#define BOOST_ALL_STATIC_LIB   1
 
#define BOOST_PROGRAM_OPTIONS_STATIC_LIB   1
 
@@ -142,20 +147,41 @@

Typedefs

 Structure to hold parsed cli arguements. More...
 
-

Macro Definition Documentation

- -

◆ BOOST_ALL_DYN_LINK

+

Detailed Description

+

Arguement handler class for native CPP cli.

+
Authors
Celal Sahir Çetiner
+ +

Definition in file argparse.h.

+

Macro Definition Documentation

+ +

◆ BOOST_ALL_STATIC_LIB

+ +
+
+ + + + +
#define BOOST_ALL_STATIC_LIB   1
+
+ +

Definition at line 11 of file argparse.h.

+ +
+
+ +

◆ BOOST_PROGRAM_OPTIONS_STATIC_LIB

- +
#define BOOST_ALL_DYN_LINK   1#define BOOST_PROGRAM_OPTIONS_STATIC_LIB   1
-

Definition at line 4 of file argparse.h.

+

Definition at line 12 of file argparse.h.

@@ -164,8 +190,8 @@

diff --git a/docs/argparse_8h.js b/docs/argparse_8h.js index 5feaa3e9..421eee60 100644 --- a/docs/argparse_8h.js +++ b/docs/argparse_8h.js @@ -2,6 +2,7 @@ var argparse_8h = [ [ "_programOptions", "struct_markov_1_1_a_p_i_1_1_c_l_i_1_1__program_options.html", "struct_markov_1_1_a_p_i_1_1_c_l_i_1_1__program_options" ], [ "Argparse", "class_markov_1_1_a_p_i_1_1_c_l_i_1_1_argparse.html", "class_markov_1_1_a_p_i_1_1_c_l_i_1_1_argparse" ], - [ "BOOST_ALL_DYN_LINK", "argparse_8h.html#a8df2553ea80556a445530460433ac2f5", null ], + [ "BOOST_ALL_STATIC_LIB", "argparse_8h.html#aaf8a1a195131e697ef0e215c1ca4f7cb", null ], + [ "BOOST_PROGRAM_OPTIONS_STATIC_LIB", "argparse_8h.html#ab42d174f6325cddd11a7bf6cedf74ca7", null ], [ "ProgramOptions", "argparse_8h.html#acdf1c80e63d183095fe2956cc38bf042", null ] ]; \ No newline at end of file diff --git a/docs/argparse_8h__dep__incl.map b/docs/argparse_8h__dep__incl.map index d1846805..15718da3 100644 --- a/docs/argparse_8h__dep__incl.map +++ b/docs/argparse_8h__dep__incl.map @@ -1,5 +1,5 @@ - - - + + + diff --git a/docs/argparse_8h__dep__incl.md5 b/docs/argparse_8h__dep__incl.md5 index 9d0d957b..20baa86f 100644 --- a/docs/argparse_8h__dep__incl.md5 +++ b/docs/argparse_8h__dep__incl.md5 @@ -1 +1 @@ -793b33124273e6cdd4846bdaa1538e5e \ No newline at end of file +88caa1975e22e00cf0e86f88a235513f \ No newline at end of file diff --git a/docs/argparse_8h__dep__incl.svg b/docs/argparse_8h__dep__incl.svg index 717cddfb..47f40e37 100644 --- a/docs/argparse_8h__dep__incl.svg +++ b/docs/argparse_8h__dep__incl.svg @@ -11,7 +11,7 @@ Node1 - + argparse.h @@ -20,7 +20,7 @@ Node2 - + argparse.cpp @@ -35,7 +35,7 @@ Node3 - + main.cpp diff --git a/docs/argparse_8h__incl.map b/docs/argparse_8h__incl.map index a76b58f8..a547ffd8 100644 --- a/docs/argparse_8h__incl.map +++ b/docs/argparse_8h__incl.map @@ -1,5 +1,5 @@ - + diff --git a/docs/argparse_8h__incl.md5 b/docs/argparse_8h__incl.md5 index 2065cb27..8201fac0 100644 --- a/docs/argparse_8h__incl.md5 +++ b/docs/argparse_8h__incl.md5 @@ -1 +1 @@ -d0ed9af54c498004fdc482e6d2a8c754 \ No newline at end of file +6057c550842d8ba4ffcfbc6cf82b6fca \ No newline at end of file diff --git a/docs/argparse_8h__incl.svg b/docs/argparse_8h__incl.svg index 8045dd73..de867e18 100644 --- a/docs/argparse_8h__incl.svg +++ b/docs/argparse_8h__incl.svg @@ -11,7 +11,7 @@ Node1 - + argparse.h diff --git a/docs/argparse_8h_source.html b/docs/argparse_8h_source.html index 51407ead..fd274f56 100644 --- a/docs/argparse_8h_source.html +++ b/docs/argparse_8h_source.html @@ -17,7 +17,7 @@ - +
@@ -87,283 +87,293 @@
argparse.h

-Go to the documentation of this file.
1 #include<string>
-
2 #include<iostream>
-
3 
-
4 #define BOOST_ALL_DYN_LINK 1
-
5 
-
6 #include <boost/program_options.hpp>
+Go to the documentation of this file.
1 /** @file argparse.h
+
2  * @brief Arguement handler class for native CPP cli
+
3  * @authors Celal Sahir Çetiner
+
4  *
+
5  * @copydoc Markov::API::CLI::Argparse:
+
6  */
7 
-
8 /** @brief Structure to hold parsed cli arguements.
-
9 */
-
10 namespace opt = boost::program_options;
-
11 
-
12 /**
-
13  @brief Namespace for the CLI objects
-
14 */
-
15 namespace Markov::API::CLI{
-
16 
-
17  /** @brief Structure to hold parsed cli arguements. */
-
18  typedef struct _programOptions {
-
19  /**
-
20  @brief Import flag to validate import
-
21  */
-
22  bool bImport;
-
23 
-
24  /**
-
25  @brief Export flag to validate export
-
26  */
-
27  bool bExport;
-
28 
-
29  /**
-
30  @brief Failure flag to validate succesfull running
-
31  */
-
32  bool bFailure;
-
33 
-
34  /**
-
35  @brief Seperator character to use with training data. (character between occurence and value)"
-
36  */
-
37  char seperator;
-
38 
-
39  /**
-
40  @brief Import name of our model
-
41  */
-
42  std::string importname;
-
43 
-
44  /**
-
45  @brief Import name of our given wordlist
-
46  */
-
47  std::string exportname;
-
48 
-
49  /**
-
50  @brief Import name of our given wordlist
-
51  */
-
52  std::string wordlistname;
-
53 
-
54  /**
-
55  @brief Output name of our generated password list
-
56  */
-
57  std::string outputfilename;
-
58 
-
59  /**
-
60  @brief The name of the given dataset
-
61  */
-
62  std::string datasetname;
-
63 
-
64  /**
-
65  @brief Number of passwords to be generated
-
66  */
-
67  int generateN;
-
68 
-
69  } ProgramOptions;
-
70 
+
8 #include<string>
+
9 #include<iostream>
+
10 
+
11 #define BOOST_ALL_STATIC_LIB 1
+
12 #define BOOST_PROGRAM_OPTIONS_STATIC_LIB 1
+
13 
+
14 #include <boost/program_options.hpp>
+
15 
+
16 /** @brief Structure to hold parsed cli arguements.
+
17 */
+
18 namespace opt = boost::program_options;
+
19 
+
20 /**
+
21  @brief Namespace for the CLI objects
+
22 */
+
23 namespace Markov::API::CLI{
+
24 
+
25  /** @brief Structure to hold parsed cli arguements. */
+
26  typedef struct _programOptions {
+
27  /**
+
28  @brief Import flag to validate import
+
29  */
+
30  bool bImport;
+
31 
+
32  /**
+
33  @brief Export flag to validate export
+
34  */
+
35  bool bExport;
+
36 
+
37  /**
+
38  @brief Failure flag to validate succesfull running
+
39  */
+
40  bool bFailure;
+
41 
+
42  /**
+
43  @brief Seperator character to use with training data. (character between occurence and value)"
+
44  */
+
45  char seperator;
+
46 
+
47  /**
+
48  @brief Import name of our model
+
49  */
+
50  std::string importname;
+
51 
+
52  /**
+
53  @brief Import name of our given wordlist
+
54  */
+
55  std::string exportname;
+
56 
+
57  /**
+
58  @brief Import name of our given wordlist
+
59  */
+
60  std::string wordlistname;
+
61 
+
62  /**
+
63  @brief Output name of our generated password list
+
64  */
+
65  std::string outputfilename;
+
66 
+
67  /**
+
68  @brief The name of the given dataset
+
69  */
+
70  std::string datasetname;
71 
-
72  /** @brief Parse command line arguements
-
73  */
-
74  class Argparse {
-
75  public:
+
72  /**
+
73  @brief Number of passwords to be generated
+
74  */
+
75  int generateN;
76 
-
77  Argparse();
+
77  } ProgramOptions;
78 
-
79  /** @brief Parse command line arguements.
-
80  *
-
81  * Parses command line arguements to populate ProgramOptions structure.
-
82  *
-
83  * @param argc Number of command line arguements
-
84  * @param argv Array of command line parameters
-
85  */
-
86  Argparse(int argc, char** argv) {
-
87 
-
88  /*bool bImp;
-
89  bool bExp;
-
90  bool bFail;
-
91  char sprt;
-
92  std::string imports;
-
93  std::string exports;
-
94  std::string outputs;
-
95  std::string datasets;
-
96  int generateN;
-
97  */
-
98  opt::options_description desc("Options");
-
99 
-
100 
-
101  desc.add_options()
-
102  ("generate", "Generate strings with given parameters")
-
103  ("train", "Train model with given parameters")
-
104  ("combine", "Combine")
-
105  ("import", opt::value<std::string>(), "Import model file")
-
106  ("output", opt::value<std::string>(), "Output model file. This model will be exported when done. Will be ignored for generation mode")
-
107  ("dataset", opt::value<std::string>(), "Dataset file to read input from training. Will be ignored for generation mode")
-
108  ("seperator", opt::value<char>(), "Seperator character to use with training data. (character between occurence and value)")
-
109  ("wordlist", opt::value<std::string>(), "Wordlist file path to export generation results to. Will be ignored for training mode")
-
110  ("count", opt::value<int>(), "Number of lines to generate. Ignored in training mode")
-
111  ("verbosity", "Output verbosity")
-
112  ("help", "Option definitions");
-
113 
-
114  opt::variables_map vm;
-
115 
-
116  opt::store(opt::parse_command_line(argc, argv, desc), vm);
-
117 
-
118  opt::notify(vm);
-
119 
-
120  //std::cout << desc << std::endl;
-
121  if (vm.count("help")) {
-
122  std::cout << desc << std::endl;
-
123  }
-
124 
-
125  if (vm.count("output") == 0) this->po.outputfilename = "NULL";
-
126  else if (vm.count("output") == 1) {
-
127  this->po.outputfilename = vm["output"].as<std::string>();
-
128  this->po.bExport = true;
-
129  }
-
130  else {
-
131  this->po.bFailure = true;
-
132  std::cout << "UNIDENTIFIED INPUT" << std::endl;
-
133  std::cout << desc << std::endl;
-
134  }
-
135 
-
136 
-
137  if (vm.count("dataset") == 0) this->po.datasetname = "NULL";
-
138  else if (vm.count("dataset") == 1) {
-
139  this->po.datasetname = vm["dataset"].as<std::string>();
-
140  }
-
141  else {
-
142  this->po.bFailure = true;
-
143  std::cout << "UNIDENTIFIED INPUT" << std::endl;
-
144  std::cout << desc << std::endl;
-
145  }
-
146 
-
147 
-
148  if (vm.count("wordlist") == 0) this->po.wordlistname = "NULL";
-
149  else if (vm.count("wordlist") == 1) {
-
150  this->po.wordlistname = vm["wordlist"].as<std::string>();
-
151  }
-
152  else {
-
153  this->po.bFailure = true;
-
154  std::cout << "UNIDENTIFIED INPUT" << std::endl;
-
155  std::cout << desc << std::endl;
-
156  }
-
157 
-
158  if (vm.count("import") == 0) this->po.importname = "NULL";
-
159  else if (vm.count("import") == 1) {
-
160  this->po.importname = vm["import"].as<std::string>();
-
161  this->po.bImport = true;
-
162  }
-
163  else {
-
164  this->po.bFailure = true;
-
165  std::cout << "UNIDENTIFIED INPUT" << std::endl;
-
166  std::cout << desc << std::endl;
-
167  }
-
168 
-
169 
-
170  if (vm.count("count") == 0) this->po.generateN = 0;
-
171  else if (vm.count("count") == 1) {
-
172  this->po.generateN = vm["count"].as<int>();
-
173  }
-
174  else {
-
175  this->po.bFailure = true;
-
176  std::cout << "UNIDENTIFIED INPUT" << std::endl;
-
177  std::cout << desc << std::endl;
-
178  }
-
179 
-
180  /*std::cout << vm["output"].as<std::string>() << std::endl;
-
181  std::cout << vm["dataset"].as<std::string>() << std::endl;
-
182  std::cout << vm["wordlist"].as<std::string>() << std::endl;
-
183  std::cout << vm["output"].as<std::string>() << std::endl;
-
184  std::cout << vm["count"].as<int>() << std::endl;*/
-
185 
-
186 
-
187  //else if (vm.count("train")) std::cout << "train oldu" << std::endl;
-
188  }
-
189 
-
190  /** @brief Getter for command line options
-
191  *
-
192  * Getter for ProgramOptions populated by the arguement parser
-
193  * @returns ProgramOptions structure.
-
194  */
-
195  Markov::API::CLI::ProgramOptions getProgramOptions(void) {
-
196  return this->po;
-
197  }
-
198 
-
199  /** @brief Initialize program options structure.
-
200  *
-
201  * @param i boolean, true if import operation is flagged
-
202  * @param e boolean, true if export operation is flagged
-
203  * @param bf boolean, true if there is something wrong with the command line parameters
-
204  * @param s seperator character for the import function
-
205  * @param iName import filename
-
206  * @param exName export filename
-
207  * @param oName output filename
-
208  * @param dName corpus filename
-
209  * @param n number of passwords to be generated
-
210  *
-
211  */
-
212  void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n) {
-
213  this->po.bImport = i;
-
214  this->po.bExport = e;
-
215  this->po.seperator = s;
-
216  this->po.bFailure = bf;
-
217  this->po.generateN = n;
-
218  this->po.importname = iName;
-
219  this->po.exportname = exName;
-
220  this->po.outputfilename = oName;
-
221  this->po.datasetname = dName;
-
222 
-
223  /*strcpy_s(this->po.importname,256,iName);
-
224  strcpy_s(this->po.exportname,256,exName);
-
225  strcpy_s(this->po.outputfilename,256,oName);
-
226  strcpy_s(this->po.datasetname,256,dName);*/
-
227 
-
228  }
-
229 
-
230  /** @brief parse cli commands and return
-
231  * @param argc - Program arguement count
-
232  * @param argv - Program arguement values array
-
233  * @return ProgramOptions structure.
-
234  */
-
235  static Markov::API::CLI::ProgramOptions* parse(int argc, char** argv);
-
236 
+
79 
+
80  /** @brief Parse command line arguements
+
81  */
+
82  class Argparse {
+
83  public:
+
84 
+
85  Argparse();
+
86 
+
87  /** @brief Parse command line arguements.
+
88  *
+
89  * Parses command line arguements to populate ProgramOptions structure.
+
90  *
+
91  * @param argc Number of command line arguements
+
92  * @param argv Array of command line parameters
+
93  */
+
94  Argparse(int argc, char** argv) {
+
95 
+
96  /*bool bImp;
+
97  bool bExp;
+
98  bool bFail;
+
99  char sprt;
+
100  std::string imports;
+
101  std::string exports;
+
102  std::string outputs;
+
103  std::string datasets;
+
104  int generateN;
+
105  */
+
106  opt::options_description desc("Options");
+
107 
+
108 
+
109  desc.add_options()
+
110  ("generate", "Generate strings with given parameters")
+
111  ("train", "Train model with given parameters")
+
112  ("combine", "Combine")
+
113  ("import", opt::value<std::string>(), "Import model file")
+
114  ("output", opt::value<std::string>(), "Output model file. This model will be exported when done. Will be ignored for generation mode")
+
115  ("dataset", opt::value<std::string>(), "Dataset file to read input from training. Will be ignored for generation mode")
+
116  ("seperator", opt::value<char>(), "Seperator character to use with training data. (character between occurence and value)")
+
117  ("wordlist", opt::value<std::string>(), "Wordlist file path to export generation results to. Will be ignored for training mode")
+
118  ("count", opt::value<int>(), "Number of lines to generate. Ignored in training mode")
+
119  ("verbosity", "Output verbosity")
+
120  ("help", "Option definitions");
+
121 
+
122  opt::variables_map vm;
+
123 
+
124  opt::store(opt::parse_command_line(argc, argv, desc), vm);
+
125 
+
126  opt::notify(vm);
+
127 
+
128  //std::cout << desc << std::endl;
+
129  if (vm.count("help")) {
+
130  std::cout << desc << std::endl;
+
131  }
+
132 
+
133  if (vm.count("output") == 0) this->po.outputfilename = "NULL";
+
134  else if (vm.count("output") == 1) {
+
135  this->po.outputfilename = vm["output"].as<std::string>();
+
136  this->po.bExport = true;
+
137  }
+
138  else {
+
139  this->po.bFailure = true;
+
140  std::cout << "UNIDENTIFIED INPUT" << std::endl;
+
141  std::cout << desc << std::endl;
+
142  }
+
143 
+
144 
+
145  if (vm.count("dataset") == 0) this->po.datasetname = "NULL";
+
146  else if (vm.count("dataset") == 1) {
+
147  this->po.datasetname = vm["dataset"].as<std::string>();
+
148  }
+
149  else {
+
150  this->po.bFailure = true;
+
151  std::cout << "UNIDENTIFIED INPUT" << std::endl;
+
152  std::cout << desc << std::endl;
+
153  }
+
154 
+
155 
+
156  if (vm.count("wordlist") == 0) this->po.wordlistname = "NULL";
+
157  else if (vm.count("wordlist") == 1) {
+
158  this->po.wordlistname = vm["wordlist"].as<std::string>();
+
159  }
+
160  else {
+
161  this->po.bFailure = true;
+
162  std::cout << "UNIDENTIFIED INPUT" << std::endl;
+
163  std::cout << desc << std::endl;
+
164  }
+
165 
+
166  if (vm.count("import") == 0) this->po.importname = "NULL";
+
167  else if (vm.count("import") == 1) {
+
168  this->po.importname = vm["import"].as<std::string>();
+
169  this->po.bImport = true;
+
170  }
+
171  else {
+
172  this->po.bFailure = true;
+
173  std::cout << "UNIDENTIFIED INPUT" << std::endl;
+
174  std::cout << desc << std::endl;
+
175  }
+
176 
+
177 
+
178  if (vm.count("count") == 0) this->po.generateN = 0;
+
179  else if (vm.count("count") == 1) {
+
180  this->po.generateN = vm["count"].as<int>();
+
181  }
+
182  else {
+
183  this->po.bFailure = true;
+
184  std::cout << "UNIDENTIFIED INPUT" << std::endl;
+
185  std::cout << desc << std::endl;
+
186  }
+
187 
+
188  /*std::cout << vm["output"].as<std::string>() << std::endl;
+
189  std::cout << vm["dataset"].as<std::string>() << std::endl;
+
190  std::cout << vm["wordlist"].as<std::string>() << std::endl;
+
191  std::cout << vm["output"].as<std::string>() << std::endl;
+
192  std::cout << vm["count"].as<int>() << std::endl;*/
+
193 
+
194 
+
195  //else if (vm.count("train")) std::cout << "train oldu" << std::endl;
+
196  }
+
197 
+
198  /** @brief Getter for command line options
+
199  *
+
200  * Getter for ProgramOptions populated by the arguement parser
+
201  * @returns ProgramOptions structure.
+
202  */
+
203  Markov::API::CLI::ProgramOptions getProgramOptions(void) {
+
204  return this->po;
+
205  }
+
206 
+
207  /** @brief Initialize program options structure.
+
208  *
+
209  * @param i boolean, true if import operation is flagged
+
210  * @param e boolean, true if export operation is flagged
+
211  * @param bf boolean, true if there is something wrong with the command line parameters
+
212  * @param s seperator character for the import function
+
213  * @param iName import filename
+
214  * @param exName export filename
+
215  * @param oName output filename
+
216  * @param dName corpus filename
+
217  * @param n number of passwords to be generated
+
218  *
+
219  */
+
220  void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n) {
+
221  this->po.bImport = i;
+
222  this->po.bExport = e;
+
223  this->po.seperator = s;
+
224  this->po.bFailure = bf;
+
225  this->po.generateN = n;
+
226  this->po.importname = iName;
+
227  this->po.exportname = exName;
+
228  this->po.outputfilename = oName;
+
229  this->po.datasetname = dName;
+
230 
+
231  /*strcpy_s(this->po.importname,256,iName);
+
232  strcpy_s(this->po.exportname,256,exName);
+
233  strcpy_s(this->po.outputfilename,256,oName);
+
234  strcpy_s(this->po.datasetname,256,dName);*/
+
235 
+
236  }
237 
-
238  /** @brief Print help string.
-
239  */
-
240  static void help();
-
241 
-
242  private:
-
243  /**
-
244  @brief ProgramOptions structure object
-
245  */
-
246 
-
247  Markov::API::CLI::ProgramOptions po;
-
248  };
+
238  /** @brief parse cli commands and return
+
239  * @param argc - Program arguement count
+
240  * @param argv - Program arguement values array
+
241  * @return ProgramOptions structure.
+
242  */
+
243  static Markov::API::CLI::ProgramOptions* parse(int argc, char** argv);
+
244 
+
245 
+
246  /** @brief Print help string.
+
247  */
+
248  static void help();
249 
-
250 };
+
250  private:
+
251  /**
+
252  @brief ProgramOptions structure object
+
253  */
+
254 
+
255  Markov::API::CLI::ProgramOptions po;
+
256  };
+
257 
+
258 };
-
std::string importname
Import name of our model.
Definition: argparse.h:42
-
bool bExport
Export flag to validate export
Definition: argparse.h:27
-
void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n)
Initialize program options structure.
Definition: argparse.h:212
-
std::string exportname
Import name of our given wordlist
Definition: argparse.h:47
-
bool bImport
Import flag to validate import
Definition: argparse.h:22
-
char seperator
Seperator character to use with training data. (character between occurence and value)"
Definition: argparse.h:37
-
int generateN
Number of passwords to be generated
Definition: argparse.h:67
-
bool bFailure
Failure flag to validate succesfull running
Definition: argparse.h:32
-
Argparse(int argc, char **argv)
Parse command line arguements.
Definition: argparse.h:86
-
Structure to hold parsed cli arguements.
Definition: argparse.h:18
-
Markov::API::CLI::ProgramOptions getProgramOptions(void)
Getter for command line options.
Definition: argparse.h:195
-
std::string wordlistname
Import name of our given wordlist
Definition: argparse.h:52
-
Parse command line arguements.
Definition: argparse.h:74
-
static void help()
Print help string.
Definition: argparse.cpp:8
-
std::string outputfilename
Output name of our generated password list
Definition: argparse.h:57
-
static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
parse cli commands and return
Definition: argparse.cpp:4
-
std::string datasetname
The name of the given dataset
Definition: argparse.h:62
+
std::string importname
Import name of our model.
Definition: argparse.h:50
+
bool bExport
Export flag to validate export
Definition: argparse.h:35
+
void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n)
Initialize program options structure.
Definition: argparse.h:220
+
std::string exportname
Import name of our given wordlist
Definition: argparse.h:55
+
Namespace for the MarkovPasswords API.
+
bool bImport
Import flag to validate import
Definition: argparse.h:30
+
char seperator
Seperator character to use with training data. (character between occurence and value)"
Definition: argparse.h:45
+
int generateN
Number of passwords to be generated
Definition: argparse.h:75
+
Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
Definition: model.h:24
+
bool bFailure
Failure flag to validate succesfull running
Definition: argparse.h:40
+
Argparse(int argc, char **argv)
Parse command line arguements.
Definition: argparse.h:94
+
Structure to hold parsed cli arguements.
Definition: argparse.h:26
+
Markov::API::CLI::ProgramOptions getProgramOptions(void)
Getter for command line options.
Definition: argparse.h:203
+
std::string wordlistname
Import name of our given wordlist
Definition: argparse.h:60
+
Parse command line arguements.
Definition: argparse.h:82
+
static void help()
Print help string.
Definition: argparse.cpp:15
+
std::string outputfilename
Output name of our generated password list
Definition: argparse.h:65
+
static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
parse cli commands and return
Definition: argparse.cpp:11
+
std::string datasetname
The name of the given dataset
Definition: argparse.h:70
-
Structure to hold parsed cli arguements.
Definition: argparse.h:15
-
Markov::API::CLI::ProgramOptions po
ProgramOptions structure object.
Definition: argparse.h:247
+
Structure to hold parsed cli arguements.
Definition: argparse.h:23
+
Markov::API::CLI::ProgramOptions po
ProgramOptions structure object.
Definition: argparse.h:255
@@ -2758,7 +3610,7 @@

Definition at line 107 of file markovPasswords.h.

+

Definition at line 124 of file markovPasswords.h.

@@ -2772,7 +3624,7 @@

- +
std::map<char , Node<char >*> Markov::Model< char >::nodesstd::map<char , Node<char >*> Markov::Model< char >::nodes
@@ -2784,12 +3636,12 @@

Definition at line 184 of file model.h.

+

Definition at line 193 of file model.h.

- -

◆ outputBuffer

+ +

◆ numberOfPartitions

+ +

◆ outputBuffer

+ +
+
+ + + @@ -2810,7 +3688,9 @@

Definition at line 99 of file cudaModelMatrix.h.

+

Definition at line 113 of file cudaModelMatrix.h.

+ +

Referenced by GatherAsyncKernelOutput(), and prepKernelMemoryChannel().

@@ -2837,7 +3717,7 @@

Definition at line 108 of file markovPasswords.h.

+

Definition at line 125 of file markovPasswords.h.

@@ -2863,9 +3743,9 @@

Definition at line 161 of file modelMatrix.h.

+

Definition at line 200 of file modelMatrix.h.

-

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

+

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

@@ -2879,7 +3759,7 @@

+ + +
char** Markov::API::CUDA::CUDAModelMatrix::outputBuffer
- +
Node<char >* Markov::Model< char >::starterNodeNode<char >* Markov::Model< char >::starterNode
@@ -2891,7 +3771,7 @@

Node of this model.

-

Definition at line 189 of file model.h.

+

Definition at line 198 of file model.h.

@@ -2917,9 +3797,61 @@

Edge Weights.

-

Definition at line 156 of file modelMatrix.h.

+

Definition at line 195 of file modelMatrix.h.

+ +

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::FastRandomWalkThread().

+ + + + +

◆ totalOutputPerKernel

+ +
+
+ + + + + +
+ + + + +
long int Markov::API::CUDA::CUDAModelMatrix::totalOutputPerKernel
+
+private
+
+ +

Definition at line 129 of file cudaModelMatrix.h.

+ +

Referenced by FastRandomWalk().

+ +
+
+ +

◆ totalOutputPerSync

+ +
+
+ + + + + +
+ + + + +
long int Markov::API::CUDA::CUDAModelMatrix::totalOutputPerSync
+
+private
+
@@ -2945,69 +3877,98 @@

Definition at line 141 of file modelMatrix.h.

+

Definition at line 180 of file modelMatrix.h.

-

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

+

Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

-
The documentation for this class was generated from the following file:
    +
    The documentation for this class was generated from the following files: -
    void AdjustEdge(const char *payload, long int occurrence)
    Adjust the model with a single string.
    Definition: model.h:323
    -
    std::map< char, Node< char > * > * Nodes()
    Return starter Node.
    Definition: model.h:177
    -
    void Import(const char *filename)
    Open a file to import with filename, and call bool Model::Import with std::ifstream.
    Definition: modelMatrix.cpp:10
    -
    long int * totalEdgeWeights
    Array of the Total Edge Weights.
    Definition: modelMatrix.h:156
    -
    void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
    Random walk on the Matrix-reduced Markov::Model.
    -
    Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
    Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
    Definition: node.h:226
    -
    Node< NodeStorageType > * LeftNode()
    return edge's LeftNode
    Definition: edge.h:158
    -
    Class to flatten and reduce Markov::Model to a Matrix.
    Definition: modelMatrix.h:13
    -
    bool Import(std::ifstream *)
    Import a file to construct the model.
    Definition: model.h:207
    -
    Node< NodeStorageType > * RightNode()
    return edge's RightNode
    Definition: edge.h:163
    -
    Markov::Model with char represented nodes.
    -
    long int ** valueMatrix
    2-d Integer array for the value Matrix (For the weights of Edges)
    Definition: modelMatrix.h:141
    -
    std::vector< Edge< storageType > * > edgesV
    Definition: node.h:165
    -
    uint64_t EdgeWeight()
    return edge's EdgeWeight.
    Definition: edge.h:153
    -
    char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
    Do a random walk on this model.
    Definition: model.h:293
    -
    bool Export(std::ofstream *)
    Export a file of the model.
    Definition: model.h:274
    - -
    static __host__ int CudaCheckNotifyErr(cudaError_t _status, const char *msg, bool bExit=true)
    Check results of the last operation on GPU.
    -
    bool ready
    True when matrix is constructed. False if not.
    Definition: modelMatrix.h:161
    +
    void AdjustEdge(const NodeStorageType *payload, long int occurrence)
    Adjust the model with a single string.
    Definition: model.h:337
    + +
    std::map< char, Node< char > * > * Nodes()
    Return starter Node.
    Definition: model.h:181
    + +
    void Import(const char *filename)
    Open a file to import with filename, and call bool Model::Import with std::ifstream.
    Definition: modelMatrix.cpp:19
    +
    long int * totalEdgeWeights
    Array of the Total Edge Weights.
    Definition: modelMatrix.h:195
    +
    char ** outputBuffer
    RandomWalk results in host.
    + +
    Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
    Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
    Definition: node.h:234
    +
    Node< NodeStorageType > * LeftNode()
    return edge's LeftNode
    Definition: edge.h:165
    + +
    Class to flatten and reduce Markov::Model to a Matrix.
    Definition: modelMatrix.h:23
    +
    bool Import(std::ifstream *)
    Import a file to construct the model.
    Definition: model.h:216
    +
    Node< NodeStorageType > * RightNode()
    return edge's RightNode
    Definition: edge.h:170
    +
    Markov::Model with char represented nodes.
    + +
    long int ** valueMatrix
    2-d Integer array for the value Matrix (For the weights of Edges)
    Definition: modelMatrix.h:180
    +
    long int * flatValueMatrix
    Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing.
    + +
    std::vector< Edge< storageType > * > edgesV
    Definition: node.h:173
    +
    void OptimizeEdgeOrder()
    Sort edges of all nodes in the model ordered by edge weights.
    Definition: model.h:265
    +
    uint64_t EdgeWeight()
    return edge's EdgeWeight.
    Definition: edge.h:160
    +
    Extension of Markov::Random::Marsaglia which is capable o working on device space.
    Definition: cudarandom.h:20
    +
    char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
    Do a random walk on this model.
    Definition: model.h:307
    +
    __device__ char * strchr(char *p, char c, int s_len)
    srtchr implementation on device space
    +
    __host__ void GatherAsyncKernelOutput(int kernelID, bool bFileIO, std::ofstream &wordlist)
    +
    bool Export(std::ofstream *)
    Export a file of the model.
    Definition: model.h:288
    + +
    __host__ void MigrateMatrix()
    Migrate the class members to the VRAM.
    +
    bool ready
    True when matrix is constructed. False if not.
    Definition: modelMatrix.h:200
    -
    Node< char > * StarterNode()
    Return starter Node.
    Definition: model.h:167
    -
    unsigned long random()
    Generate Random Number.
    Definition: random.h:131
    -
    int matrixSize
    to hold Matrix size
    Definition: modelMatrix.h:146
    -
    void Train(const char *datasetFileName, char delimiter, int threads)
    Train the model with the dataset file.
    -
    void AdjustEdge(long int offset)
    Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
    Definition: edge.h:130
    -
    Edge< storageType > * Link(Node< storageType > *)
    Link this node with another, with this node as its source.
    Definition: node.h:212
    -
    unsigned char NodeValue()
    Return character representation of this node.
    Definition: node.h:207
    -
    Model()
    Initialize a model with only start and end nodes.
    Definition: model.h:201
    -
    std::vector< Edge< char > * > edges
    A list of all edges in this model.
    Definition: model.h:195
    -
    void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
    A single thread invoked by the Generate function.
    -
    Edge< storageType > * FindEdge(storageType repr)
    Find an edge with its character representation.
    Definition: node.h:252
    -
    Implementation of Marsaglia Random Engine.
    Definition: random.h:116
    -
    bool next(std::string *line)
    Read the next line from the file.
    -
    void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
    A single thread of a single partition of FastRandomWalk.
    +
    Node< char > * StarterNode()
    Return starter Node.
    Definition: model.h:171
    +
    unsigned long random()
    Generate Random Number.
    Definition: random.h:140
    +
    int matrixSize
    to hold Matrix size
    Definition: modelMatrix.h:185
    + +
    long int * device_valueMatrix
    VRAM Address pointer of value matrix (from modelMatrix.h)
    +
    void Train(const char *datasetFileName, char delimiter, int threads)
    Train the model with the dataset file.
    + +
    void AdjustEdge(long int offset)
    Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
    Definition: edge.h:137
    + +
    Edge< storageType > * Link(Node< storageType > *)
    Link this node with another, with this node as its source.
    Definition: node.h:220
    +
    unsigned char NodeValue()
    Return character representation of this node.
    Definition: node.h:215
    +
    Model()
    Initialize a model with only start and end nodes.
    Definition: model.h:210
    +
    std::vector< Edge< char > * > edges
    A list of all edges in this model.
    Definition: model.h:204
    +
    __host__ void FlattenMatrix()
    Flatten migrated matrix from 2d to 1d.
    +
    void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
    A single thread invoked by the Generate function.
    +
    __host__ void LaunchAsyncKernel(int kernelID, int minLen, int maxLen)
    +
    static unsigned long * MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize)
    Migrate a Marsaglia[] to VRAM as seedChunk.
    Definition: cudarandom.h:28
    +
    char * device_matrixIndex
    VRAM Address pointer of matrixIndex (from modelMatrix.h)
    +
    Edge< storageType > * FindEdge(storageType repr)
    Find an edge with its character representation.
    Definition: node.h:260
    +
    int FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
    Random walk on the Matrix-reduced Markov::Model.
    +
    Implementation of Marsaglia Random Engine.
    Definition: random.h:125
    +
    bool next(std::string *line)
    Read the next line from the file.
    +
    long int * device_totalEdgeWeights
    VRAM Address pointer of total edge weights (from modelMatrix.h)
    +
    char * flatEdgeMatrix
    Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.
    +
    char * device_edgeMatrix
    VRAM Address pointer of edge matrix (from modelMatrix.h)
    +
    void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
    A single thread of a single partition of FastRandomWalk.
    f
    output file handle
    Definition: model_2gram.py:16
    -
    bool DeallocateMatrix()
    Deallocate matrix and make it ready for re-construction.
    Definition: modelMatrix.cpp:72
    +
    __global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
    CUDA kernel for the FastRandomWalk operation.
    +
    bool DeallocateMatrix()
    Deallocate matrix and make it ready for re-construction.
    Definition: modelMatrix.cpp:81
    -
    __device__ char * strchr(char *p, char c, int s_len)
    srtchr implementation on device space
    -
    std::map< char, Node< char > * > nodes
    Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
    Definition: model.h:184
    -
    bool ConstructMatrix()
    Construct the related Matrix data for the model.
    Definition: modelMatrix.cpp:22
    -
    Node< char > * starterNode
    Starter Node of this model.
    Definition: model.h:189
    -
    static volatile int keepRunning
    - -
    void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
    A single partition of FastRandomWalk event.
    -
    char * matrixIndex
    to hold the Matrix index (To hold the orders of 2-D arrays')
    Definition: modelMatrix.h:151
    -
    Edge class used to link nodes in the model together.
    Definition: model.h:26
    -
    char ** edgeMatrix
    2-D Character array for the edge Matrix (The characters of Nodes)
    Definition: modelMatrix.h:136
    +
    char ** device_outputBuffer
    RandomWalk results in device.
    +
    std::map< char, Node< char > * > nodes
    Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
    Definition: model.h:193
    +
    bool ConstructMatrix()
    Construct the related Matrix data for the model.
    Definition: modelMatrix.cpp:31
    + +
    __host__ void prepKernelMemoryChannel(int numberOfStreams)
    +
    Node< char > * starterNode
    Starter Node of this model.
    Definition: model.h:198
    +
    static volatile int keepRunning
    + +
    static __host__ int CudaCheckNotifyErr(cudaError_t _status, const char *msg, bool bExit=true)
    Check results of the last operation on GPU.
    + +
    void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
    A single partition of FastRandomWalk event.
    +
    char * matrixIndex
    to hold the Matrix index (To hold the orders of 2-D arrays')
    Definition: modelMatrix.h:190
    +
    Edge class used to link nodes in the model together.
    Definition: model.h:30
    +
    char ** edgeMatrix
    2-D Character array for the edge Matrix (The characters of Nodes)
    Definition: modelMatrix.h:175
    -

    Definition at line 130 of file edge.h.

    -
    130  {
    -
    131  this->_weight += offset;
    -
    132  this->LeftNode()->UpdateTotalVerticeWeight(offset);
    -
    133 }
    +

    Definition at line 137 of file edge.h.

    +
    137  {
    +
    138  this->_weight += offset;
    +
    139  this->LeftNode()->UpdateTotalVerticeWeight(offset);
    +
    140 }
    +

    Referenced by Markov::API::MarkovPasswords::Buff().

    +
    +Here is the caller graph for this function:
    +
    +
    +
    +
    +
    @@ -299,16 +301,16 @@

    Returns
    edge's EdgeWeight.
    -

    Definition at line 153 of file edge.h.

    -
    153  {
    -
    154  return this->_weight;
    -
    155 }
    +

    Definition at line 160 of file edge.h.

    +
    160  {
    +
    161  return this->_weight;
    +
    162 }
    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    +

    Referenced by Markov::API::MarkovPasswords::Buff(), and Markov::API::ModelMatrix::ConstructMatrix().

    Here is the caller graph for this function:
    -
    +
    @@ -331,10 +333,10 @@

    Returns
    edge's LeftNode.
    -

    Definition at line 158 of file edge.h.

    -
    158  {
    -
    159  return this->_left;
    -
    160 }
    +

    Definition at line 165 of file edge.h.

    +
    165  {
    +
    166  return this->_left;
    +
    167 }

    @@ -363,12 +365,12 @@

    Returns
    edge's RightNode.
    -

    Definition at line 163 of file edge.h.

    -
    163  {
    -
    164  return this->_right;
    -
    165 }
    +

    Definition at line 170 of file edge.h.

    +
    170  {
    +
    171  return this->_right;
    +
    172 }
    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    Here is the caller graph for this function:
    @@ -404,10 +406,10 @@

    Definition at line 143 of file edge.h.

    -
    143  {
    -
    144  this->_left = n;
    -
    145 }
    +

    Definition at line 150 of file edge.h.

    +
    150  {
    +
    151  this->_left = n;
    +
    152 }

    @@ -437,10 +439,10 @@

    Definition at line 148 of file edge.h.

    -
    148  {
    -
    149  this->_right = n;
    -
    150 }
    +

    Definition at line 155 of file edge.h.

    +
    155  {
    +
    156  this->_right = n;
    +
    157 }

    @@ -475,12 +477,12 @@

    e1->AdjustEdge(25);

    Markov::Edge<unsigned char>* e2 = e1->traverseNode();
    -

    Definition at line 136 of file edge.h.

    -
    136  {
    -
    137  if (this->RightNode()->NodeValue() == 0xff) //terminator node
    -
    138  return NULL;
    -
    139  return _right;
    -
    140 }
    +

    Definition at line 143 of file edge.h.

    +
    143  {
    +
    144  if (this->RightNode()->NodeValue() == 0xff) //terminator node
    +
    145  return NULL;
    +
    146  return _right;
    +
    147 }
    @@ -509,7 +511,7 @@

    Definition at line 98 of file edge.h.

    +

    Definition at line 105 of file edge.h.

    @@ -537,9 +539,9 @@

    Definition at line 103 of file edge.h.

    +

    Definition at line 110 of file edge.h.

    -

    Referenced by Markov::Edge< char >::TraverseNode().

    +

    Referenced by Markov::Edge< char >::TraverseNode().

    @@ -567,7 +569,7 @@

    Edge Edge Weight.

    -

    Definition at line 108 of file edge.h.

    +

    Definition at line 115 of file edge.h.

    @@ -577,20 +579,20 @@

    Node< NodeStorageType > * LeftNode()
    return edge's LeftNode
    Definition: edge.h:158
    -
    Node< NodeStorageType > * RightNode()
    return edge's RightNode
    Definition: edge.h:163
    -
    A node class that for the vertices of model. Connected with eachother using Edge.
    Definition: model.h:23
    -
    void AdjustEdge(long int offset)
    Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
    Definition: edge.h:130
    -
    long int _weight
    Edge Edge Weight.
    Definition: edge.h:108
    -
    Node< NodeStorageType > * _left
    source node
    Definition: edge.h:98
    -
    Node< NodeStorageType > * _right
    target node
    Definition: edge.h:103
    -
    Edge class used to link nodes in the model together.
    Definition: model.h:26
    -
    void UpdateTotalVerticeWeight(long int offset)
    Change total weights with offset.
    Definition: node.h:259
    +
    Node< NodeStorageType > * LeftNode()
    return edge's LeftNode
    Definition: edge.h:165
    +
    Node< NodeStorageType > * RightNode()
    return edge's RightNode
    Definition: edge.h:170
    +
    A node class that for the vertices of model. Connected with eachother using Edge.
    Definition: model.h:27
    +
    void AdjustEdge(long int offset)
    Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
    Definition: edge.h:137
    +
    long int _weight
    Edge Edge Weight.
    Definition: edge.h:115
    +
    Node< NodeStorageType > * _left
    source node
    Definition: edge.h:105
    +
    Node< NodeStorageType > * _right
    target node
    Definition: edge.h:110
    +
    Edge class used to link nodes in the model together.
    Definition: model.h:30
    +
    void UpdateTotalVerticeWeight(long int offset)
    Change total weights with offset.
    Definition: node.h:267
    @@ -431,7 +433,7 @@

    - +
    unsigned char Markov::Node< storageType >::NodeValueunsigned char Markov::Node< storageType >::NodeValue
    @@ -444,12 +446,12 @@

    Returns
    character representation at _value.
    -

    Definition at line 207 of file node.h.

    -
    207  {
    -
    208  return _value;
    -
    209 }
    +

    Definition at line 215 of file node.h.

    +
    215  {
    +
    216  return _value;
    +
    217 }
    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    Here is the caller graph for this function:
    @@ -480,9 +482,9 @@

    Returns
    Node that was chosen at EdgeWeight biased random.

    Example Use: Use randomNext to do a random walk on the model

    char* buffer[64];
    - -
    model.Import("model.mdl");
    -
    Markov::Node<char>* n = model.starterNode;
    + +
    model.Import("model.mdl");
    +
    int len = 0;
    Markov::Node<char>* temp_node;
    while (true) {
    @@ -503,23 +505,23 @@

    buffer[len++] = n->NodeValue();

    }

    -

    Definition at line 226 of file node.h.

    -
    226  {
    -
    227 
    -
    228  //get a random NodeValue in range of total_vertice_weight
    -
    229  long int selection = randomEngine->random() % this->total_edge_weights;//distribution()(generator());// distribution(generator);
    -
    230  //make absolute, no negative modulus values wanted
    -
    231  //selection = (selection >= 0) ? selection : (selection + this->total_edge_weights);
    -
    232  for(int i=0;i<this->edgesV.size();i++){
    -
    233  selection -= this->edgesV[i]->EdgeWeight();
    -
    234  if (selection < 0) return this->edgesV[i]->TraverseNode();
    -
    235  }
    -
    236 
    -
    237  //if this assertion is reached, it means there is an implementation error above
    -
    238  std::cout << "This should never be reached (node failed to walk to next)\n"; //cant assert from child thread
    -
    239  assert(true && "This should never be reached (node failed to walk to next)");
    -
    240  return NULL;
    -
    241 }
    +

    Definition at line 234 of file node.h.

    +
    234  {
    +
    235 
    +
    236  //get a random NodeValue in range of total_vertice_weight
    +
    237  long int selection = randomEngine->random() % this->total_edge_weights;//distribution()(generator());// distribution(generator);
    +
    238  //make absolute, no negative modulus values wanted
    +
    239  //selection = (selection >= 0) ? selection : (selection + this->total_edge_weights);
    +
    240  for(int i=0;i<this->edgesV.size();i++){
    +
    241  selection -= this->edgesV[i]->EdgeWeight();
    +
    242  if (selection < 0) return this->edgesV[i]->TraverseNode();
    +
    243  }
    +
    244 
    +
    245  //if this assertion is reached, it means there is an implementation error above
    +
    246  std::cout << "This should never be reached (node failed to walk to next)\n"; //cant assert from child thread
    +
    247  assert(true && "This should never be reached (node failed to walk to next)");
    +
    248  return NULL;
    +
    249 }
    @@ -547,12 +549,12 @@

    Definition at line 269 of file node.h.

    -
    269  {
    -
    270  return this->total_edge_weights;
    -
    271 }
    +

    Definition at line 277 of file node.h.

    +
    277  {
    +
    278  return this->total_edge_weights;
    +
    279 }
    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix().

    Here is the caller graph for this function:
    @@ -599,13 +601,13 @@

    e2->AdjustEdge(30);

    src->UpdateEdges(e2);
    -

    Definition at line 244 of file node.h.

    -
    244  {
    -
    245  this->edges.insert({ v->RightNode()->NodeValue(), v });
    -
    246  this->edgesV.push_back(v);
    -
    247  //this->total_edge_weights += v->EdgeWeight();
    -
    248  return v->TraverseNode();
    -
    249 }
    +

    Definition at line 252 of file node.h.

    +
    252  {
    +
    253  this->edges.insert({ v->RightNode()->NodeValue(), v });
    +
    254  this->edgesV.push_back(v);
    +
    255  //this->total_edge_weights += v->EdgeWeight();
    +
    256  return v->TraverseNode();
    +
    257 }
    @@ -635,10 +637,10 @@

    Definition at line 259 of file node.h.

    -
    259  {
    -
    260  this->total_edge_weights += offset;
    -
    261 }
    +

    Definition at line 267 of file node.h.

    +
    267  {
    +
    268  this->total_edge_weights += offset;
    +
    269 }
    @@ -667,9 +669,9 @@

    Definition at line 171 of file node.h.

    +

    Definition at line 179 of file node.h.

    -

    Referenced by Markov::Node< NodeStorageType >::NodeValue().

    +

    Referenced by Markov::Node< NodeStorageType >::NodeValue().

    @@ -697,7 +699,7 @@

    Definition at line 182 of file node.h.

    +

    Definition at line 190 of file node.h.

    @@ -715,7 +717,7 @@

    -

    Definition at line 165 of file node.h.

    +

    Definition at line 173 of file node.h.

    @@ -743,7 +745,7 @@

    Definition at line 176 of file node.h.

    +

    Definition at line 184 of file node.h.

    @@ -753,29 +755,30 @@

    storageType _value
    Character representation of this node. 0 for starter, 0xff for terminator.
    Definition: node.h:171
    -
    void SetLeftEdge(Node< NodeStorageType > *)
    Set LeftNode of this edge.
    Definition: edge.h:143
    -
    Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
    Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
    Definition: node.h:226
    -
    Node< NodeStorageType > * RightNode()
    return edge's RightNode
    Definition: edge.h:163
    -
    std::vector< Edge< storageType > * > edgesV
    Definition: node.h:165
    -
    std::map< storageType, Edge< storageType > * > edges
    A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsi...
    Definition: node.h:182
    -
    A node class that for the vertices of model. Connected with eachother using Edge.
    Definition: model.h:23
    +
    storageType _value
    Character representation of this node. 0 for starter, 0xff for terminator.
    Definition: node.h:179
    +
    void SetLeftEdge(Node< NodeStorageType > *)
    Set LeftNode of this edge.
    Definition: edge.h:150
    +
    Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
    Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
    Definition: node.h:234
    +
    bool Import(std::ifstream *)
    Import a file to construct the model.
    Definition: model.h:216
    +
    Node< NodeStorageType > * RightNode()
    return edge's RightNode
    Definition: edge.h:170
    +
    std::vector< Edge< storageType > * > edgesV
    Definition: node.h:173
    +
    std::map< storageType, Edge< storageType > * > edges
    A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsi...
    Definition: node.h:190
    +
    A node class that for the vertices of model. Connected with eachother using Edge.
    Definition: model.h:27
    virtual unsigned long random()=0
    -
    void AdjustEdge(long int offset)
    Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
    Definition: edge.h:130
    -
    Edge< storageType > * Link(Node< storageType > *)
    Link this node with another, with this node as its source.
    Definition: node.h:212
    -
    unsigned char NodeValue()
    Return character representation of this node.
    Definition: node.h:207
    -
    Edge< storageType > * FindEdge(storageType repr)
    Find an edge with its character representation.
    Definition: node.h:252
    -
    long int total_edge_weights
    Total weights of the vertices, required by RandomNext.
    Definition: node.h:176
    -
    Node< NodeStorageType > * TraverseNode()
    Traverse this edge to RightNode.
    Definition: edge.h:136
    +
    void AdjustEdge(long int offset)
    Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
    Definition: edge.h:137
    +
    Edge< storageType > * Link(Node< storageType > *)
    Link this node with another, with this node as its source.
    Definition: node.h:220
    +
    unsigned char NodeValue()
    Return character representation of this node.
    Definition: node.h:215
    +
    Edge< storageType > * FindEdge(storageType repr)
    Find an edge with its character representation.
    Definition: node.h:260
    +
    long int total_edge_weights
    Total weights of the vertices, required by RandomNext.
    Definition: node.h:184
    +
    Node< NodeStorageType > * TraverseNode()
    Traverse this edge to RightNode.
    Definition: edge.h:143
    -
    bool UpdateEdges(Edge< storageType > *)
    Insert a new edge to the this.edges.
    Definition: node.h:244
    - -
    Edge class used to link nodes in the model together.
    Definition: model.h:26
    +
    bool UpdateEdges(Edge< storageType > *)
    Insert a new edge to the this.edges.
    Definition: node.h:252
    +
    Node< NodeStorageType > * starterNode
    Starter Node of this model.
    Definition: model.h:198
    +
    Edge class used to link nodes in the model together.
    Definition: model.h:30
    -Go to the documentation of this file.
    1 // pch.h: This is a precompiled header file.
    -
    2 // Files listed below are compiled only once, improving build performance for future builds.
    -
    3 // This also affects IntelliSense performance, including code completion and many code browsing features.
    -
    4 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
    -
    5 // Do not add files here that you will be updating frequently as this negates the performance advantage.
    -
    6 
    -
    7 #ifndef PCH_H
    -
    8 #define PCH_H
    -
    9 
    -
    10 // add headers that you want to pre-compile here
    -
    11 #include "framework.h"
    -
    12 
    -
    13 #endif //PCH_H
    +Go to the documentation of this file.
    1 /** @file pch.h
    +
    2  * @brief For windows dynamic library
    +
    3  * @authors Ata Hakçıl
    +
    4  *
    +
    5  */
    +
    6 // pch.h: This is a precompiled header file.
    +
    7 // Files listed below are compiled only once, improving build performance for future builds.
    +
    8 // This also affects IntelliSense performance, including code completion and many code browsing features.
    +
    9 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
    +
    10 // Do not add files here that you will be updating frequently as this negates the performance advantage.
    +
    11 
    +
    12 #ifndef PCH_H
    +
    13 #define PCH_H
    +
    14 
    +
    15 // add headers that you want to pre-compile here
    +
    16 #include "framework.h"
    +
    17 
    +
    18 #endif //PCH_H
    @@ -86,40 +86,48 @@
    -
    UI/src/main.cpp File Reference
    +
    MarkovPasswordsGUI/src/main.cpp File Reference
    + +

    Entry point for GUI. +More...

    #include "menu.h"
    #include <QtWidgets/QApplication>
    #include <QSplashScreen>
    #include <QDateTime>
    #include "CLI.h"
    -Include dependency graph for UI/src/main.cpp:
    +Include dependency graph for MarkovPasswordsGUI/src/main.cpp:
    -
    +
    - - + + - +
    -

    Go to the source code of this file.

    +

    Go to the source code of this file.

    - - + +

    Functions

    int main (int argc, char *argv[])
     Launch UI. More...
    int main (int argc, char *argv[])
     Launch UI. More...
     
    -

    Function Documentation

    +

    Detailed Description

    +

    Entry point for GUI.

    +
    Authors
    Yunus Emre Yılmaz
    + +

    Definition in file MarkovPasswordsGUI/src/main.cpp.

    +

    Function Documentation

    ◆ main()

    @@ -135,7 +143,7 @@

    - char *  + charargv[]  @@ -148,52 +156,41 @@

    Definition at line 12 of file UI/src/main.cpp.

    -
    13 {
    -
    14 
    -
    15 
    -
    16 
    -
    17  QApplication a(argc, argv);
    -
    18 
    -
    19  QPixmap loadingPix("views/startup.jpg");
    -
    20  QSplashScreen splash(loadingPix);
    -
    21  splash.show();
    -
    22  QDateTime time = QDateTime::currentDateTime();
    -
    23  QDateTime currentTime = QDateTime::currentDateTime(); //Record current time
    -
    24  while (time.secsTo(currentTime) <= 5) //5 is the number of seconds to delay
    -
    25  {
    -
    26  currentTime = QDateTime::currentDateTime();
    -
    27  a.processEvents();
    -
    28  };
    -
    29 
    -
    30 
    -
    31  CLI w;
    -
    32  w.show();
    -
    33  splash.finish(&w);
    -
    34  return a.exec();
    -
    35 }
    +

    Definition at line 18 of file MarkovPasswordsGUI/src/main.cpp.

    +
    19 {
    +
    20 
    +
    21 
    +
    22 
    +
    23  QApplication a(argc, argv);
    +
    24 
    +
    25  QPixmap loadingPix("views/startup.jpg");
    +
    26  QSplashScreen splash(loadingPix);
    +
    27  splash.show();
    +
    28  QDateTime time = QDateTime::currentDateTime();
    +
    29  QDateTime currentTime = QDateTime::currentDateTime(); //Record current time
    +
    30  while (time.secsTo(currentTime) <= 5) //5 is the number of seconds to delay
    +
    31  {
    +
    32  currentTime = QDateTime::currentDateTime();
    +
    33  a.processEvents();
    +
    34  };
    +
    35 
    +
    36 
    +
    37  CLI w;
    +
    38  w.show();
    +
    39  splash.finish(&w);
    +
    40  return a.exec();
    +
    41 }
    -

    References Markov::GUI::CLI::start().

    -
    -Here is the call graph for this function:
    -
    -
    - - - - -
    -
    -
    QT CLI Class.
    Definition: CLI.h:8
    +
    QT CLI Class.
    Definition: CLI.h:14
    @@ -84,54 +84,61 @@
    -
    UI/src/main.cpp
    +
    MarkovPasswordsGUI/src/main.cpp
    -Go to the documentation of this file.
    1 //#include "MarkovPasswordsGUI.h"
    -
    2 #include "menu.h"
    -
    3 #include <QtWidgets/QApplication>
    -
    4 #include <QSplashScreen>
    -
    5 #include < QDateTime >
    -
    6 #include "CLI.h"
    -
    7 
    -
    8 using namespace Markov::GUI;
    -
    9 
    -
    10 /** @brief Launch UI.
    -
    11 */
    -
    12 int main(int argc, char *argv[])
    -
    13 {
    -
    14 
    +Go to the documentation of this file.
    1 /** @file main.cpp
    +
    2  * @brief Entry point for GUI
    +
    3  * @authors Yunus Emre Yılmaz
    +
    4  *
    +
    5  */
    +
    6 
    +
    7 //#include "MarkovPasswordsGUI.h"
    +
    8 #include "menu.h"
    +
    9 #include <QtWidgets/QApplication>
    +
    10 #include <QSplashScreen>
    +
    11 #include < QDateTime >
    +
    12 #include "CLI.h"
    +
    13 
    +
    14 using namespace Markov::GUI;
    15 
    -
    16 
    -
    17  QApplication a(argc, argv);
    -
    18 
    -
    19  QPixmap loadingPix("views/startup.jpg");
    -
    20  QSplashScreen splash(loadingPix);
    -
    21  splash.show();
    -
    22  QDateTime time = QDateTime::currentDateTime();
    -
    23  QDateTime currentTime = QDateTime::currentDateTime(); //Record current time
    -
    24  while (time.secsTo(currentTime) <= 5) //5 is the number of seconds to delay
    -
    25  {
    -
    26  currentTime = QDateTime::currentDateTime();
    -
    27  a.processEvents();
    -
    28  };
    -
    29 
    -
    30 
    -
    31  CLI w;
    -
    32  w.show();
    -
    33  splash.finish(&w);
    -
    34  return a.exec();
    -
    35 }
    +
    16 /** @brief Launch UI.
    +
    17 */
    +
    18 int main(int argc, char *argv[])
    +
    19 {
    +
    20 
    +
    21 
    +
    22 
    +
    23  QApplication a(argc, argv);
    +
    24 
    +
    25  QPixmap loadingPix("views/startup.jpg");
    +
    26  QSplashScreen splash(loadingPix);
    +
    27  splash.show();
    +
    28  QDateTime time = QDateTime::currentDateTime();
    +
    29  QDateTime currentTime = QDateTime::currentDateTime(); //Record current time
    +
    30  while (time.secsTo(currentTime) <= 5) //5 is the number of seconds to delay
    +
    31  {
    +
    32  currentTime = QDateTime::currentDateTime();
    +
    33  a.processEvents();
    +
    34  };
    +
    35 
    +
    36 
    +
    37  CLI w;
    +
    38  w.show();
    +
    39  splash.finish(&w);
    +
    40  return a.exec();
    +
    41 }
    -
    int main(int argc, char *argv[])
    Launch UI.
    Definition: UI/src/main.cpp:12
    -
    namespace for MarkovPasswords API GUI wrapper
    Definition: menu.h:6
    - +
    int main(int argc, char **argv)
    Definition: main.cu:21
    +
    namespace for MarkovPasswords API GUI wrapper
    Definition: about.h:14
    +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    +
    QT CLI Class.
    Definition: CLI.h:14
    + +

    Main activity page for GUI. +More...

    #include "MarkovPasswordsGUI.h"
    #include <fstream>
    #include <qwebengineview.h>
    -#include <Windows.h>
    #include "CLI.h"
    Include dependency graph for MarkovPasswordsGUI.cpp:
    - - + + - - - + + - +

    Go to the source code of this file.

    -
    +

    Detailed Description

    +

    Main activity page for GUI.

    +
    Authors
    Yunus Emre Yılmaz
    + +

    Definition in file MarkovPasswordsGUI.cpp.

    +
    -Go to the documentation of this file.
    -
    2 #include <fstream>
    -
    3 #include <qwebengineview.h>
    -
    4 #include <Windows.h>
    -
    5 #include "CLI.h"
    +Go to the documentation of this file.
    1 /** @file MarkovPasswordsGUI.cpp
    +
    2  * @brief Main activity page for GUI
    +
    3  * @authors Yunus Emre Yılmaz
    +
    4  *
    +
    5  */
    6 
    -
    7 using namespace Markov::GUI;
    -
    8 
    -
    9 MarkovPasswordsGUI::MarkovPasswordsGUI(QWidget *parent)
    -
    10  : QMainWindow(parent)
    -
    11 {
    -
    12  ui.setupUi(this);
    + +
    8 #include <fstream>
    +
    9 #include <qwebengineview.h>
    +
    10 #include "CLI.h"
    +
    11 
    +
    12 using namespace Markov::GUI;
    13 
    -
    14 
    -
    15  QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {home(); });
    -
    16  QObject::connect(ui.pushButton_2, &QPushButton::clicked, this, [this] {model(); });
    -
    17  QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {pass(); });
    -
    18 }
    -
    19 
    -
    20 
    -
    21 void MarkovPasswordsGUI::home() {
    -
    22  CLI* w = new CLI;
    -
    23  w->show();
    -
    24  this->close();
    -
    25 }
    -
    26 void MarkovPasswordsGUI::pass() {
    -
    27  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
    -
    28 
    -
    29  //get working directory
    -
    30  char path[255];
    -
    31  GetCurrentDirectoryA(255, path);
    -
    32 
    -
    33  //get absolute path to the layout html
    -
    34  std::string layout = "file:///" + std::string(path) + "\\views\\bar.html";
    -
    35  std::replace(layout.begin(), layout.end(), '\\', '/');
    -
    36  webkit->setUrl(QUrl(layout.c_str()));
    -
    37 }
    -
    38 
    -
    39 void MarkovPasswordsGUI::model() {
    -
    40  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
    +
    14 Markov::GUI::MarkovPasswordsGUI::MarkovPasswordsGUI(QWidget *parent) : QMainWindow(parent){
    +
    15  ui.setupUi(this);
    +
    16 
    +
    17 
    +
    18  QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {home(); });
    +
    19  QObject::connect(ui.pushButton_2, &QPushButton::clicked, this, [this] {model(); });
    +
    20  QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {pass(); });
    +
    21 }
    +
    22 
    +
    23 
    + +
    25  CLI* w = new CLI;
    +
    26  w->show();
    +
    27  this->close();
    +
    28 }
    + +
    30  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
    +
    31 
    +
    32  //get working directory
    +
    33  char path[255];
    +
    34  GetCurrentDirectoryA(255, path);
    +
    35 
    +
    36  //get absolute path to the layout html
    +
    37  std::string layout = "file:///" + std::string(path) + "\\views\\bar.html";
    +
    38  std::replace(layout.begin(), layout.end(), '\\', '/');
    +
    39  webkit->setUrl(QUrl(layout.c_str()));
    +
    40 }
    41 
    -
    42  //get working directory
    -
    43  char path[255];
    -
    44  GetCurrentDirectoryA(255, path);
    -
    45 
    -
    46  //get absolute path to the layout html
    -
    47  std::string layout = "file:///" + std::string(path) + "\\views\\index.html";
    -
    48  std::replace(layout.begin(), layout.end(), '\\', '/');
    -
    49  webkit->setUrl(QUrl(layout.c_str()));
    -
    50 }
    + +
    43  QWebEngineView* webkit = ui.centralWidget->findChild<QWebEngineView*>("chartArea");
    +
    44 
    +
    45  //get working directory
    +
    46  char path[255];
    +
    47  GetCurrentDirectoryA(255, path);
    +
    48 
    +
    49  //get absolute path to the layout html
    +
    50  std::string layout = "file:///" + std::string(path) + "\\views\\index.html";
    +
    51  std::replace(layout.begin(), layout.end(), '\\', '/');
    +
    52  webkit->setUrl(QUrl(layout.c_str()));
    +
    53 }
    -
    namespace for MarkovPasswords API GUI wrapper
    Definition: menu.h:6
    + +
    namespace for MarkovPasswords API GUI wrapper
    Definition: about.h:14
    + +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    +
    QT CLI Class.
    Definition: CLI.h:14
    + +
    MarkovPasswordsGUI(QWidget *parent=Q_NULLPTR)
    +
    Ui::MarkovPasswordsGUIClass ui
    +
    + +

    Main activity page for GUI. +More...

    #include <QtWidgets/QMainWindow>
    #include "ui_MarkovPasswordsGUI.h"
    @@ -97,7 +100,7 @@
    - + @@ -107,9 +110,10 @@
    - - - + + + +
    @@ -130,13 +134,18 @@  namespace for MarkovPasswords API GUI wrapper
      -
    +

    Detailed Description

    +

    Main activity page for GUI.

    +
    Authors
    Yunus Emre Yılmaz
    + +

    Definition in file MarkovPasswordsGUI.h.

    +
    -Go to the documentation of this file.
    1 #pragma once
    -
    2 
    -
    3 #include <QtWidgets/QMainWindow>
    -
    4 #include "ui_MarkovPasswordsGUI.h"
    -
    5 
    +Go to the documentation of this file.
    1 /** @file MarkovPasswordsGUI.h
    +
    2  * @brief Main activity page for GUI
    +
    3  * @authors Yunus Emre Yılmaz
    +
    4  *
    +
    5  */
    6 
    -
    7 
    -
    8 namespace Markov::GUI{
    -
    9  /** @brief Reporting UI.
    -
    10  *
    -
    11  * UI for reporting and debugging tools for MarkovPassword
    -
    12  */
    - -
    14  Q_OBJECT
    -
    15 
    -
    16  private:
    - -
    18 
    -
    19 
    -
    20  //Slots for buttons in GUI.
    -
    21  public slots:
    -
    22 
    - - - - +
    7 #pragma once
    +
    8 
    +
    9 #include <QtWidgets/QMainWindow>
    +
    10 #include "ui_MarkovPasswordsGUI.h"
    +
    11 
    +
    12 
    +
    13 
    +
    14 namespace Markov::GUI{
    +
    15  /** @brief Reporting UI.
    +
    16  *
    +
    17  * UI for reporting and debugging tools for MarkovPassword
    +
    18  */
    +
    19  class MarkovPasswordsGUI : public QMainWindow {
    +
    20  Q_OBJECT
    +
    21  public:
    +
    22  MarkovPasswordsGUI(QWidget* parent = Q_NULLPTR);
    +
    23 
    +
    24  private:
    +
    25  Ui::MarkovPasswordsGUIClass ui;
    +
    26 
    27 
    -
    28 
    -
    29  public slots:
    +
    28  //Slots for buttons in GUI.
    +
    29  public slots:
    30 
    -
    31  void MarkovPasswordsGUI::home();
    -
    32  void MarkovPasswordsGUI :: pass();
    -
    33  void MarkovPasswordsGUI::model();
    -
    34  };
    -
    35 };
    +
    31  void benchmarkSelected();
    +
    32  //void MarkovPasswordsGUI::modelvisSelected();
    +
    33  //void MarkovPasswordsGUI::visualDebugSelected();
    +
    34  //void MarkovPasswordsGUI::comparisonSelected();
    +
    35 
    +
    36 
    +
    37  public slots:
    +
    38 
    +
    39  void home();
    +
    40  void pass();
    +
    41  void model();
    +
    42  };
    +
    43 };
    -
    void MarkovPasswordsGUI::home()
    -
    namespace for MarkovPasswords API GUI wrapper
    Definition: menu.h:6
    -
    void MarkovPasswordsGUI::comparisonSelected()
    -
    void MarkovPasswordsGUI ::pass()
    -
    void MarkovPasswordsGUI::visualDebugSelected()
    -
    void MarkovPasswordsGUI::modelvisSelected()
    -
    void MarkovPasswordsGUI::model()
    + +
    namespace for MarkovPasswords API GUI wrapper
    Definition: about.h:14
    + +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    + +
    MarkovPasswordsGUI(QWidget *parent=Q_NULLPTR)
    +
    Ui::MarkovPasswordsGUIClass ui
    + +
    + +

    training page for GUI +More...

    #include <QtWidgets/QMainWindow>
    #include "ui_Train.h"
    @@ -97,11 +100,21 @@
    - +
    +
    +This graph shows which files directly or indirectly include this file:
    +
    +
    + + + + + +

    Go to the source code of this file.

    @@ -120,13 +133,18 @@
     namespace for MarkovPasswords API GUI wrapper
     
    -
    +

    Detailed Description

    +

    training page for GUI

    +
    Authors
    Yunus Emre Yılmaz
    + +

    Definition in file Train.h.

    +
    -Go to the documentation of this file.
    1 #pragma once
    -
    2 #include <QtWidgets/QMainWindow>
    -
    3 #include "ui_Train.h"
    -
    4 
    -
    5 namespace Markov::GUI{
    +Go to the documentation of this file.
    1 /** @file Train.h
    +
    2  * @brief training page for GUI
    +
    3  * @authors Yunus Emre Yılmaz
    +
    4  *
    +
    5  */
    6 
    -
    7  /** @brief QT Training page class
    -
    8  */
    -
    9  class Train :public QMainWindow {
    -
    10  Q_OBJECT
    -
    11  public:
    - -
    13 
    -
    14  private:
    - -
    16 
    -
    17  public slots:
    -
    18  void home();
    -
    19  void train();
    -
    20  };
    -
    21 };
    +
    7 #pragma once
    +
    8 #include <QtWidgets/QMainWindow>
    +
    9 #include "ui_Train.h"
    +
    10 
    +
    11 namespace Markov::GUI{
    +
    12 
    +
    13  /** @brief QT Training page class
    +
    14  */
    +
    15  class Train :public QMainWindow {
    +
    16  Q_OBJECT
    +
    17  public:
    +
    18  Train(QWidget* parent = Q_NULLPTR);
    +
    19 
    +
    20  private:
    +
    21  Ui::Train ui;
    +
    22 
    +
    23  public slots:
    +
    24  void home();
    +
    25  void train();
    +
    26  };
    +
    27 };
    -
    namespace for MarkovPasswords API GUI wrapper
    Definition: menu.h:6
    -
    Ui::Train ui
    Definition: Train.h:15
    - - +
    namespace for MarkovPasswords API GUI wrapper
    Definition: about.h:14
    +
    Ui::Train ui
    Definition: Train.h:21
    +
    Train(QWidget *parent=Q_NULLPTR)
    Definition: Train.cpp:22
    +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    + +
    QT Training page class.
    Definition: Train.h:15
    +
    + +

    For windows dynamic library. +More...

    #include "pch.h"
    Include dependency graph for UnitTests/pch.cpp:
    - - + +

    Go to the source code of this file.

    -
    +

    Detailed Description

    +

    For windows dynamic library.

    +
    Authors
    Ata Hakçıl
    + +

    Definition in file UnitTests/pch.cpp.

    +
    -Go to the documentation of this file.
    1 // pch.cpp: source file corresponding to the pre-compiled header
    -
    2 
    -
    3 #include "pch.h"
    -
    4 
    -
    5 // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
    +Go to the documentation of this file.
    1 /** @file pch.cpp
    +
    2  * @brief For windows dynamic library
    +
    3  * @authors Ata Hakçıl
    +
    4  *
    +
    5  */
    +
    6 // pch.cpp: source file corresponding to the pre-compiled header
    +
    7 
    +
    8 #include "pch.h"
    +
    9 
    +
    10 // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
    + +

    For windows dynamic library. +More...

    This graph shows which files directly or indirectly include this file:
    - - - + + +

    Go to the source code of this file.

    -
    +

    Detailed Description

    +

    For windows dynamic library.

    +
    Authors
    Ata Hakçıl
    + +

    Definition in file UnitTests/pch.h.

    +
    -Go to the documentation of this file.
    1 // pch.h: This is a precompiled header file.
    -
    2 // Files listed below are compiled only once, improving build performance for future builds.
    -
    3 // This also affects IntelliSense performance, including code completion and many code browsing features.
    -
    4 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
    -
    5 // Do not add files here that you will be updating frequently as this negates the performance advantage.
    -
    6 
    -
    7 #ifndef PCH_H
    -
    8 #define PCH_H
    -
    9 
    -
    10 // add headers that you want to pre-compile here
    +Go to the documentation of this file.
    1 /** @file pch.h
    +
    2  * @brief For windows dynamic library
    +
    3  * @authors Ata Hakçıl
    +
    4  *
    +
    5  */
    +
    6 // pch.h: This is a precompiled header file.
    +
    7 // Files listed below are compiled only once, improving build performance for future builds.
    +
    8 // This also affects IntelliSense performance, including code completion and many code browsing features.
    +
    9 // However, files listed here are ALL re-compiled if any one of them is updated between builds.
    +
    10 // Do not add files here that you will be updating frequently as this negates the performance advantage.
    11 
    -
    12 #endif //PCH_H
    +
    12 #ifndef PCH_H
    +
    13 #define PCH_H
    +
    14 
    +
    15 // add headers that you want to pre-compile here
    +
    16 
    +
    17 #endif //PCH_H
    + +

    Unit tests with Microsoft::VisualStudio::CppUnitTestFramework. +More...

    #include "pch.h"
    #include "CppUnitTest.h"
    #include "MarkovModel/src/model.h"
    @@ -98,21 +101,21 @@
    - - + + - + - - + + - + @@ -166,13 +169,18 @@  Test class for rest of model cases. More...
      -
    +

    Detailed Description

    +

    Unit tests with Microsoft::VisualStudio::CppUnitTestFramework.

    +
    Authors
    Ata Hakçıl, Osman Ömer Yıldıztugay, Yunus Emre Yılmaz
    + +

    Definition in file UnitTests.cpp.

    +
    -Go to the documentation of this file.
    1 #include "pch.h"
    -
    2 #include "CppUnitTest.h"
    -
    3 #include "MarkovModel/src/model.h"
    -
    4 
    -
    5 using namespace Microsoft::VisualStudio::CppUnitTestFramework;
    +Go to the documentation of this file.
    1 /** @file UnitTests.cpp
    +
    2  * @brief Unit tests with Microsoft::VisualStudio::CppUnitTestFramework
    +
    3  * @authors Ata Hakçıl, Osman Ömer Yıldıztugay, Yunus Emre Yılmaz
    +
    4  *
    +
    5  */
    6 
    -
    7 
    -
    8 /** @brief Namespace for Microsoft Native Unit Testing Classes
    -
    9 */
    -
    10 namespace Testing {
    -
    11 
    -
    12  /** @brief Testing Namespace for Minimal Viable Product
    -
    13  */
    -
    14  namespace MVP {
    -
    15  /** @brief Testing Namespace for MVP MarkovModel
    -
    16  */
    -
    17  namespace MarkovModel
    -
    18  {
    -
    19  /** @brief Test class for minimal viable Edge
    -
    20  */
    - -
    22  {
    -
    23  public:
    -
    24 
    -
    25  /** @brief test default constructor
    -
    26  */
    - -
    28  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>;
    -
    29  Assert::IsNull(e->LeftNode());
    -
    30  Assert::IsNull(e->RightNode());
    -
    31  delete e;
    -
    32  }
    -
    33 
    -
    34  /** @brief test linked constructor with two nodes
    -
    35  */
    - -
    37  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    38  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    39  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    - - -
    42  delete LeftNode;
    -
    43  delete RightNode;
    -
    44  delete e;
    -
    45  }
    -
    46 
    -
    47  /** @brief test AdjustEdge function
    -
    48  */
    - -
    50  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    51  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    52  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    -
    53  e->AdjustEdge(15);
    -
    54  Assert::AreEqual(15ull, e->EdgeWeight());
    -
    55  e->AdjustEdge(15);
    -
    56  Assert::AreEqual(30ull, e->EdgeWeight());
    -
    57  delete LeftNode;
    -
    58  delete RightNode;
    -
    59  delete e;
    -
    60  }
    -
    61 
    -
    62  /** @brief test TraverseNode returning RightNode
    -
    63  */
    - -
    65  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    66  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    67  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    - -
    69  delete LeftNode;
    -
    70  delete RightNode;
    -
    71  delete e;
    -
    72  }
    -
    73 
    -
    74  /** @brief test LeftNode/RightNode setter
    -
    75  */
    - -
    77  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    78  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    79  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    -
    80 
    -
    81  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>;
    - - -
    84 
    -
    85  Assert::IsTrue(e1->LeftNode() == e2->LeftNode());
    -
    86  Assert::IsTrue(e1->RightNode() == e2->RightNode());
    -
    87  delete LeftNode;
    -
    88  delete RightNode;
    -
    89  delete e1;
    -
    90  delete e2;
    -
    91  }
    -
    92 
    -
    93  /** @brief test negative adjustments
    -
    94  */
    - -
    96  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    97  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    98  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    -
    99  e->AdjustEdge(15);
    -
    100  Assert::AreEqual(15ull, e->EdgeWeight());
    -
    101  e->AdjustEdge(-15);
    -
    102  Assert::AreEqual(0ull, e->EdgeWeight());
    -
    103  delete LeftNode;
    -
    104  delete RightNode;
    -
    105  delete e;
    -
    106  }
    -
    107  };
    -
    108 
    -
    109  /** @brief Test class for minimal viable Node
    -
    110  */
    - -
    112  {
    -
    113  public:
    +
    7 #include "pch.h"
    +
    8 #include "CppUnitTest.h"
    +
    9 #include "MarkovModel/src/model.h"
    +
    10 
    +
    11 using namespace Microsoft::VisualStudio::CppUnitTestFramework;
    +
    12 
    +
    13 
    +
    14 /** @brief Namespace for Microsoft Native Unit Testing Classes
    +
    15 */
    +
    16 namespace Testing {
    +
    17 
    +
    18  /** @brief Testing Namespace for Minimal Viable Product
    +
    19  */
    +
    20  namespace MVP {
    +
    21  /** @brief Testing Namespace for MVP MarkovModel
    +
    22  */
    +
    23  namespace MarkovModel
    +
    24  {
    +
    25  /** @brief Test class for minimal viable Edge
    +
    26  */
    + +
    28  {
    +
    29  public:
    +
    30 
    +
    31  /** @brief test default constructor
    +
    32  */
    + +
    34  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>;
    +
    35  Assert::IsNull(e->LeftNode());
    +
    36  Assert::IsNull(e->RightNode());
    +
    37  delete e;
    +
    38  }
    +
    39 
    +
    40  /** @brief test linked constructor with two nodes
    +
    41  */
    + +
    43  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    44  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    45  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    + + +
    48  delete LeftNode;
    +
    49  delete RightNode;
    +
    50  delete e;
    +
    51  }
    +
    52 
    +
    53  /** @brief test AdjustEdge function
    +
    54  */
    + +
    56  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    57  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    58  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    +
    59  e->AdjustEdge(15);
    +
    60  Assert::AreEqual(15ull, e->EdgeWeight());
    +
    61  e->AdjustEdge(15);
    +
    62  Assert::AreEqual(30ull, e->EdgeWeight());
    +
    63  delete LeftNode;
    +
    64  delete RightNode;
    +
    65  delete e;
    +
    66  }
    +
    67 
    +
    68  /** @brief test TraverseNode returning RightNode
    +
    69  */
    + +
    71  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    72  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    73  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    + +
    75  delete LeftNode;
    +
    76  delete RightNode;
    +
    77  delete e;
    +
    78  }
    +
    79 
    +
    80  /** @brief test LeftNode/RightNode setter
    +
    81  */
    + +
    83  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    84  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    85  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    +
    86 
    +
    87  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>;
    + + +
    90 
    +
    91  Assert::IsTrue(e1->LeftNode() == e2->LeftNode());
    +
    92  Assert::IsTrue(e1->RightNode() == e2->RightNode());
    +
    93  delete LeftNode;
    +
    94  delete RightNode;
    +
    95  delete e1;
    +
    96  delete e2;
    +
    97  }
    +
    98 
    +
    99  /** @brief test negative adjustments
    +
    100  */
    + +
    102  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    103  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    104  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    +
    105  e->AdjustEdge(15);
    +
    106  Assert::AreEqual(15ull, e->EdgeWeight());
    +
    107  e->AdjustEdge(-15);
    +
    108  Assert::AreEqual(0ull, e->EdgeWeight());
    +
    109  delete LeftNode;
    +
    110  delete RightNode;
    +
    111  delete e;
    +
    112  }
    +
    113  };
    114 
    -
    115  /** @brief test default constructor
    -
    116  */
    - -
    118  Markov::Node<unsigned char>* n = new Markov::Node<unsigned char>();
    -
    119  Assert::AreEqual((unsigned char)0, n->NodeValue());
    -
    120  delete n;
    -
    121  }
    -
    122 
    -
    123  /** @brief test custom constructor with unsigned char
    -
    124  */
    - -
    126  Markov::Node<unsigned char>* n = NULL;
    -
    127  unsigned char test_cases[] = { 'c', 0x00, 0xff, -32 };
    -
    128  for (unsigned char tcase : test_cases) {
    -
    129  n = new Markov::Node<unsigned char>(tcase);
    - -
    131  delete n;
    -
    132  }
    -
    133  }
    -
    134 
    -
    135  /** @brief test link function
    -
    136  */
    - -
    138  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    139  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    115  /** @brief Test class for minimal viable Node
    +
    116  */
    + +
    118  {
    +
    119  public:
    +
    120 
    +
    121  /** @brief test default constructor
    +
    122  */
    + +
    124  Markov::Node<unsigned char>* n = new Markov::Node<unsigned char>();
    +
    125  Assert::AreEqual((unsigned char)0, n->NodeValue());
    +
    126  delete n;
    +
    127  }
    +
    128 
    +
    129  /** @brief test custom constructor with unsigned char
    +
    130  */
    + +
    132  Markov::Node<unsigned char>* n = NULL;
    +
    133  unsigned char test_cases[] = { 'c', 0x00, 0xff, -32 };
    +
    134  for (unsigned char tcase : test_cases) {
    +
    135  n = new Markov::Node<unsigned char>(tcase);
    + +
    137  delete n;
    +
    138  }
    +
    139  }
    140 
    -
    141  Markov::Edge<unsigned char>* e = LeftNode->Link(RightNode);
    -
    142  delete LeftNode;
    -
    143  delete RightNode;
    -
    144  delete e;
    -
    145  }
    +
    141  /** @brief test link function
    +
    142  */
    + +
    144  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    145  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    146 
    -
    147  /** @brief test link function
    -
    148  */
    - -
    150  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    151  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    147  Markov::Edge<unsigned char>* e = LeftNode->Link(RightNode);
    +
    148  delete LeftNode;
    +
    149  delete RightNode;
    +
    150  delete e;
    +
    151  }
    152 
    -
    153  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(NULL, RightNode);
    -
    154  LeftNode->Link(e);
    -
    155  Assert::IsTrue(LeftNode == e->LeftNode());
    - -
    157  delete LeftNode;
    -
    158  delete RightNode;
    -
    159  delete e;
    -
    160  }
    -
    161 
    -
    162  /** @brief test RandomNext with low values
    -
    163  */
    - - -
    166  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    167  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    168  Markov::Edge<unsigned char>* e = src->Link(target1);
    -
    169  e->AdjustEdge(15);
    -
    170  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    171  Assert::IsTrue(res == target1);
    -
    172  delete src;
    -
    173  delete target1;
    -
    174  delete e;
    -
    175 
    -
    176  }
    -
    177 
    -
    178  /** @brief test RandomNext with 32 bit high values
    -
    179  */
    - - -
    182  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    183  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    184  Markov::Edge<unsigned char>* e = src->Link(target1);
    -
    185  e->AdjustEdge(1 << 31);
    -
    186  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    187  Assert::IsTrue(res == target1);
    -
    188  delete src;
    -
    189  delete target1;
    -
    190  delete e;
    -
    191 
    -
    192  }
    -
    193 
    -
    194  /** @brief random next on a node with no follow-ups
    -
    195  */
    - - -
    198  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    199  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    200  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    -
    201  Markov::Edge<unsigned char>* e1 = src->Link(target1);
    -
    202  Markov::Edge<unsigned char>* e2 = src->Link(target2);
    -
    203  e1->AdjustEdge(1);
    -
    204  e2->AdjustEdge((unsigned long)(1ull << 31));
    -
    205  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    206  Assert::IsNotNull(res);
    -
    207  Assert::IsTrue(res == target2);
    -
    208  delete src;
    -
    209  delete target1;
    -
    210  delete e1;
    -
    211  delete e2;
    -
    212  }
    -
    213 
    -
    214  /** @brief random next on a node with no follow-ups
    -
    215  */
    - - -
    218  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    219  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    220  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    -
    221  Markov::Edge<unsigned char>* e1 = src->Link(target1);
    -
    222  Markov::Edge<unsigned char>* e2 = src->Link(target2);
    -
    223  e2->AdjustEdge(1);
    -
    224  e1->AdjustEdge((unsigned long)(1ull << 31));
    -
    225  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    226  Assert::IsNotNull(res);
    -
    227  Assert::IsTrue(res == target1);
    -
    228  delete src;
    -
    229  delete target1;
    -
    230  delete e1;
    -
    231  delete e2;
    -
    232  }
    -
    233 
    -
    234 
    -
    235  /** @brief test updateEdges
    -
    236  */
    - -
    238 
    -
    239  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    240  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    241  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    -
    242  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
    -
    243  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target2);
    -
    244  e1->AdjustEdge(25);
    -
    245  src->UpdateEdges(e1);
    -
    246  e2->AdjustEdge(30);
    -
    247  src->UpdateEdges(e2);
    -
    248 
    -
    249  Assert::AreEqual((size_t)2, src->Edges()->size());
    -
    250 
    -
    251  delete src;
    -
    252  delete target1;
    -
    253  delete e1;
    -
    254  delete e2;
    -
    255 
    -
    256  }
    -
    257 
    -
    258  /** @brief test updateEdges
    -
    259  */
    - +
    153  /** @brief test link function
    +
    154  */
    + +
    156  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    157  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    158 
    +
    159  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(NULL, RightNode);
    +
    160  LeftNode->Link(e);
    +
    161  Assert::IsTrue(LeftNode == e->LeftNode());
    + +
    163  delete LeftNode;
    +
    164  delete RightNode;
    +
    165  delete e;
    +
    166  }
    +
    167 
    +
    168  /** @brief test RandomNext with low values
    +
    169  */
    + + +
    172  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    173  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    174  Markov::Edge<unsigned char>* e = src->Link(target1);
    +
    175  e->AdjustEdge(15);
    +
    176  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    177  Assert::IsTrue(res == target1);
    +
    178  delete src;
    +
    179  delete target1;
    +
    180  delete e;
    +
    181 
    +
    182  }
    +
    183 
    +
    184  /** @brief test RandomNext with 32 bit high values
    +
    185  */
    + + +
    188  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    189  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    190  Markov::Edge<unsigned char>* e = src->Link(target1);
    +
    191  e->AdjustEdge(1 << 31);
    +
    192  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    193  Assert::IsTrue(res == target1);
    +
    194  delete src;
    +
    195  delete target1;
    +
    196  delete e;
    +
    197 
    +
    198  }
    +
    199 
    +
    200  /** @brief random next on a node with no follow-ups
    +
    201  */
    + + +
    204  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    205  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    206  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    +
    207  Markov::Edge<unsigned char>* e1 = src->Link(target1);
    +
    208  Markov::Edge<unsigned char>* e2 = src->Link(target2);
    +
    209  e1->AdjustEdge(1);
    +
    210  e2->AdjustEdge((unsigned long)(1ull << 31));
    +
    211  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    212  Assert::IsNotNull(res);
    +
    213  Assert::IsTrue(res == target2);
    +
    214  delete src;
    +
    215  delete target1;
    +
    216  delete e1;
    +
    217  delete e2;
    +
    218  }
    +
    219 
    +
    220  /** @brief random next on a node with no follow-ups
    +
    221  */
    + + +
    224  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    225  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    226  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    +
    227  Markov::Edge<unsigned char>* e1 = src->Link(target1);
    +
    228  Markov::Edge<unsigned char>* e2 = src->Link(target2);
    +
    229  e2->AdjustEdge(1);
    +
    230  e1->AdjustEdge((unsigned long)(1ull << 31));
    +
    231  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    232  Assert::IsNotNull(res);
    +
    233  Assert::IsTrue(res == target1);
    +
    234  delete src;
    +
    235  delete target1;
    +
    236  delete e1;
    +
    237  delete e2;
    +
    238  }
    +
    239 
    +
    240 
    +
    241  /** @brief test updateEdges
    +
    242  */
    + +
    244 
    +
    245  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    246  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    247  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    +
    248  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
    +
    249  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target2);
    +
    250  e1->AdjustEdge(25);
    +
    251  src->UpdateEdges(e1);
    +
    252  e2->AdjustEdge(30);
    +
    253  src->UpdateEdges(e2);
    +
    254 
    +
    255  Assert::AreEqual((size_t)2, src->Edges()->size());
    +
    256 
    +
    257  delete src;
    +
    258  delete target1;
    +
    259  delete e1;
    +
    260  delete e2;
    261 
    -
    262  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    263  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    264  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
    -
    265  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target1);
    -
    266  e1->AdjustEdge(25);
    -
    267  src->UpdateEdges(e1);
    -
    268  e2->AdjustEdge(30);
    -
    269  src->UpdateEdges(e2);
    -
    270 
    -
    271  //Assert::AreEqual(55ull, src->TotalEdgeWeights());
    -
    272 
    -
    273  delete src;
    -
    274  delete target1;
    -
    275  delete e1;
    -
    276  delete e2;
    -
    277  }
    +
    262  }
    +
    263 
    +
    264  /** @brief test updateEdges
    +
    265  */
    + +
    267 
    +
    268  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    269  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    270  Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
    +
    271  Markov::Edge<unsigned char>* e2 = new Markov::Edge<unsigned char>(src, target1);
    +
    272  e1->AdjustEdge(25);
    +
    273  src->UpdateEdges(e1);
    +
    274  e2->AdjustEdge(30);
    +
    275  src->UpdateEdges(e2);
    +
    276 
    +
    277  //Assert::AreEqual(55ull, src->TotalEdgeWeights());
    278 
    -
    279 
    -
    280  /** @brief test FindVertice
    -
    281  */
    - -
    283 
    -
    284  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    285  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    286  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    -
    287  Markov::Edge<unsigned char>* res = NULL;
    -
    288  src->Link(target1);
    -
    289  src->Link(target2);
    -
    290 
    -
    291 
    -
    292  res = src->FindEdge('b');
    -
    293  Assert::IsNotNull(res);
    -
    294  Assert::AreEqual((unsigned char)'b', res->TraverseNode()->NodeValue());
    -
    295  res = src->FindEdge('c');
    -
    296  Assert::IsNotNull(res);
    -
    297  Assert::AreEqual((unsigned char)'c', res->TraverseNode()->NodeValue());
    -
    298 
    -
    299  delete src;
    -
    300  delete target1;
    -
    301  delete target2;
    -
    302 
    -
    303 
    -
    304  }
    -
    305 
    -
    306 
    -
    307  /** @brief test FindVertice
    -
    308  */
    - -
    310 
    -
    311  auto _invalid_next = [] {
    -
    312  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    313  Markov::Edge<unsigned char>* res = NULL;
    -
    314 
    -
    315  res = src->FindEdge('b');
    -
    316  Assert::IsNull(res);
    -
    317 
    -
    318  delete src;
    -
    319  };
    +
    279  delete src;
    +
    280  delete target1;
    +
    281  delete e1;
    +
    282  delete e2;
    +
    283  }
    +
    284 
    +
    285 
    +
    286  /** @brief test FindVertice
    +
    287  */
    + +
    289 
    +
    290  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    291  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    292  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    +
    293  Markov::Edge<unsigned char>* res = NULL;
    +
    294  src->Link(target1);
    +
    295  src->Link(target2);
    +
    296 
    +
    297 
    +
    298  res = src->FindEdge('b');
    +
    299  Assert::IsNotNull(res);
    +
    300  Assert::AreEqual((unsigned char)'b', res->TraverseNode()->NodeValue());
    +
    301  res = src->FindEdge('c');
    +
    302  Assert::IsNotNull(res);
    +
    303  Assert::AreEqual((unsigned char)'c', res->TraverseNode()->NodeValue());
    +
    304 
    +
    305  delete src;
    +
    306  delete target1;
    +
    307  delete target2;
    +
    308 
    +
    309 
    +
    310  }
    +
    311 
    +
    312 
    +
    313  /** @brief test FindVertice
    +
    314  */
    + +
    316 
    +
    317  auto _invalid_next = [] {
    +
    318  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    319  Markov::Edge<unsigned char>* res = NULL;
    320 
    -
    321  //Assert::ExpectException<std::logic_error>(_invalid_next);
    -
    322  }
    +
    321  res = src->FindEdge('b');
    +
    322  Assert::IsNull(res);
    323 
    -
    324  /** @brief test FindVertice
    -
    325  */
    - -
    327 
    -
    328  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    329  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    330  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    -
    331  Markov::Edge<unsigned char>* res = NULL;
    -
    332  src->Link(target1);
    -
    333  src->Link(target2);
    -
    334 
    -
    335  res = src->FindEdge('D');
    -
    336  Assert::IsNull(res);
    -
    337 
    -
    338  delete src;
    -
    339  delete target1;
    -
    340  delete target2;
    -
    341 
    -
    342  }
    -
    343  };
    -
    344 
    -
    345  /** @brief Test class for minimal viable Model
    -
    346  */
    - -
    348  {
    -
    349  public:
    -
    350  /** @brief test model constructor for starter node
    -
    351  */
    - -
    353  Markov::Model<unsigned char> m;
    -
    354  Assert::AreEqual((unsigned char)'\0', m.StarterNode()->NodeValue());
    -
    355  }
    -
    356 
    -
    357  /** @brief test import
    -
    358  */
    - -
    360  Markov::Model<unsigned char> m;
    -
    361  Assert::IsTrue(m.Import("../MarkovPasswords/Models/2gram.mdl"));
    -
    362  }
    -
    363 
    -
    364  /** @brief test export
    -
    365  */
    - -
    367  Markov::Model<unsigned char> m;
    -
    368  Assert::IsTrue(m.Export("../MarkovPasswords/Models/testcase.mdl"));
    -
    369  }
    -
    370 
    -
    371  /** @brief test random walk
    -
    372  */
    - -
    374  unsigned char* res = new unsigned char[12 + 5];
    - -
    376  Markov::Model<unsigned char> m;
    -
    377  Assert::IsTrue(m.Import("../Models/finished2.mdl"));
    - -
    379  }
    -
    380  };
    -
    381  }
    -
    382 
    -
    383  /** @brief Testing namespace for MVP MarkovPasswords
    -
    384  */
    -
    385  namespace MarkovPasswords
    -
    386  {
    -
    387  /** @brief Test Class for Argparse class
    -
    388  */
    - -
    390  {
    -
    391  public:
    -
    392  /** @brief test basic generate
    -
    393  */
    - -
    395  int argc = 8;
    -
    396  char *argv[] = {"markov.exe", "generate", "-if", "model.mdl", "-of", "passwords.txt", "-n", "100"};
    -
    397 
    -
    398  /*ProgramOptions *p = Argparse::parse(argc, argv);
    -
    399  Assert::IsNotNull(p);
    -
    400 
    -
    401  Assert::AreEqual(p->bImport, true);
    -
    402  Assert::AreEqual(p->bExport, false);
    -
    403  Assert::AreEqual(p->importname, "model.mdl");
    -
    404  Assert::AreEqual(p->outputfilename, "passwords.txt");
    -
    405  Assert::AreEqual(p->generateN, 100); */
    -
    406 
    -
    407  }
    -
    408 
    -
    409  /** @brief test basic generate reordered params
    -
    410  */
    - -
    412  int argc = 8;
    -
    413  char *argv[] = { "markov.exe", "generate", "-n", "100", "-if", "model.mdl", "-of", "passwords.txt" };
    +
    324  delete src;
    +
    325  };
    +
    326 
    +
    327  //Assert::ExpectException<std::logic_error>(_invalid_next);
    +
    328  }
    +
    329 
    +
    330  /** @brief test FindVertice
    +
    331  */
    + +
    333 
    +
    334  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    335  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    336  Markov::Node<unsigned char>* target2 = new Markov::Node<unsigned char>('c');
    +
    337  Markov::Edge<unsigned char>* res = NULL;
    +
    338  src->Link(target1);
    +
    339  src->Link(target2);
    +
    340 
    +
    341  res = src->FindEdge('D');
    +
    342  Assert::IsNull(res);
    +
    343 
    +
    344  delete src;
    +
    345  delete target1;
    +
    346  delete target2;
    +
    347 
    +
    348  }
    +
    349  };
    +
    350 
    +
    351  /** @brief Test class for minimal viable Model
    +
    352  */
    + +
    354  {
    +
    355  public:
    +
    356  /** @brief test model constructor for starter node
    +
    357  */
    + +
    359  Markov::Model<unsigned char> m;
    +
    360  Assert::AreEqual((unsigned char)'\0', m.StarterNode()->NodeValue());
    +
    361  }
    +
    362 
    +
    363  /** @brief test import
    +
    364  */
    + +
    366  Markov::Model<unsigned char> m;
    +
    367  Assert::IsTrue(m.Import("../MarkovPasswords/Models/2gram.mdl"));
    +
    368  }
    +
    369 
    +
    370  /** @brief test export
    +
    371  */
    + +
    373  Markov::Model<unsigned char> m;
    +
    374  Assert::IsTrue(m.Export("../MarkovPasswords/Models/testcase.mdl"));
    +
    375  }
    +
    376 
    +
    377  /** @brief test random walk
    +
    378  */
    + +
    380  unsigned char* res = new unsigned char[12 + 5];
    + +
    382  Markov::Model<unsigned char> m;
    +
    383  Assert::IsTrue(m.Import("../Models/finished2.mdl"));
    + +
    385  }
    +
    386  };
    +
    387  }
    +
    388 
    +
    389  /** @brief Testing namespace for MVP MarkovPasswords
    +
    390  */
    +
    391  namespace MarkovPasswords
    +
    392  {
    +
    393  /** @brief Test Class for Argparse class
    +
    394  */
    + +
    396  {
    +
    397  public:
    +
    398  /** @brief test basic generate
    +
    399  */
    + +
    401  int argc = 8;
    +
    402  char *argv[] = {"markov.exe", "generate", "-if", "model.mdl", "-of", "passwords.txt", "-n", "100"};
    +
    403 
    +
    404  /*ProgramOptions *p = Argparse::parse(argc, argv);
    +
    405  Assert::IsNotNull(p);
    +
    406 
    +
    407  Assert::AreEqual(p->bImport, true);
    +
    408  Assert::AreEqual(p->bExport, false);
    +
    409  Assert::AreEqual(p->importname, "model.mdl");
    +
    410  Assert::AreEqual(p->outputfilename, "passwords.txt");
    +
    411  Assert::AreEqual(p->generateN, 100); */
    +
    412 
    +
    413  }
    414 
    -
    415  /*ProgramOptions* p = Argparse::parse(argc, argv);
    -
    416  Assert::IsNotNull(p);
    -
    417 
    -
    418  Assert::AreEqual(p->bImport, true);
    -
    419  Assert::AreEqual(p->bExport, false);
    -
    420  Assert::AreEqual(p->importname, "model.mdl");
    -
    421  Assert::AreEqual(p->outputfilename, "passwords.txt");
    -
    422  Assert::AreEqual(p->generateN, 100);*/
    -
    423  }
    -
    424 
    -
    425  /** @brief test basic generate param longnames
    -
    426  */
    - -
    428  int argc = 8;
    -
    429  char *argv[] = { "markov.exe", "generate", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
    +
    415  /** @brief test basic generate reordered params
    +
    416  */
    + +
    418  int argc = 8;
    +
    419  char *argv[] = { "markov.exe", "generate", "-n", "100", "-if", "model.mdl", "-of", "passwords.txt" };
    +
    420 
    +
    421  /*ProgramOptions* p = Argparse::parse(argc, argv);
    +
    422  Assert::IsNotNull(p);
    +
    423 
    +
    424  Assert::AreEqual(p->bImport, true);
    +
    425  Assert::AreEqual(p->bExport, false);
    +
    426  Assert::AreEqual(p->importname, "model.mdl");
    +
    427  Assert::AreEqual(p->outputfilename, "passwords.txt");
    +
    428  Assert::AreEqual(p->generateN, 100);*/
    +
    429  }
    430 
    -
    431  /*ProgramOptions* p = Argparse::parse(argc, argv);
    -
    432  Assert::IsNotNull(p);
    -
    433 
    -
    434  Assert::AreEqual(p->bImport, true);
    -
    435  Assert::AreEqual(p->bExport, false);
    -
    436  Assert::AreEqual(p->importname, "model.mdl");
    -
    437  Assert::AreEqual(p->outputfilename, "passwords.txt");
    -
    438  Assert::AreEqual(p->generateN, 100); */
    -
    439  }
    -
    440 
    -
    441  /** @brief test basic generate
    -
    442  */
    - -
    444  int argc = 8;
    -
    445  char *argv[] = { "markov.exe", "junk", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
    +
    431  /** @brief test basic generate param longnames
    +
    432  */
    + +
    434  int argc = 8;
    +
    435  char *argv[] = { "markov.exe", "generate", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
    +
    436 
    +
    437  /*ProgramOptions* p = Argparse::parse(argc, argv);
    +
    438  Assert::IsNotNull(p);
    +
    439 
    +
    440  Assert::AreEqual(p->bImport, true);
    +
    441  Assert::AreEqual(p->bExport, false);
    +
    442  Assert::AreEqual(p->importname, "model.mdl");
    +
    443  Assert::AreEqual(p->outputfilename, "passwords.txt");
    +
    444  Assert::AreEqual(p->generateN, 100); */
    +
    445  }
    446 
    -
    447  /*ProgramOptions* p = Argparse::parse(argc, argv);
    -
    448  Assert::IsNull(p); */
    -
    449  }
    -
    450 
    -
    451  /** @brief test basic train
    -
    452  */
    - -
    454  int argc = 4;
    -
    455  char *argv[] = { "markov.exe", "train", "-ef", "model.mdl" };
    +
    447  /** @brief test basic generate
    +
    448  */
    + +
    450  int argc = 8;
    +
    451  char *argv[] = { "markov.exe", "junk", "-n", "100", "--inputfilename", "model.mdl", "--outputfilename", "passwords.txt" };
    +
    452 
    +
    453  /*ProgramOptions* p = Argparse::parse(argc, argv);
    +
    454  Assert::IsNull(p); */
    +
    455  }
    456 
    -
    457  /*ProgramOptions* p = Argparse::parse(argc, argv);
    -
    458  Assert::IsNotNull(p);
    -
    459 
    -
    460  Assert::AreEqual(p->bImport, false);
    -
    461  Assert::AreEqual(p->bExport, true);
    -
    462  Assert::AreEqual(p->exportname, "model.mdl"); */
    -
    463 
    -
    464  }
    -
    465 
    -
    466  /** @brief test basic generate
    -
    467  */
    - -
    469  int argc = 4;
    -
    470  char *argv[] = { "markov.exe", "train", "--exportfilename", "model.mdl" };
    +
    457  /** @brief test basic train
    +
    458  */
    + +
    460  int argc = 4;
    +
    461  char *argv[] = { "markov.exe", "train", "-ef", "model.mdl" };
    +
    462 
    +
    463  /*ProgramOptions* p = Argparse::parse(argc, argv);
    +
    464  Assert::IsNotNull(p);
    +
    465 
    +
    466  Assert::AreEqual(p->bImport, false);
    +
    467  Assert::AreEqual(p->bExport, true);
    +
    468  Assert::AreEqual(p->exportname, "model.mdl"); */
    +
    469 
    +
    470  }
    471 
    -
    472  /*ProgramOptions* p = Argparse::parse(argc, argv);
    -
    473  Assert::IsNotNull(p);
    -
    474 
    -
    475  Assert::AreEqual(p->bImport, false);
    -
    476  Assert::AreEqual(p->bExport, true);
    -
    477  Assert::AreEqual(p->exportname, "model.mdl"); */
    -
    478  }
    -
    479 
    -
    480 
    -
    481 
    -
    482  };
    -
    483 
    -
    484  }
    -
    485  }
    +
    472  /** @brief test basic generate
    +
    473  */
    + +
    475  int argc = 4;
    +
    476  char *argv[] = { "markov.exe", "train", "--exportfilename", "model.mdl" };
    +
    477 
    +
    478  /*ProgramOptions* p = Argparse::parse(argc, argv);
    +
    479  Assert::IsNotNull(p);
    +
    480 
    +
    481  Assert::AreEqual(p->bImport, false);
    +
    482  Assert::AreEqual(p->bExport, true);
    +
    483  Assert::AreEqual(p->exportname, "model.mdl"); */
    +
    484  }
    +
    485 
    486 
    487 
    -
    488  /** @brief Testing namespace for MarkovModel
    -
    489  */
    -
    490  namespace MarkovModel {
    -
    491 
    -
    492  /** @brief Test class for rest of Edge cases
    -
    493  */
    - -
    495  {
    -
    496  public:
    -
    497  /** @brief send exception on integer underflow
    -
    498  */
    - -
    500  auto _underflow_adjust = [] {
    -
    501  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    502  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    503  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    -
    504  e->AdjustEdge(15);
    -
    505  e->AdjustEdge(-30);
    -
    506  delete LeftNode;
    -
    507  delete RightNode;
    -
    508  delete e;
    -
    509  };
    - -
    511  }
    -
    512 
    -
    513  /** @brief test integer overflows
    -
    514  */
    - -
    516  auto _overflow_adjust = [] {
    -
    517  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    -
    518  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    -
    519  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    -
    520  e->AdjustEdge(~0ull);
    -
    521  e->AdjustEdge(1);
    -
    522  delete LeftNode;
    -
    523  delete RightNode;
    -
    524  delete e;
    -
    525  };
    - -
    527  }
    -
    528  };
    -
    529 
    -
    530  /** @brief Test class for rest of Node cases
    -
    531  */
    - -
    533  {
    -
    534  public:
    +
    488  };
    +
    489 
    +
    490  }
    +
    491  }
    +
    492 
    +
    493 
    +
    494  /** @brief Testing namespace for MarkovModel
    +
    495  */
    +
    496  namespace MarkovModel {
    +
    497 
    +
    498  /** @brief Test class for rest of Edge cases
    +
    499  */
    + +
    501  {
    +
    502  public:
    +
    503  /** @brief send exception on integer underflow
    +
    504  */
    + +
    506  auto _underflow_adjust = [] {
    +
    507  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    508  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    509  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    +
    510  e->AdjustEdge(15);
    +
    511  e->AdjustEdge(-30);
    +
    512  delete LeftNode;
    +
    513  delete RightNode;
    +
    514  delete e;
    +
    515  };
    + +
    517  }
    +
    518 
    +
    519  /** @brief test integer overflows
    +
    520  */
    + +
    522  auto _overflow_adjust = [] {
    +
    523  Markov::Node<unsigned char>* LeftNode = new Markov::Node<unsigned char>('l');
    +
    524  Markov::Node<unsigned char>* RightNode = new Markov::Node<unsigned char>('r');
    +
    525  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(LeftNode, RightNode);
    +
    526  e->AdjustEdge(~0ull);
    +
    527  e->AdjustEdge(1);
    +
    528  delete LeftNode;
    +
    529  delete RightNode;
    +
    530  delete e;
    +
    531  };
    + +
    533  }
    +
    534  };
    535 
    -
    536  /** @brief test RandomNext with 64 bit high values
    -
    537  */
    - - -
    540  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    541  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    542  Markov::Edge<unsigned char>* e = src->Link(target1);
    -
    543  e->AdjustEdge((unsigned long)(1ull << 63));
    -
    544  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    545  Assert::IsTrue(res == target1);
    -
    546  delete src;
    -
    547  delete target1;
    -
    548  delete e;
    -
    549 
    -
    550  }
    -
    551 
    -
    552  /** @brief test RandomNext with 64 bit high values
    -
    553  */
    - - -
    556  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    557  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    558  Markov::Edge<unsigned char>* e = src->Link(target1);
    -
    559  e->AdjustEdge((0xffffFFFF));
    -
    560  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    561  Assert::IsTrue(res == target1);
    -
    562  delete src;
    -
    563  delete target1;
    -
    564  delete e;
    -
    565 
    -
    566  }
    -
    567 
    -
    568  /** @brief randomNext when no edges are present
    -
    569  */
    - +
    536  /** @brief Test class for rest of Node cases
    +
    537  */
    + +
    539  {
    +
    540  public:
    +
    541 
    +
    542  /** @brief test RandomNext with 64 bit high values
    +
    543  */
    + + +
    546  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    547  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    548  Markov::Edge<unsigned char>* e = src->Link(target1);
    +
    549  e->AdjustEdge((unsigned long)(1ull << 63));
    +
    550  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    551  Assert::IsTrue(res == target1);
    +
    552  delete src;
    +
    553  delete target1;
    +
    554  delete e;
    +
    555 
    +
    556  }
    +
    557 
    +
    558  /** @brief test RandomNext with 64 bit high values
    +
    559  */
    + + +
    562  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    563  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    564  Markov::Edge<unsigned char>* e = src->Link(target1);
    +
    565  e->AdjustEdge((0xffffFFFF));
    +
    566  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    567  Assert::IsTrue(res == target1);
    +
    568  delete src;
    +
    569  delete target1;
    +
    570  delete e;
    571 
    -
    572  auto _invalid_next = [] {
    - -
    574  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    -
    575  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    -
    576  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(src, target1);
    -
    577  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    -
    578 
    -
    579  delete src;
    -
    580  delete target1;
    -
    581  delete e;
    -
    582  };
    -
    583 
    - -
    585  }
    -
    586 
    -
    587 
    -
    588  };
    +
    572  }
    +
    573 
    +
    574  /** @brief randomNext when no edges are present
    +
    575  */
    + +
    577 
    +
    578  auto _invalid_next = [] {
    + +
    580  Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
    +
    581  Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
    +
    582  Markov::Edge<unsigned char>* e = new Markov::Edge<unsigned char>(src, target1);
    +
    583  Markov::Node<unsigned char>* res = src->RandomNext(&MarsagliaRandomEngine);
    +
    584 
    +
    585  delete src;
    +
    586  delete target1;
    +
    587  delete e;
    +
    588  };
    589 
    -
    590  /** @brief Test class for rest of model cases
    -
    591  */
    - -
    593  {
    -
    594  public:
    - -
    596  unsigned char* res2 = new unsigned char[12 + 5];
    - -
    598  Markov::Model<unsigned char> m;
    -
    599  Markov::Node<unsigned char>* starter = m.StarterNode();
    -
    600  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
    -
    601  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
    -
    602  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
    -
    603  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
    -
    604  starter->Link(a)->AdjustEdge(1);
    -
    605  a->Link(b)->AdjustEdge(1);
    -
    606  b->Link(c)->AdjustEdge(1);
    -
    607  c->Link(end)->AdjustEdge(1);
    -
    608 
    -
    609  char* res = (char*)m.RandomWalk(&MarsagliaRandomEngine,1,12,res2);
    -
    610  Assert::IsFalse(strcmp(res, "abc"));
    -
    611  }
    - -
    613  Markov::Model<unsigned char> m;
    -
    614  Markov::Node<unsigned char>* starter = m.StarterNode();
    -
    615  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
    -
    616  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
    -
    617  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
    -
    618  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
    -
    619  Markov::Edge<unsigned char>* res = NULL;
    -
    620  starter->Link(a)->AdjustEdge(1);
    -
    621  a->Link(b)->AdjustEdge(1);
    -
    622  b->Link(c)->AdjustEdge(1);
    -
    623  c->Link(end)->AdjustEdge(1);
    -
    624 
    -
    625  res = starter->FindEdge('D');
    -
    626  Assert::IsNull(res);
    -
    627 
    -
    628  }
    -
    629  };
    + +
    591  }
    +
    592 
    +
    593 
    +
    594  };
    +
    595 
    +
    596  /** @brief Test class for rest of model cases
    +
    597  */
    + +
    599  {
    +
    600  public:
    + +
    602  unsigned char* res2 = new unsigned char[12 + 5];
    + +
    604  Markov::Model<unsigned char> m;
    +
    605  Markov::Node<unsigned char>* starter = m.StarterNode();
    +
    606  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
    +
    607  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
    +
    608  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
    +
    609  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
    +
    610  starter->Link(a)->AdjustEdge(1);
    +
    611  a->Link(b)->AdjustEdge(1);
    +
    612  b->Link(c)->AdjustEdge(1);
    +
    613  c->Link(end)->AdjustEdge(1);
    +
    614 
    +
    615  char* res = (char*)m.RandomWalk(&MarsagliaRandomEngine,1,12,res2);
    +
    616  Assert::IsFalse(strcmp(res, "abc"));
    +
    617  }
    + +
    619  Markov::Model<unsigned char> m;
    +
    620  Markov::Node<unsigned char>* starter = m.StarterNode();
    +
    621  Markov::Node<unsigned char>* a = new Markov::Node<unsigned char>('a');
    +
    622  Markov::Node<unsigned char>* b = new Markov::Node<unsigned char>('b');
    +
    623  Markov::Node<unsigned char>* c = new Markov::Node<unsigned char>('c');
    +
    624  Markov::Node<unsigned char>* end = new Markov::Node<unsigned char>(0xff);
    +
    625  Markov::Edge<unsigned char>* res = NULL;
    +
    626  starter->Link(a)->AdjustEdge(1);
    +
    627  a->Link(b)->AdjustEdge(1);
    +
    628  b->Link(c)->AdjustEdge(1);
    +
    629  c->Link(end)->AdjustEdge(1);
    630 
    -
    631  }
    -
    632 
    -
    633  /** @brief Testing namespace for MarkovPasswords
    -
    634  */
    -
    635  namespace MarkovPasswords {
    +
    631  res = starter->FindEdge('D');
    +
    632  Assert::IsNull(res);
    +
    633 
    +
    634  }
    +
    635  };
    636 
    -
    637  };
    +
    637  }
    638 
    -
    639 }
    +
    639  /** @brief Testing namespace for MarkovPasswords
    +
    640  */
    +
    641  namespace MarkovPasswords {
    +
    642 
    +
    643  };
    +
    644 
    +
    645 }
    -
    TEST_CLASS(ArgParser)
    Test Class for Argparse class.
    Definition: UnitTests.cpp:389
    -
    Testing namespace for MarkovPasswords.
    Definition: UnitTests.cpp:635
    -
    Testing Namespace for Minimal Viable Product.
    Definition: UnitTests.cpp:14
    -
    Namespace for Microsoft Native Unit Testing Classes.
    Definition: UnitTests.cpp:10
    -
    TEST_CLASS(Model)
    Test class for rest of model cases.
    Definition: UnitTests.cpp:592
    -
    TEST_CLASS(Model)
    Test class for minimal viable Model.
    Definition: UnitTests.cpp:347
    +
    TEST_CLASS(ArgParser)
    Test Class for Argparse class.
    Definition: UnitTests.cpp:395
    +
    Testing namespace for MarkovPasswords.
    Definition: UnitTests.cpp:641
    +
    Testing Namespace for Minimal Viable Product.
    Definition: UnitTests.cpp:20
    +
    Namespace for Microsoft Native Unit Testing Classes.
    Definition: UnitTests.cpp:16
    +
    TEST_CLASS(Model)
    Test class for rest of model cases.
    Definition: UnitTests.cpp:598
    +
    TEST_CLASS(Model)
    Test class for minimal viable Model.
    Definition: UnitTests.cpp:353
    + +

    About page. +More...

    #include <QtWidgets/QMainWindow>
    #include "ui_about.h"
    #include <ui_menu.h>
    @@ -98,12 +101,21 @@
    - +
    +
    +This graph shows which files directly or indirectly include this file:
    +
    +
    + + + + +

    Go to the source code of this file.

    @@ -122,13 +134,18 @@
     namespace for MarkovPasswords API GUI wrapper
     
    -
    +

    Detailed Description

    +

    About page.

    +
    Authors
    Yunus Emre Yılmaz
    + +

    Definition in file about.h.

    +
    -Go to the documentation of this file.
    1 #pragma once
    -
    2 #include <QtWidgets/QMainWindow>
    -
    3 #include "ui_about.h"
    -
    4 #include <ui_menu.h>
    -
    5 
    -
    6 /** @brief namespace for MarkovPasswords API GUI wrapper
    -
    7 */
    -
    8 namespace Markov::GUI{
    -
    9 
    -
    10  /** @brief QT Class for about page
    -
    11  */
    -
    12  class about :public QMainWindow {
    -
    13  Q_OBJECT
    -
    14  public:
    - -
    16 
    -
    17  private:
    -
    18  Ui:: main ui;
    -
    19 
    -
    20 
    -
    21  };
    -
    22 };
    +Go to the documentation of this file.
    1 /** @file about.h
    +
    2  * @brief About page
    +
    3  * @authors Yunus Emre Yılmaz
    +
    4  *
    +
    5  */
    +
    6 
    +
    7 #pragma once
    +
    8 #include <QtWidgets/QMainWindow>
    +
    9 #include "ui_about.h"
    +
    10 #include <ui_menu.h>
    +
    11 
    +
    12 /** @brief namespace for MarkovPasswords API GUI wrapper
    +
    13 */
    +
    14 namespace Markov::GUI{
    +
    15 
    +
    16  /** @brief QT Class for about page
    +
    17  */
    +
    18  class about :public QMainWindow {
    +
    19  Q_OBJECT
    +
    20  public:
    +
    21  about(QWidget* parent = Q_NULLPTR);
    +
    22 
    +
    23  private:
    +
    24  Ui:: main ui;
    +
    25 
    +
    26 
    +
    27  };
    +
    28 };
    -
    namespace for MarkovPasswords API GUI wrapper
    Definition: menu.h:6
    -
    about(QWidget *parent=Q_NULLPTR)
    -
    Ui::main ui
    Definition: about.h:18
    +
    QT Class for about page.
    Definition: about.h:18
    +
    namespace for MarkovPasswords API GUI wrapper
    Definition: about.h:14
    +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    +
    about(QWidget *parent=Q_NULLPTR)
    Definition: about.cpp:14
    +
    Ui::main ui
    Definition: about.h:24
    @@ -127,7 +129,7 @@
    + +

    Arguement handler class for native CPP cli. +More...

    #include "argparse.h"
    #include "color/term.h"
    @@ -94,9 +97,9 @@
    - - - + + + @@ -105,13 +108,19 @@

    Go to the source code of this file.

    -
    +

    Detailed Description

    +

    Arguement handler class for native CPP cli.

    +
    Authors
    Celal Sahir Çetiner
    +

    Parse command line arguements.

    + +

    Definition in file argparse.cpp.

    +
    -Go to the documentation of this file.
    1 #include "argparse.h"
    -
    2 #include "color/term.h"
    -
    3 
    -
    4 Markov::API::CLI::ProgramOptions* Markov::API::CLI::Argparse::parse(int argc, char** argv) { return 0; }
    -
    5 
    -
    6 
    +Go to the documentation of this file.
    1 /** @file argparse.cpp
    +
    2  * @brief Arguement handler class for native CPP cli
    +
    3  * @authors Celal Sahir Çetiner
    +
    4  *
    +
    5  * @copydoc Markov::API::CLI::Argparse
    +
    6  */
    7 
    -
    8 void Markov::API::CLI::Argparse::help() {
    -
    9  std::cout <<
    -
    10  "Markov Passwords - Help\n"
    -
    11  "Options:\n"
    -
    12  " \n"
    -
    13  " -of --outputfilename\n"
    -
    14  " Filename to output the generation results\n"
    -
    15  " -ef --exportfilename\n"
    -
    16  " filename to export built model to\n"
    -
    17  " -if --importfilename\n"
    -
    18  " filename to import model from\n"
    -
    19  " -n (generate count)\n"
    -
    20  " Number of lines to generate\n"
    -
    21  " \n"
    -
    22  "Usage: \n"
    -
    23  " markov.exe -if empty_model.mdl -ef model.mdl\n"
    -
    24  " import empty_model.mdl and train it with data from stdin. When done, output the model to model.mdl\n"
    -
    25  "\n"
    -
    26  " markov.exe -if empty_model.mdl -n 15000 -of wordlist.txt\n"
    -
    27  " import empty_model.mdl and generate 15000 words to wordlist.txt\n"
    -
    28 
    -
    29  << std::endl;
    -
    30 }
    +
    8 #include "argparse.h"
    +
    9 #include "color/term.h"
    +
    10 
    +
    11 Markov::API::CLI::ProgramOptions* Markov::API::CLI::Argparse::parse(int argc, char** argv) { return 0; }
    +
    12 
    +
    13 
    +
    14 
    +
    15 void Markov::API::CLI::Argparse::help() {
    +
    16  std::cout <<
    +
    17  "Markov Passwords - Help\n"
    +
    18  "Options:\n"
    +
    19  " \n"
    +
    20  " -of --outputfilename\n"
    +
    21  " Filename to output the generation results\n"
    +
    22  " -ef --exportfilename\n"
    +
    23  " filename to export built model to\n"
    +
    24  " -if --importfilename\n"
    +
    25  " filename to import model from\n"
    +
    26  " -n (generate count)\n"
    +
    27  " Number of lines to generate\n"
    +
    28  " \n"
    +
    29  "Usage: \n"
    +
    30  " markov.exe -if empty_model.mdl -ef model.mdl\n"
    +
    31  " import empty_model.mdl and train it with data from stdin. When done, output the model to model.mdl\n"
    +
    32  "\n"
    +
    33  " markov.exe -if empty_model.mdl -n 15000 -of wordlist.txt\n"
    +
    34  " import empty_model.mdl and generate 15000 words to wordlist.txt\n"
    +
    35 
    +
    36  << std::endl;
    +
    37 }
    -
    Parse command line arguements.
    Definition: argparse.h:74
    -
    static void help()
    Print help string.
    Definition: argparse.cpp:8
    -
    static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
    parse cli commands and return
    Definition: argparse.cpp:4
    -
    Structure to hold parsed cli arguements.
    Definition: argparse.h:15
    +
    Namespace for the MarkovPasswords API.
    +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    +
    Parse command line arguements.
    Definition: argparse.h:82
    +
    static void help()
    Print help string.
    Definition: argparse.cpp:15
    +
    static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
    parse cli commands and return
    Definition: argparse.cpp:11
    +
    Structure to hold parsed cli arguements.
    Definition: argparse.h:23
    + +

    Arguement handler class for native CPP cli. +More...

    #include <string>
    #include <iostream>
    #include <boost/program_options.hpp>
    @@ -100,7 +103,7 @@
    - + @@ -111,9 +114,9 @@
    - - - + + +
    @@ -142,8 +145,10 @@ - - + + + +

    Macros

    #define BOOST_ALL_DYN_LINK   1
     
    #define BOOST_ALL_STATIC_LIB   1
     
    #define BOOST_PROGRAM_OPTIONS_STATIC_LIB   1
     
    @@ -151,20 +156,41 @@

    Typedefs

     Structure to hold parsed cli arguements. More...
     
    -

    Macro Definition Documentation

    - -

    ◆ BOOST_ALL_DYN_LINK

    +

    Detailed Description

    +

    Arguement handler class for native CPP cli.

    +
    Authors
    Celal Sahir Çetiner
    + +

    Definition in file argparse.h.

    +

    Macro Definition Documentation

    + +

    ◆ BOOST_ALL_STATIC_LIB

    + +
    +
    + + + + +
    #define BOOST_ALL_STATIC_LIB   1
    +
    + +

    Definition at line 11 of file argparse.h.

    + +
    +
    + +

    ◆ BOOST_PROGRAM_OPTIONS_STATIC_LIB

    - +
    #define BOOST_ALL_DYN_LINK   1#define BOOST_PROGRAM_OPTIONS_STATIC_LIB   1
    -

    Definition at line 4 of file argparse.h.

    +

    Definition at line 12 of file argparse.h.

    @@ -173,8 +199,8 @@

    diff --git a/docs/dark/argparse_8h.js b/docs/dark/argparse_8h.js index 5feaa3e9..421eee60 100644 --- a/docs/dark/argparse_8h.js +++ b/docs/dark/argparse_8h.js @@ -2,6 +2,7 @@ var argparse_8h = [ [ "_programOptions", "struct_markov_1_1_a_p_i_1_1_c_l_i_1_1__program_options.html", "struct_markov_1_1_a_p_i_1_1_c_l_i_1_1__program_options" ], [ "Argparse", "class_markov_1_1_a_p_i_1_1_c_l_i_1_1_argparse.html", "class_markov_1_1_a_p_i_1_1_c_l_i_1_1_argparse" ], - [ "BOOST_ALL_DYN_LINK", "argparse_8h.html#a8df2553ea80556a445530460433ac2f5", null ], + [ "BOOST_ALL_STATIC_LIB", "argparse_8h.html#aaf8a1a195131e697ef0e215c1ca4f7cb", null ], + [ "BOOST_PROGRAM_OPTIONS_STATIC_LIB", "argparse_8h.html#ab42d174f6325cddd11a7bf6cedf74ca7", null ], [ "ProgramOptions", "argparse_8h.html#acdf1c80e63d183095fe2956cc38bf042", null ] ]; \ No newline at end of file diff --git a/docs/dark/argparse_8h__dep__incl.map b/docs/dark/argparse_8h__dep__incl.map index d1846805..15718da3 100644 --- a/docs/dark/argparse_8h__dep__incl.map +++ b/docs/dark/argparse_8h__dep__incl.map @@ -1,5 +1,5 @@ - - - + + + diff --git a/docs/dark/argparse_8h__dep__incl.md5 b/docs/dark/argparse_8h__dep__incl.md5 index 9d0d957b..20baa86f 100644 --- a/docs/dark/argparse_8h__dep__incl.md5 +++ b/docs/dark/argparse_8h__dep__incl.md5 @@ -1 +1 @@ -793b33124273e6cdd4846bdaa1538e5e \ No newline at end of file +88caa1975e22e00cf0e86f88a235513f \ No newline at end of file diff --git a/docs/dark/argparse_8h__incl.map b/docs/dark/argparse_8h__incl.map index a76b58f8..a547ffd8 100644 --- a/docs/dark/argparse_8h__incl.map +++ b/docs/dark/argparse_8h__incl.map @@ -1,5 +1,5 @@ - + diff --git a/docs/dark/argparse_8h__incl.md5 b/docs/dark/argparse_8h__incl.md5 index 2065cb27..8201fac0 100644 --- a/docs/dark/argparse_8h__incl.md5 +++ b/docs/dark/argparse_8h__incl.md5 @@ -1 +1 @@ -d0ed9af54c498004fdc482e6d2a8c754 \ No newline at end of file +6057c550842d8ba4ffcfbc6cf82b6fca \ No newline at end of file diff --git a/docs/dark/argparse_8h_source.html b/docs/dark/argparse_8h_source.html index 06cc7d25..e0cfa8a3 100644 --- a/docs/dark/argparse_8h_source.html +++ b/docs/dark/argparse_8h_source.html @@ -87,283 +87,293 @@
    argparse.h

    -Go to the documentation of this file.
    1 #include<string>
    -
    2 #include<iostream>
    -
    3 
    -
    4 #define BOOST_ALL_DYN_LINK 1
    -
    5 
    -
    6 #include <boost/program_options.hpp>
    +Go to the documentation of this file.
    1 /** @file argparse.h
    +
    2  * @brief Arguement handler class for native CPP cli
    +
    3  * @authors Celal Sahir Çetiner
    +
    4  *
    +
    5  * @copydoc Markov::API::CLI::Argparse:
    +
    6  */
    7 
    -
    8 /** @brief Structure to hold parsed cli arguements.
    -
    9 */
    -
    10 namespace opt = boost::program_options;
    -
    11 
    -
    12 /**
    -
    13  @brief Namespace for the CLI objects
    -
    14 */
    -
    15 namespace Markov::API::CLI{
    -
    16 
    -
    17  /** @brief Structure to hold parsed cli arguements. */
    -
    18  typedef struct _programOptions {
    -
    19  /**
    -
    20  @brief Import flag to validate import
    -
    21  */
    -
    22  bool bImport;
    -
    23 
    -
    24  /**
    -
    25  @brief Export flag to validate export
    -
    26  */
    -
    27  bool bExport;
    -
    28 
    -
    29  /**
    -
    30  @brief Failure flag to validate succesfull running
    -
    31  */
    -
    32  bool bFailure;
    -
    33 
    -
    34  /**
    -
    35  @brief Seperator character to use with training data. (character between occurence and value)"
    -
    36  */
    -
    37  char seperator;
    -
    38 
    -
    39  /**
    -
    40  @brief Import name of our model
    -
    41  */
    -
    42  std::string importname;
    -
    43 
    -
    44  /**
    -
    45  @brief Import name of our given wordlist
    -
    46  */
    -
    47  std::string exportname;
    -
    48 
    -
    49  /**
    -
    50  @brief Import name of our given wordlist
    -
    51  */
    -
    52  std::string wordlistname;
    -
    53 
    -
    54  /**
    -
    55  @brief Output name of our generated password list
    -
    56  */
    -
    57  std::string outputfilename;
    -
    58 
    -
    59  /**
    -
    60  @brief The name of the given dataset
    -
    61  */
    -
    62  std::string datasetname;
    -
    63 
    -
    64  /**
    -
    65  @brief Number of passwords to be generated
    -
    66  */
    -
    67  int generateN;
    -
    68 
    -
    69  } ProgramOptions;
    -
    70 
    +
    8 #include<string>
    +
    9 #include<iostream>
    +
    10 
    +
    11 #define BOOST_ALL_STATIC_LIB 1
    +
    12 #define BOOST_PROGRAM_OPTIONS_STATIC_LIB 1
    +
    13 
    +
    14 #include <boost/program_options.hpp>
    +
    15 
    +
    16 /** @brief Structure to hold parsed cli arguements.
    +
    17 */
    +
    18 namespace opt = boost::program_options;
    +
    19 
    +
    20 /**
    +
    21  @brief Namespace for the CLI objects
    +
    22 */
    +
    23 namespace Markov::API::CLI{
    +
    24 
    +
    25  /** @brief Structure to hold parsed cli arguements. */
    +
    26  typedef struct _programOptions {
    +
    27  /**
    +
    28  @brief Import flag to validate import
    +
    29  */
    +
    30  bool bImport;
    +
    31 
    +
    32  /**
    +
    33  @brief Export flag to validate export
    +
    34  */
    +
    35  bool bExport;
    +
    36 
    +
    37  /**
    +
    38  @brief Failure flag to validate succesfull running
    +
    39  */
    +
    40  bool bFailure;
    +
    41 
    +
    42  /**
    +
    43  @brief Seperator character to use with training data. (character between occurence and value)"
    +
    44  */
    +
    45  char seperator;
    +
    46 
    +
    47  /**
    +
    48  @brief Import name of our model
    +
    49  */
    +
    50  std::string importname;
    +
    51 
    +
    52  /**
    +
    53  @brief Import name of our given wordlist
    +
    54  */
    +
    55  std::string exportname;
    +
    56 
    +
    57  /**
    +
    58  @brief Import name of our given wordlist
    +
    59  */
    +
    60  std::string wordlistname;
    +
    61 
    +
    62  /**
    +
    63  @brief Output name of our generated password list
    +
    64  */
    +
    65  std::string outputfilename;
    +
    66 
    +
    67  /**
    +
    68  @brief The name of the given dataset
    +
    69  */
    +
    70  std::string datasetname;
    71 
    -
    72  /** @brief Parse command line arguements
    -
    73  */
    -
    74  class Argparse {
    -
    75  public:
    +
    72  /**
    +
    73  @brief Number of passwords to be generated
    +
    74  */
    +
    75  int generateN;
    76 
    -
    77  Argparse();
    +
    77  } ProgramOptions;
    78 
    -
    79  /** @brief Parse command line arguements.
    -
    80  *
    -
    81  * Parses command line arguements to populate ProgramOptions structure.
    -
    82  *
    -
    83  * @param argc Number of command line arguements
    -
    84  * @param argv Array of command line parameters
    -
    85  */
    -
    86  Argparse(int argc, char** argv) {
    -
    87 
    -
    88  /*bool bImp;
    -
    89  bool bExp;
    -
    90  bool bFail;
    -
    91  char sprt;
    -
    92  std::string imports;
    -
    93  std::string exports;
    -
    94  std::string outputs;
    -
    95  std::string datasets;
    -
    96  int generateN;
    -
    97  */
    -
    98  opt::options_description desc("Options");
    -
    99 
    -
    100 
    -
    101  desc.add_options()
    -
    102  ("generate", "Generate strings with given parameters")
    -
    103  ("train", "Train model with given parameters")
    -
    104  ("combine", "Combine")
    -
    105  ("import", opt::value<std::string>(), "Import model file")
    -
    106  ("output", opt::value<std::string>(), "Output model file. This model will be exported when done. Will be ignored for generation mode")
    -
    107  ("dataset", opt::value<std::string>(), "Dataset file to read input from training. Will be ignored for generation mode")
    -
    108  ("seperator", opt::value<char>(), "Seperator character to use with training data. (character between occurence and value)")
    -
    109  ("wordlist", opt::value<std::string>(), "Wordlist file path to export generation results to. Will be ignored for training mode")
    -
    110  ("count", opt::value<int>(), "Number of lines to generate. Ignored in training mode")
    -
    111  ("verbosity", "Output verbosity")
    -
    112  ("help", "Option definitions");
    -
    113 
    -
    114  opt::variables_map vm;
    -
    115 
    -
    116  opt::store(opt::parse_command_line(argc, argv, desc), vm);
    -
    117 
    -
    118  opt::notify(vm);
    -
    119 
    -
    120  //std::cout << desc << std::endl;
    -
    121  if (vm.count("help")) {
    -
    122  std::cout << desc << std::endl;
    -
    123  }
    -
    124 
    -
    125  if (vm.count("output") == 0) this->po.outputfilename = "NULL";
    -
    126  else if (vm.count("output") == 1) {
    -
    127  this->po.outputfilename = vm["output"].as<std::string>();
    -
    128  this->po.bExport = true;
    -
    129  }
    -
    130  else {
    -
    131  this->po.bFailure = true;
    -
    132  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    -
    133  std::cout << desc << std::endl;
    -
    134  }
    -
    135 
    -
    136 
    -
    137  if (vm.count("dataset") == 0) this->po.datasetname = "NULL";
    -
    138  else if (vm.count("dataset") == 1) {
    -
    139  this->po.datasetname = vm["dataset"].as<std::string>();
    -
    140  }
    -
    141  else {
    -
    142  this->po.bFailure = true;
    -
    143  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    -
    144  std::cout << desc << std::endl;
    -
    145  }
    -
    146 
    -
    147 
    -
    148  if (vm.count("wordlist") == 0) this->po.wordlistname = "NULL";
    -
    149  else if (vm.count("wordlist") == 1) {
    -
    150  this->po.wordlistname = vm["wordlist"].as<std::string>();
    -
    151  }
    -
    152  else {
    -
    153  this->po.bFailure = true;
    -
    154  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    -
    155  std::cout << desc << std::endl;
    -
    156  }
    -
    157 
    -
    158  if (vm.count("import") == 0) this->po.importname = "NULL";
    -
    159  else if (vm.count("import") == 1) {
    -
    160  this->po.importname = vm["import"].as<std::string>();
    -
    161  this->po.bImport = true;
    -
    162  }
    -
    163  else {
    -
    164  this->po.bFailure = true;
    -
    165  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    -
    166  std::cout << desc << std::endl;
    -
    167  }
    -
    168 
    -
    169 
    -
    170  if (vm.count("count") == 0) this->po.generateN = 0;
    -
    171  else if (vm.count("count") == 1) {
    -
    172  this->po.generateN = vm["count"].as<int>();
    -
    173  }
    -
    174  else {
    -
    175  this->po.bFailure = true;
    -
    176  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    -
    177  std::cout << desc << std::endl;
    -
    178  }
    -
    179 
    -
    180  /*std::cout << vm["output"].as<std::string>() << std::endl;
    -
    181  std::cout << vm["dataset"].as<std::string>() << std::endl;
    -
    182  std::cout << vm["wordlist"].as<std::string>() << std::endl;
    -
    183  std::cout << vm["output"].as<std::string>() << std::endl;
    -
    184  std::cout << vm["count"].as<int>() << std::endl;*/
    -
    185 
    -
    186 
    -
    187  //else if (vm.count("train")) std::cout << "train oldu" << std::endl;
    -
    188  }
    -
    189 
    -
    190  /** @brief Getter for command line options
    -
    191  *
    -
    192  * Getter for ProgramOptions populated by the arguement parser
    -
    193  * @returns ProgramOptions structure.
    -
    194  */
    -
    195  Markov::API::CLI::ProgramOptions getProgramOptions(void) {
    -
    196  return this->po;
    -
    197  }
    -
    198 
    -
    199  /** @brief Initialize program options structure.
    -
    200  *
    -
    201  * @param i boolean, true if import operation is flagged
    -
    202  * @param e boolean, true if export operation is flagged
    -
    203  * @param bf boolean, true if there is something wrong with the command line parameters
    -
    204  * @param s seperator character for the import function
    -
    205  * @param iName import filename
    -
    206  * @param exName export filename
    -
    207  * @param oName output filename
    -
    208  * @param dName corpus filename
    -
    209  * @param n number of passwords to be generated
    -
    210  *
    -
    211  */
    -
    212  void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n) {
    -
    213  this->po.bImport = i;
    -
    214  this->po.bExport = e;
    -
    215  this->po.seperator = s;
    -
    216  this->po.bFailure = bf;
    -
    217  this->po.generateN = n;
    -
    218  this->po.importname = iName;
    -
    219  this->po.exportname = exName;
    -
    220  this->po.outputfilename = oName;
    -
    221  this->po.datasetname = dName;
    -
    222 
    -
    223  /*strcpy_s(this->po.importname,256,iName);
    -
    224  strcpy_s(this->po.exportname,256,exName);
    -
    225  strcpy_s(this->po.outputfilename,256,oName);
    -
    226  strcpy_s(this->po.datasetname,256,dName);*/
    -
    227 
    -
    228  }
    -
    229 
    -
    230  /** @brief parse cli commands and return
    -
    231  * @param argc - Program arguement count
    -
    232  * @param argv - Program arguement values array
    -
    233  * @return ProgramOptions structure.
    -
    234  */
    -
    235  static Markov::API::CLI::ProgramOptions* parse(int argc, char** argv);
    -
    236 
    +
    79 
    +
    80  /** @brief Parse command line arguements
    +
    81  */
    +
    82  class Argparse {
    +
    83  public:
    +
    84 
    +
    85  Argparse();
    +
    86 
    +
    87  /** @brief Parse command line arguements.
    +
    88  *
    +
    89  * Parses command line arguements to populate ProgramOptions structure.
    +
    90  *
    +
    91  * @param argc Number of command line arguements
    +
    92  * @param argv Array of command line parameters
    +
    93  */
    +
    94  Argparse(int argc, char** argv) {
    +
    95 
    +
    96  /*bool bImp;
    +
    97  bool bExp;
    +
    98  bool bFail;
    +
    99  char sprt;
    +
    100  std::string imports;
    +
    101  std::string exports;
    +
    102  std::string outputs;
    +
    103  std::string datasets;
    +
    104  int generateN;
    +
    105  */
    +
    106  opt::options_description desc("Options");
    +
    107 
    +
    108 
    +
    109  desc.add_options()
    +
    110  ("generate", "Generate strings with given parameters")
    +
    111  ("train", "Train model with given parameters")
    +
    112  ("combine", "Combine")
    +
    113  ("import", opt::value<std::string>(), "Import model file")
    +
    114  ("output", opt::value<std::string>(), "Output model file. This model will be exported when done. Will be ignored for generation mode")
    +
    115  ("dataset", opt::value<std::string>(), "Dataset file to read input from training. Will be ignored for generation mode")
    +
    116  ("seperator", opt::value<char>(), "Seperator character to use with training data. (character between occurence and value)")
    +
    117  ("wordlist", opt::value<std::string>(), "Wordlist file path to export generation results to. Will be ignored for training mode")
    +
    118  ("count", opt::value<int>(), "Number of lines to generate. Ignored in training mode")
    +
    119  ("verbosity", "Output verbosity")
    +
    120  ("help", "Option definitions");
    +
    121 
    +
    122  opt::variables_map vm;
    +
    123 
    +
    124  opt::store(opt::parse_command_line(argc, argv, desc), vm);
    +
    125 
    +
    126  opt::notify(vm);
    +
    127 
    +
    128  //std::cout << desc << std::endl;
    +
    129  if (vm.count("help")) {
    +
    130  std::cout << desc << std::endl;
    +
    131  }
    +
    132 
    +
    133  if (vm.count("output") == 0) this->po.outputfilename = "NULL";
    +
    134  else if (vm.count("output") == 1) {
    +
    135  this->po.outputfilename = vm["output"].as<std::string>();
    +
    136  this->po.bExport = true;
    +
    137  }
    +
    138  else {
    +
    139  this->po.bFailure = true;
    +
    140  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    +
    141  std::cout << desc << std::endl;
    +
    142  }
    +
    143 
    +
    144 
    +
    145  if (vm.count("dataset") == 0) this->po.datasetname = "NULL";
    +
    146  else if (vm.count("dataset") == 1) {
    +
    147  this->po.datasetname = vm["dataset"].as<std::string>();
    +
    148  }
    +
    149  else {
    +
    150  this->po.bFailure = true;
    +
    151  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    +
    152  std::cout << desc << std::endl;
    +
    153  }
    +
    154 
    +
    155 
    +
    156  if (vm.count("wordlist") == 0) this->po.wordlistname = "NULL";
    +
    157  else if (vm.count("wordlist") == 1) {
    +
    158  this->po.wordlistname = vm["wordlist"].as<std::string>();
    +
    159  }
    +
    160  else {
    +
    161  this->po.bFailure = true;
    +
    162  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    +
    163  std::cout << desc << std::endl;
    +
    164  }
    +
    165 
    +
    166  if (vm.count("import") == 0) this->po.importname = "NULL";
    +
    167  else if (vm.count("import") == 1) {
    +
    168  this->po.importname = vm["import"].as<std::string>();
    +
    169  this->po.bImport = true;
    +
    170  }
    +
    171  else {
    +
    172  this->po.bFailure = true;
    +
    173  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    +
    174  std::cout << desc << std::endl;
    +
    175  }
    +
    176 
    +
    177 
    +
    178  if (vm.count("count") == 0) this->po.generateN = 0;
    +
    179  else if (vm.count("count") == 1) {
    +
    180  this->po.generateN = vm["count"].as<int>();
    +
    181  }
    +
    182  else {
    +
    183  this->po.bFailure = true;
    +
    184  std::cout << "UNIDENTIFIED INPUT" << std::endl;
    +
    185  std::cout << desc << std::endl;
    +
    186  }
    +
    187 
    +
    188  /*std::cout << vm["output"].as<std::string>() << std::endl;
    +
    189  std::cout << vm["dataset"].as<std::string>() << std::endl;
    +
    190  std::cout << vm["wordlist"].as<std::string>() << std::endl;
    +
    191  std::cout << vm["output"].as<std::string>() << std::endl;
    +
    192  std::cout << vm["count"].as<int>() << std::endl;*/
    +
    193 
    +
    194 
    +
    195  //else if (vm.count("train")) std::cout << "train oldu" << std::endl;
    +
    196  }
    +
    197 
    +
    198  /** @brief Getter for command line options
    +
    199  *
    +
    200  * Getter for ProgramOptions populated by the arguement parser
    +
    201  * @returns ProgramOptions structure.
    +
    202  */
    +
    203  Markov::API::CLI::ProgramOptions getProgramOptions(void) {
    +
    204  return this->po;
    +
    205  }
    +
    206 
    +
    207  /** @brief Initialize program options structure.
    +
    208  *
    +
    209  * @param i boolean, true if import operation is flagged
    +
    210  * @param e boolean, true if export operation is flagged
    +
    211  * @param bf boolean, true if there is something wrong with the command line parameters
    +
    212  * @param s seperator character for the import function
    +
    213  * @param iName import filename
    +
    214  * @param exName export filename
    +
    215  * @param oName output filename
    +
    216  * @param dName corpus filename
    +
    217  * @param n number of passwords to be generated
    +
    218  *
    +
    219  */
    +
    220  void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n) {
    +
    221  this->po.bImport = i;
    +
    222  this->po.bExport = e;
    +
    223  this->po.seperator = s;
    +
    224  this->po.bFailure = bf;
    +
    225  this->po.generateN = n;
    +
    226  this->po.importname = iName;
    +
    227  this->po.exportname = exName;
    +
    228  this->po.outputfilename = oName;
    +
    229  this->po.datasetname = dName;
    +
    230 
    +
    231  /*strcpy_s(this->po.importname,256,iName);
    +
    232  strcpy_s(this->po.exportname,256,exName);
    +
    233  strcpy_s(this->po.outputfilename,256,oName);
    +
    234  strcpy_s(this->po.datasetname,256,dName);*/
    +
    235 
    +
    236  }
    237 
    -
    238  /** @brief Print help string.
    -
    239  */
    -
    240  static void help();
    -
    241 
    -
    242  private:
    -
    243  /**
    -
    244  @brief ProgramOptions structure object
    -
    245  */
    -
    246 
    -
    247  Markov::API::CLI::ProgramOptions po;
    -
    248  };
    +
    238  /** @brief parse cli commands and return
    +
    239  * @param argc - Program arguement count
    +
    240  * @param argv - Program arguement values array
    +
    241  * @return ProgramOptions structure.
    +
    242  */
    +
    243  static Markov::API::CLI::ProgramOptions* parse(int argc, char** argv);
    +
    244 
    +
    245 
    +
    246  /** @brief Print help string.
    +
    247  */
    +
    248  static void help();
    249 
    -
    250 };
    +
    250  private:
    +
    251  /**
    +
    252  @brief ProgramOptions structure object
    +
    253  */
    +
    254 
    +
    255  Markov::API::CLI::ProgramOptions po;
    +
    256  };
    +
    257 
    +
    258 };
    -
    std::string importname
    Import name of our model.
    Definition: argparse.h:42
    -
    bool bExport
    Export flag to validate export
    Definition: argparse.h:27
    -
    void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n)
    Initialize program options structure.
    Definition: argparse.h:212
    -
    std::string exportname
    Import name of our given wordlist
    Definition: argparse.h:47
    -
    bool bImport
    Import flag to validate import
    Definition: argparse.h:22
    -
    char seperator
    Seperator character to use with training data. (character between occurence and value)"
    Definition: argparse.h:37
    -
    int generateN
    Number of passwords to be generated
    Definition: argparse.h:67
    -
    bool bFailure
    Failure flag to validate succesfull running
    Definition: argparse.h:32
    -
    Argparse(int argc, char **argv)
    Parse command line arguements.
    Definition: argparse.h:86
    -
    Structure to hold parsed cli arguements.
    Definition: argparse.h:18
    -
    Markov::API::CLI::ProgramOptions getProgramOptions(void)
    Getter for command line options.
    Definition: argparse.h:195
    -
    std::string wordlistname
    Import name of our given wordlist
    Definition: argparse.h:52
    -
    Parse command line arguements.
    Definition: argparse.h:74
    -
    static void help()
    Print help string.
    Definition: argparse.cpp:8
    -
    std::string outputfilename
    Output name of our generated password list
    Definition: argparse.h:57
    -
    static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
    parse cli commands and return
    Definition: argparse.cpp:4
    -
    std::string datasetname
    The name of the given dataset
    Definition: argparse.h:62
    +
    std::string importname
    Import name of our model.
    Definition: argparse.h:50
    +
    bool bExport
    Export flag to validate export
    Definition: argparse.h:35
    +
    void setProgramOptions(bool i, bool e, bool bf, char s, std::string iName, std::string exName, std::string oName, std::string dName, int n)
    Initialize program options structure.
    Definition: argparse.h:220
    +
    std::string exportname
    Import name of our given wordlist
    Definition: argparse.h:55
    +
    Namespace for the MarkovPasswords API.
    +
    bool bImport
    Import flag to validate import
    Definition: argparse.h:30
    +
    char seperator
    Seperator character to use with training data. (character between occurence and value)"
    Definition: argparse.h:45
    +
    int generateN
    Number of passwords to be generated
    Definition: argparse.h:75
    +
    Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
    Definition: model.h:24
    +
    bool bFailure
    Failure flag to validate succesfull running
    Definition: argparse.h:40
    +
    Argparse(int argc, char **argv)
    Parse command line arguements.
    Definition: argparse.h:94
    +
    Structure to hold parsed cli arguements.
    Definition: argparse.h:26
    +
    Markov::API::CLI::ProgramOptions getProgramOptions(void)
    Getter for command line options.
    Definition: argparse.h:203
    +
    std::string wordlistname
    Import name of our given wordlist
    Definition: argparse.h:60
    +
    Parse command line arguements.
    Definition: argparse.h:82
    +
    static void help()
    Print help string.
    Definition: argparse.cpp:15
    +
    std::string outputfilename
    Output name of our generated password list
    Definition: argparse.h:65
    +
    static Markov::API::CLI::ProgramOptions * parse(int argc, char **argv)
    parse cli commands and return
    Definition: argparse.cpp:11
    +
    std::string datasetname
    The name of the given dataset
    Definition: argparse.h:70
    -
    Structure to hold parsed cli arguements.
    Definition: argparse.h:15
    -
    Markov::API::CLI::ProgramOptions po
    ProgramOptions structure object.
    Definition: argparse.h:247
    +
    Structure to hold parsed cli arguements.
    Definition: argparse.h:23
    +
    Markov::API::CLI::ProgramOptions po
    ProgramOptions structure object.
    Definition: argparse.h:255
    @@ -242,9 +241,9 @@

    {Terminal::color::RESET, 0},
    }
    -

    Definition at line 32 of file term.h.

    +

    Definition at line 39 of file term.h.

    -

    Referenced by operator<<().

    +

    Referenced by operator<<().

    @@ -268,7 +267,7 @@

    -

    Definition at line 37 of file term.h.

    +

    Definition at line 44 of file term.h.

    @@ -278,23 +277,23 @@

    @ WHITE
    Definition: term.h:26
    - - - - - - - - - - - + + + + + + + + + + + +
    + +

    Buff expression of some characters in the model.

    +
    Parameters
    + + + + + +
    strA string containing all the characters to be buffed
    multiplierA constant value to buff the nodes with.
    bDontAdjustSelfEdgesDo not adjust weights if target node is same as source node
    bDontAdjustExtendedLoopsDo not adjust if both source and target nodes are in first parameter
    +
    +
    + +

    Definition at line 153 of file markovPasswords.cpp.

    +
    153  {
    +
    154  std::string buffstr(str);
    +
    155  std::map< char, Node< char > * > *nodes;
    +
    156  std::map< char, Edge< char > * > *edges;
    +
    157  nodes = this->Nodes();
    +
    158  int i=0;
    +
    159  for (auto const& [repr, node] : *nodes){
    +
    160  edges = node->Edges();
    +
    161  for (auto const& [targetrepr, edge] : *edges){
    +
    162  if(buffstr.find(targetrepr)!= std::string::npos){
    +
    163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
    +
    164  if(bDontAdjustExtendedLoops){
    +
    165  if(buffstr.find(repr)!= std::string::npos){
    +
    166  continue;
    +
    167  }
    +
    168  }
    +
    169  long int weight = edge->EdgeWeight();
    +
    170  weight = weight*multiplier;
    +
    171  edge->AdjustEdge(weight);
    +
    172  }
    +
    173 
    +
    174  }
    +
    175  i++;
    +
    176  }
    +
    177 
    +
    178  this->OptimizeEdgeOrder();
    +
    179 }
    +
    +

    References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().

    + +

    Referenced by main().

    +
    +Here is the call graph for this function:
    +
    +
    + + + + + + + + +
    +
    +Here is the caller graph for this function:
    +
    +
    + + + + +
    +
    @@ -496,60 +643,60 @@

    Node.

    Returns
    True if constructed. False if already construced.
    -

    Definition at line 22 of file modelMatrix.cpp.

    -
    22  {
    -
    23  if(this->ready) return false;
    -
    24  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
    -
    25 
    -
    26  this->matrixIndex = new char[this->matrixSize];
    -
    27  this->totalEdgeWeights = new long int[this->matrixSize];
    -
    28 
    -
    29  this->edgeMatrix = new char*[this->matrixSize];
    -
    30  for(int i=0;i<this->matrixSize;i++){
    -
    31  this->edgeMatrix[i] = new char[this->matrixSize];
    -
    32  }
    -
    33  this->valueMatrix = new long int*[this->matrixSize];
    -
    34  for(int i=0;i<this->matrixSize;i++){
    -
    35  this->valueMatrix[i] = new long int[this->matrixSize];
    -
    36  }
    -
    37  std::map< char, Node< char > * > *nodes;
    -
    38  nodes = this->Nodes();
    -
    39  int i=0;
    -
    40  for (auto const& [repr, node] : *nodes){
    -
    41  if(repr!=0) this->matrixIndex[i] = repr;
    -
    42  else this->matrixIndex[i] = 199;
    -
    43  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
    -
    44  for(int j=0;j<this->matrixSize;j++){
    -
    45  char val = node->NodeValue();
    -
    46  if(val < 0){
    -
    47  for(int k=0;k<this->matrixSize;k++){
    -
    48  this->valueMatrix[i][k] = 0;
    -
    49  this->edgeMatrix[i][k] = 255;
    -
    50  }
    -
    51  break;
    -
    52  }
    -
    53  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
    -
    54  this->valueMatrix[i][j] = 0;
    -
    55  this->edgeMatrix[i][j] = 255;
    -
    56  }else if(j==(this->matrixSize-1)) {
    -
    57  this->valueMatrix[i][j] = 0;
    -
    58  this->edgeMatrix[i][j] = 255;
    -
    59  }else{
    -
    60  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
    -
    61  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
    -
    62  }
    -
    63 
    -
    64  }
    -
    65  i++;
    -
    66  }
    -
    67  this->ready = true;
    -
    68  return true;
    -
    69  //this->DumpJSON();
    -
    70 }
    +

    Definition at line 31 of file modelMatrix.cpp.

    +
    31  {
    +
    32  if(this->ready) return false;
    +
    33  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
    +
    34 
    +
    35  this->matrixIndex = new char[this->matrixSize];
    +
    36  this->totalEdgeWeights = new long int[this->matrixSize];
    +
    37 
    +
    38  this->edgeMatrix = new char*[this->matrixSize];
    +
    39  for(int i=0;i<this->matrixSize;i++){
    +
    40  this->edgeMatrix[i] = new char[this->matrixSize];
    +
    41  }
    +
    42  this->valueMatrix = new long int*[this->matrixSize];
    +
    43  for(int i=0;i<this->matrixSize;i++){
    +
    44  this->valueMatrix[i] = new long int[this->matrixSize];
    +
    45  }
    +
    46  std::map< char, Node< char > * > *nodes;
    +
    47  nodes = this->Nodes();
    +
    48  int i=0;
    +
    49  for (auto const& [repr, node] : *nodes){
    +
    50  if(repr!=0) this->matrixIndex[i] = repr;
    +
    51  else this->matrixIndex[i] = 199;
    +
    52  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
    +
    53  for(int j=0;j<this->matrixSize;j++){
    +
    54  char val = node->NodeValue();
    +
    55  if(val < 0){
    +
    56  for(int k=0;k<this->matrixSize;k++){
    +
    57  this->valueMatrix[i][k] = 0;
    +
    58  this->edgeMatrix[i][k] = 255;
    +
    59  }
    +
    60  break;
    +
    61  }
    +
    62  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
    +
    63  this->valueMatrix[i][j] = 0;
    +
    64  this->edgeMatrix[i][j] = 255;
    +
    65  }else if(j==(this->matrixSize-1)) {
    +
    66  this->valueMatrix[i][j] = 0;
    +
    67  this->edgeMatrix[i][j] = 255;
    +
    68  }else{
    +
    69  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
    +
    70  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
    +
    71  }
    +
    72 
    +
    73  }
    +
    74  i++;
    +
    75  }
    +
    76  this->ready = true;
    +
    77  return true;
    +
    78  //this->DumpJSON();
    +
    79 }
    -

    References Markov::API::ModelMatrix::edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), Markov::API::ModelMatrix::ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::API::ModelMatrix::totalEdgeWeights, Markov::Node< storageType >::TotalEdgeWeights(), and Markov::API::ModelMatrix::valueMatrix.

    +

    References Markov::API::ModelMatrix::edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), Markov::API::ModelMatrix::ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::Node< storageType >::TotalEdgeWeights(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

    -

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

    +

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

    Here is the call graph for this function:
    @@ -573,14 +720,14 @@

    - +

    - -

    ◆ CudaCheckNotifyErr()

    + +

    ◆ CudaCheckNotifyErr()

    @@ -589,7 +736,7 @@

    - + @@ -597,7 +744,7 @@

    - + @@ -630,9 +777,22 @@

    Returns
    0 if successful, 1 if failure. Example output:
    char *da, a = "test";
    cudastatus = cudaMalloc((char **)&da, 5*sizeof(char*));
    -
    CudaCheckNotifyErr(cudastatus, "Failed to allocate VRAM for *da.\n");
    +
    CudaCheckNotifyErr(cudastatus, "Failed to allocate VRAM for *da.\n");
    +

    Definition at line 32 of file cudaDeviceController.cu.

    +
    32  {
    +
    33  if (_status != cudaSuccess) {
    +
    34  std::cerr << "\033[1;31m" << msg << " -> " << cudaGetErrorString(_status) << " ("<< _status << ")" << "\033[0m" << "\n";
    +
    35 
    +
    36  if(bExit) {
    +
    37  cudaDeviceReset();
    +
    38  exit(1);
    +
    39  }
    +
    40  }
    +
    41  return 0;
    +
    42  }
    +
    @@ -692,17 +852,17 @@

    char* dst;
    cudastatus = CudaMalloc2DToFlat<char>(&dst, 5, 15);
    if(cudastatus!=cudaSuccess){
    -
    CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
    +
    CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
    }
    -

    Definition at line 73 of file cudaDeviceController.h.

    -
    73  {
    -
    74  cudaError_t cudastatus = cudaMalloc((T **)dst, row*col*sizeof(T));
    -
    75  CudaCheckNotifyErr(cudastatus, "cudaMalloc Failed.", false);
    -
    76  return cudastatus;
    -
    77  }
    +

    Definition at line 75 of file cudaDeviceController.h.

    +
    75  {
    +
    76  cudaError_t cudastatus = cudaMalloc((T **)dst, row*col*sizeof(T));
    +
    77  CudaCheckNotifyErr(cudastatus, "cudaMalloc Failed.", false);
    +
    78  return cudastatus;
    +
    79  }
    -

    References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    +

    References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    Here is the call graph for this function:
    @@ -778,21 +938,21 @@

    cudaError_t cudastatus;
    char* dst;
    cudastatus = CudaMalloc2DToFlat<char>(&dst, 5, 15);
    -
    CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
    +
    CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
    cudastatus = CudaMemcpy2DToFlat<char>(*dst,src,15,15);
    -
    CudaCheckNotifyErr(cudastatus, " CudaMemcpy2DToFlat Failed.", false);
    +
    CudaCheckNotifyErr(cudastatus, " CudaMemcpy2DToFlat Failed.", false);

    -

    Definition at line 101 of file cudaDeviceController.h.

    -
    101  {
    -
    102  T* tempbuf = new T[row*col];
    -
    103  for(int i=0;i<row;i++){
    -
    104  memcpy(&(tempbuf[row*i]), src[i], col);
    -
    105  }
    -
    106  return cudaMemcpy(dst, tempbuf, row*col*sizeof(T), cudaMemcpyHostToDevice);
    -
    107 
    -
    108  }
    +

    Definition at line 103 of file cudaDeviceController.h.

    +
    103  {
    +
    104  T* tempbuf = new T[row*col];
    +
    105  for(int i=0;i<row;i++){
    +
    106  memcpy(&(tempbuf[row*i]), src[i], col);
    +
    107  }
    +
    108  return cudaMemcpy(dst, tempbuf, row*col*sizeof(T), cudaMemcpyHostToDevice);
    +
    109 
    +
    110  }
    -

    References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    +

    References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    Here is the call graph for this function:
    @@ -869,24 +1029,24 @@

    char* dst;

    cudastatus = CudaMigrate2DFlat<long int>(
    -
    CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize value matrix row.");
    +
    CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize value matrix row.");
    -

    Definition at line 130 of file cudaDeviceController.h.

    -
    130  {
    -
    131  cudaError_t cudastatus;
    -
    132  cudastatus = CudaMalloc2DToFlat<T>(dst, row, col);
    -
    133  if(cudastatus!=cudaSuccess){
    -
    134  CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
    -
    135  return cudastatus;
    -
    136  }
    -
    137  cudastatus = CudaMemcpy2DToFlat<T>(*dst,src,row,col);
    -
    138  CudaCheckNotifyErr(cudastatus, " CudaMemcpy2DToFlat Failed.", false);
    -
    139  return cudastatus;
    -
    140  }
    +

    Definition at line 132 of file cudaDeviceController.h.

    +
    132  {
    +
    133  cudaError_t cudastatus;
    +
    134  cudastatus = CudaMalloc2DToFlat<T>(dst, row, col);
    +
    135  if(cudastatus!=cudaSuccess){
    +
    136  CudaCheckNotifyErr(cudastatus, " CudaMalloc2DToFlat Failed.", false);
    +
    137  return cudastatus;
    +
    138  }
    +
    139  cudastatus = CudaMemcpy2DToFlat<T>(*dst,src,row,col);
    +
    140  CudaCheckNotifyErr(cudastatus, " CudaMemcpy2DToFlat Failed.", false);
    +
    141  return cudastatus;
    +
    142  }
    -

    References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    +

    References Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    -

    Referenced by Markov::API::CUDA::CUDADeviceController::CudaMalloc2DToFlat(), Markov::API::CUDA::CUDADeviceController::CudaMemcpy2DToFlat(), and Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    +

    Referenced by Markov::API::CUDA::CUDADeviceController::CudaMalloc2DToFlat(), Markov::API::CUDA::CUDADeviceController::CudaMemcpy2DToFlat(), and Markov::API::CUDA::CUDADeviceController::CudaMigrate2DFlat().

    Here is the call graph for this function:
    @@ -934,40 +1094,40 @@

    Returns
    True if deallocated. False if matrix was not initialized
    -

    Definition at line 72 of file modelMatrix.cpp.

    -
    72  {
    -
    73  if(!this->ready) return false;
    -
    74  delete[] this->matrixIndex;
    -
    75  delete[] this->totalEdgeWeights;
    -
    76 
    -
    77  for(int i=0;i<this->matrixSize;i++){
    -
    78  delete[] this->edgeMatrix[i];
    -
    79  }
    -
    80  delete[] this->edgeMatrix;
    -
    81 
    -
    82  for(int i=0;i<this->matrixSize;i++){
    -
    83  delete[] this->valueMatrix[i];
    -
    84  }
    -
    85  delete[] this->valueMatrix;
    -
    86 
    -
    87  this->matrixSize = -1;
    -
    88  this->ready = false;
    -
    89  return true;
    -
    90 }
    +

    Definition at line 81 of file modelMatrix.cpp.

    +
    81  {
    +
    82  if(!this->ready) return false;
    +
    83  delete[] this->matrixIndex;
    +
    84  delete[] this->totalEdgeWeights;
    +
    85 
    +
    86  for(int i=0;i<this->matrixSize;i++){
    +
    87  delete[] this->edgeMatrix[i];
    +
    88  }
    +
    89  delete[] this->edgeMatrix;
    +
    90 
    +
    91  for(int i=0;i<this->matrixSize;i++){
    +
    92  delete[] this->valueMatrix[i];
    +
    93  }
    +
    94  delete[] this->valueMatrix;
    +
    95 
    +
    96  this->matrixSize = -1;
    +
    97  this->ready = false;
    +
    98  return true;
    +
    99 }
    -

    References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::API::ModelMatrix::ready, Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

    +

    References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::API::ModelMatrix::ready, Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

    -

    Referenced by Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

    +

    Referenced by Markov::API::ModelMatrix::Import(), and Markov::API::ModelMatrix::Train().

    Here is the caller graph for this function:
    - - - - + + + +
    @@ -999,61 +1159,61 @@

    Definition at line 92 of file modelMatrix.cpp.

    -
    92  {
    -
    93 
    -
    94  std::cout << "{\n \"index\": \"";
    -
    95  for(int i=0;i<this->matrixSize;i++){
    -
    96  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
    -
    97  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
    -
    98  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
    -
    99  else if(i==0) std::cout << "\\\\xff";
    -
    100  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
    -
    101  else std::cout << this->matrixIndex[i];
    -
    102  }
    -
    103  std::cout <<
    -
    104  "\",\n"
    -
    105  " \"edgemap\": {\n";
    -
    106 
    -
    107  for(int i=0;i<this->matrixSize;i++){
    -
    108  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
    -
    109  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
    -
    110  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
    -
    111  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
    -
    112  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
    -
    113  for(int j=0;j<this->matrixSize;j++){
    -
    114  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
    -
    115  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
    -
    116  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
    -
    117  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
    -
    118  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
    -
    119  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
    -
    120  if(j!=this->matrixSize-1) std::cout << ", ";
    -
    121  }
    -
    122  std::cout << "],\n";
    -
    123  }
    -
    124  std::cout << "},\n";
    -
    125 
    -
    126  std::cout << "\" weightmap\": {\n";
    -
    127  for(int i=0;i<this->matrixSize;i++){
    -
    128  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
    -
    129  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
    -
    130  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
    -
    131  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
    -
    132  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
    -
    133 
    -
    134  for(int j=0;j<this->matrixSize;j++){
    -
    135  std::cout << this->valueMatrix[i][j];
    -
    136  if(j!=this->matrixSize-1) std::cout << ", ";
    -
    137  }
    -
    138  std::cout << "],\n";
    -
    139  }
    -
    140  std::cout << " }\n}\n";
    -
    141 }
    +

    Definition at line 101 of file modelMatrix.cpp.

    +
    101  {
    +
    102 
    +
    103  std::cout << "{\n \"index\": \"";
    +
    104  for(int i=0;i<this->matrixSize;i++){
    +
    105  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
    +
    106  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
    +
    107  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
    +
    108  else if(i==0) std::cout << "\\\\xff";
    +
    109  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
    +
    110  else std::cout << this->matrixIndex[i];
    +
    111  }
    +
    112  std::cout <<
    +
    113  "\",\n"
    +
    114  " \"edgemap\": {\n";
    +
    115 
    +
    116  for(int i=0;i<this->matrixSize;i++){
    +
    117  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
    +
    118  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
    +
    119  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
    +
    120  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
    +
    121  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
    +
    122  for(int j=0;j<this->matrixSize;j++){
    +
    123  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
    +
    124  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
    +
    125  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
    +
    126  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
    +
    127  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
    +
    128  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
    +
    129  if(j!=this->matrixSize-1) std::cout << ", ";
    +
    130  }
    +
    131  std::cout << "],\n";
    +
    132  }
    +
    133  std::cout << "},\n";
    +
    134 
    +
    135  std::cout << "\" weightmap\": {\n";
    +
    136  for(int i=0;i<this->matrixSize;i++){
    +
    137  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
    +
    138  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
    +
    139  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
    +
    140  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
    +
    141  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
    +
    142 
    +
    143  for(int j=0;j<this->matrixSize;j++){
    +
    144  std::cout << this->valueMatrix[i][j];
    +
    145  if(j!=this->matrixSize-1) std::cout << ", ";
    +
    146  }
    +
    147  std::cout << "],\n";
    +
    148  }
    +
    149  std::cout << " }\n}\n";
    +
    150 }
    -

    References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, and Markov::API::ModelMatrix::valueMatrix.

    +

    References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, and Markov::API::ModelMatrix::valueMatrix.

    -

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

    +

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

    Here is the caller graph for this function:
    @@ -1076,7 +1236,7 @@

    static __host__ int Markov::API::CUDA::CUDADeviceController::CudaCheckNotifyErr __host__ int Markov::API::CUDA::CUDADeviceController::CudaCheckNotifyErr ( cudaError_t  _status, const char * const char msg,
    - + @@ -1092,8 +1252,8 @@

    Returns
    vector of edges
    -

    Definition at line 172 of file model.h.

    -
    172 { return &edges;}
    +

    Definition at line 176 of file model.h.

    +
    176 { return &edges;}
    @@ -1107,9 +1267,9 @@

    std::vector<Edge<char >*>* Markov::Model< char >::Edges std::vector<Edge<char >*>* Markov::Model< char >::Edges ( )
    - + - + @@ -1123,15 +1283,15 @@

    Model::Export with std::ofstream.

    Returns
    True if successful, False for incomplete models or corrupt file formats
    -

    Example Use: Export file to filename

    -
    model.Export("test.mdl");
    +

    Example Use: Export file to filename

    +
    model.Export("test.mdl");
    -

    Definition at line 286 of file model.h.

    -
    286  {
    -
    287  std::ofstream exportfile;
    -
    288  exportfile.open(filename);
    -
    289  return this->Export(&exportfile);
    -
    290 }
    +

    Definition at line 300 of file model.h.

    +
    300  {
    +
    301  std::ofstream exportfile;
    +
    302  exportfile.open(filename);
    +
    303  return this->Export(&exportfile);
    +
    304 }
    @@ -1145,7 +1305,7 @@

    bool Markov::Model< char >::Export bool Markov::Model< char >::Export (const char * const char filename)
    - + @@ -1162,26 +1322,26 @@

    Returns
    True if successful, False for incomplete models.
    -

    Example Use: Export file to ofstream

    +

    Example Use: Export file to ofstream

    std::ofstream file("test.mdl");
    -
    model.Export(&file);
    +
    model.Export(&file);
    -

    Definition at line 274 of file model.h.

    -
    274  {
    - -
    276  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
    -
    277  e = this->edges[i];
    -
    278  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
    -
    279  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
    -
    280  }
    -
    281 
    -
    282  return true;
    -
    283 }
    +

    Definition at line 288 of file model.h.

    +
    288  {
    + +
    290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
    +
    291  e = this->edges[i];
    +
    292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
    +
    293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
    +
    294  }
    +
    295 
    +
    296  return true;
    +
    297 }
    - -

    ◆ FastRandomWalk() [1/2]

    + +

    ◆ FastRandomWalk() [1/3]

    @@ -1195,7 +1355,7 @@

    - + @@ -1214,7 +1374,13 @@

    - + + + + + + + @@ -1239,12 +1405,102 @@

    mp.Import("models/finished.mdl");
    -
    mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
    +
    mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
    +

    Definition at line 58 of file cudaModelMatrix.cu.

    +
    58  {
    +
    59  cudaDeviceProp prop;
    +
    60  int device=0;
    +
    61  cudaGetDeviceProperties(&prop, device);
    +
    62  cudaChooseDevice(&device, &prop);
    +
    63  //std::cout << "Flattening matrix." << std::endl;
    +
    64  this->FlattenMatrix();
    +
    65  //std::cout << "Migrating matrix." << std::endl;
    +
    66  this->MigrateMatrix();
    +
    67  //std::cout << "Migrated matrix." << std::endl;
    +
    68  std::ofstream wordlist;
    +
    69  if(bFileIO)
    +
    70  wordlist.open(wordlistFileName);
    +
    71 
    +
    72 
    +
    73  cudaBlocks = 1024;
    +
    74  cudaThreads = 256;
    + + + + + + + + +
    83  this->prepKernelMemoryChannel(alternatingKernels);
    +
    84 
    +
    85  unsigned long int leftover = n - (totalOutputPerSync*numberOfPartitions);
    +
    86 
    +
    87  if(bInfinite && !numberOfPartitions) numberOfPartitions=5;
    +
    88  std::cerr << cudaPerKernelAllocationSize << "\n";
    +
    89 
    +
    90  if(n%totalOutputPerSync) std::cerr << "For optimization, request outputs muliples of "<< totalOutputPerSync << ".\n";
    +
    91 
    +
    92  //start kernelID 1
    +
    93  this->LaunchAsyncKernel(1, minLen, maxLen);
    +
    94 
    +
    95  for(int i=1;i<numberOfPartitions;i++){
    +
    96  if(bInfinite) i=0;
    +
    97 
    +
    98  //wait kernelID1 to finish, and start kernelID 0
    +
    99  cudaStreamSynchronize(this->cudastreams[1]);
    +
    100  this->LaunchAsyncKernel(0, minLen, maxLen);
    +
    101 
    +
    102  //start memcpy from kernel 1 (block until done)
    +
    103  this->GatherAsyncKernelOutput(1, bFileIO, wordlist);
    +
    104 
    +
    105  //wait kernelID 0 to finish, then start kernelID1
    +
    106  cudaStreamSynchronize(this->cudastreams[0]);
    +
    107  this->LaunchAsyncKernel(1, minLen, maxLen);
    +
    108 
    +
    109  //start memcpy from kernel 0 (block until done)
    +
    110  this->GatherAsyncKernelOutput(0, bFileIO, wordlist);
    +
    111 
    +
    112  }
    +
    113 
    +
    114  //wait kernelID1 to finish, and start kernelID 0
    +
    115  cudaStreamSynchronize(this->cudastreams[1]);
    +
    116  this->LaunchAsyncKernel(0, minLen, maxLen);
    +
    117  this->GatherAsyncKernelOutput(1, bFileIO, wordlist);
    +
    118  cudaStreamSynchronize(this->cudastreams[0]);
    +
    119  this->GatherAsyncKernelOutput(0, bFileIO, wordlist);
    +
    120 
    +
    121 
    +
    122  if(!leftover) return;
    + +
    124  std::cerr << "Remaining line count (" << leftover << ") is lower than partition. Adjusting CUDA workload..\n";
    +
    125  this->iterationsPerKernelThread = leftover/cudaGridSize;
    +
    126  this->LaunchAsyncKernel(0, minLen, maxLen);
    +
    127  cudaStreamSynchronize(this->cudastreams[0]);
    +
    128  this->GatherAsyncKernelOutput(0, bFileIO, wordlist);
    +
    129 
    +
    130  leftover -= this->iterationsPerKernelThread*cudaGridSize;
    +
    131  if(!leftover) return;
    +
    132 
    +
    133  std::cerr << "Remaining line count (" << leftover << ") is lower than minimum possible. Handing over to CPU generation.\n";
    +
    134  this->iterationsPerKernelThread = leftover/cudaGridSize;
    +
    135 
    +
    136  leftover -= this->iterationsPerKernelThread;
    +
    137 
    +
    138  if(!leftover) return;
    +
    139  std::cerr << "Remaining " << leftover << " lines are absolutely not worth printing.\n";
    + +
    141  Markov::API::ModelMatrix::FastRandomWalk(leftover, &wordlist, minLen, maxLen, 1, bFileIO);
    +
    142 
    +
    143  }
    +
    +

    References alternatingKernels, cudaBlocks, cudaGridSize, cudaMemPerGrid, cudaPerKernelAllocationSize, cudaThreads, iterationsPerKernelThread, numberOfPartitions, totalOutputPerKernel, and totalOutputPerSync.

    + - -

    ◆ FastRandomWalk() [2/2]

    + +

    ◆ FastRandomWalk() [2/3]

    @@ -1253,7 +1509,7 @@

    bool Markov::Model< char >::Export bool Markov::Model< char >::Export ( std::ofstream *  f) const char * const char wordlistFileName,
    bool bFileIO bFileIO,
    bool bInfinite 
    - + @@ -1261,7 +1517,7 @@

    - + @@ -1319,35 +1575,144 @@

    mp.Import("models/finished.mdl");
    -
    mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
    +
    mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
    + +

    Definition at line 217 of file modelMatrix.cpp.

    +
    217  {
    +
    218  std::ofstream wordlist;
    +
    219  if(bFileIO)
    +
    220  wordlist.open(wordlistFileName);
    +
    221  this->FastRandomWalk(n, &wordlist, minLen, maxLen, threads, bFileIO);
    +
    222  return 0;
    +
    223 }
    +
    +

    References Markov::API::ModelMatrix::FastRandomWalk().

    + +

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

    +
    +Here is the call graph for this function:
    +
    +
    + + + + + + + +
    +
    +Here is the caller graph for this function:
    +
    +
    + + + + +
    + + + + +

    ◆ FastRandomWalk() [3/3]

    + +
    +
    +
    void Markov::API::ModelMatrix::FastRandomWalk int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n, const char * const char wordlistFileName,
    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    int Markov::API::ModelMatrix::FastRandomWalk (unsigned long int n,
    std::ofstream * wordlist,
    int minLen = 6,
    int maxLen = 12,
    int threads = 20,
    bool bFileIO = true 
    )
    +
    +protectedinherited
    +

    + +

    Random walk on the Matrix-reduced Markov::Model.

    +

    This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

    +

    If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

    +

    While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

    +

    This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

    +
    Parameters
    + + + + + + + +
    n- Number of passwords to generate.
    wordlistFileName- Filename to write to
    minLen- Minimum password length to generate
    maxLen- Maximum password length to generate
    threads- number of OS threads to spawn
    bFileIO- If false, filename will be ignored and will output to stdout.
    +
    +
    +
    +
    mp.Import("models/finished.mdl");
    +
    mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
    -

    Definition at line 195 of file modelMatrix.cpp.

    -
    195  {
    -
    196 
    -
    197 
    -
    198  std::ofstream wordlist;
    -
    199  if(bFileIO)
    -
    200  wordlist.open(wordlistFileName);
    -
    201 
    -
    202  std::mutex mlock;
    -
    203  if(n<=50000000ull) return this->FastRandomWalkPartition(&mlock, &wordlist, n, minLen, maxLen, bFileIO, threads);
    -
    204  else{
    -
    205  int numberOfPartitions = n/50000000ull;
    -
    206  for(int i=0;i<numberOfPartitions;i++)
    -
    207  this->FastRandomWalkPartition(&mlock, &wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
    -
    208  }
    -
    209 
    -
    210 
    -
    211 }
    +

    Definition at line 204 of file modelMatrix.cpp.

    +
    204  {
    +
    205 
    +
    206 
    +
    207  std::mutex mlock;
    +
    208  if(n<=50000000ull) this->FastRandomWalkPartition(&mlock, wordlist, n, minLen, maxLen, bFileIO, threads);
    +
    209  else{
    +
    210  int numberOfPartitions = n/50000000ull;
    +
    211  for(int i=0;i<numberOfPartitions;i++)
    +
    212  this->FastRandomWalkPartition(&mlock, wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
    +
    213  }
    +
    214  return 0;
    +
    215 }
    -

    References Markov::API::ModelMatrix::FastRandomWalkPartition().

    +

    References Markov::API::ModelMatrix::FastRandomWalkPartition().

    -

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

    +

    Referenced by Markov::API::ModelMatrix::FastRandomWalk().

    Here is the call graph for this function:
    -
    - +
    + @@ -1357,9 +1722,10 @@

    Here is the caller graph for this function:

    -
    - - +
    + + +
    @@ -1451,30 +1817,30 @@

    Definition at line 214 of file modelMatrix.cpp.

    -
    214  {
    -
    215 
    -
    216  int iterationsPerThread = n/threads;
    -
    217  int iterationsPerThreadCarryOver = n%threads;
    -
    218 
    -
    219  std::vector<std::thread*> threadsV;
    -
    220 
    -
    221  int id = 0;
    -
    222  for(int i=0;i<threads;i++){
    -
    223  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
    -
    224  id++;
    -
    225  }
    -
    226 
    -
    227  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
    -
    228 
    -
    229  for(int i=0;i<threads;i++){
    -
    230  threadsV[i]->join();
    -
    231  }
    -
    232 }
    +

    Definition at line 225 of file modelMatrix.cpp.

    +
    225  {
    +
    226 
    +
    227  int iterationsPerThread = n/threads;
    +
    228  int iterationsPerThreadCarryOver = n%threads;
    +
    229 
    +
    230  std::vector<std::thread*> threadsV;
    +
    231 
    +
    232  int id = 0;
    +
    233  for(int i=0;i<threads;i++){
    +
    234  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
    +
    235  id++;
    +
    236  }
    +
    237 
    +
    238  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
    +
    239 
    +
    240  for(int i=0;i<threads;i++){
    +
    241  threadsV[i]->join();
    +
    242  }
    +
    243 }
    -

    References Markov::API::ModelMatrix::FastRandomWalkThread().

    +

    References Markov::API::ModelMatrix::FastRandomWalkThread().

    -

    Referenced by Markov::API::ModelMatrix::FastRandomWalk().

    +

    Referenced by Markov::API::ModelMatrix::FastRandomWalk().

    Here is the call graph for this function:
    @@ -1490,8 +1856,9 @@

    - - + + +

    @@ -1579,60 +1946,60 @@

    Definition at line 144 of file modelMatrix.cpp.

    -
    144  {
    -
    145  if(n==0) return;
    -
    146 
    -
    147  Markov::Random::Marsaglia MarsagliaRandomEngine;
    -
    148  char* e;
    -
    149  char *res = new char[maxLen*n];
    -
    150  int index = 0;
    -
    151  char next;
    -
    152  int len=0;
    -
    153  long int selection;
    -
    154  char cur;
    -
    155  long int bufferctr = 0;
    -
    156  for (int i = 0; i < n; i++) {
    -
    157  cur=199;
    -
    158  len=0;
    -
    159  while (true) {
    -
    160  e = strchr(this->matrixIndex, cur);
    -
    161  index = e - this->matrixIndex;
    -
    162  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
    -
    163  for(int j=0;j<this->matrixSize;j++){
    -
    164  selection -= this->valueMatrix[index][j];
    -
    165  if (selection < 0){
    -
    166  next = this->edgeMatrix[index][j];
    -
    167  break;
    -
    168  }
    -
    169  }
    -
    170 
    -
    171  if (len >= maxLen) break;
    -
    172  else if ((next < 0) && (len < minLen)) continue;
    -
    173  else if (next < 0) break;
    -
    174  cur = next;
    -
    175  res[bufferctr + len++] = cur;
    -
    176  }
    -
    177  res[bufferctr + len++] = '\n';
    -
    178  bufferctr+=len;
    -
    179 
    -
    180  }
    -
    181  if(bFileIO){
    -
    182  mlock->lock();
    -
    183  *wordlist << res;
    -
    184  mlock->unlock();
    -
    185  }else{
    -
    186  mlock->lock();
    -
    187  std::cout << res;
    -
    188  mlock->unlock();
    +

    Definition at line 153 of file modelMatrix.cpp.

    +
    153  {
    +
    154  if(n==0) return;
    +
    155 
    +
    156  Markov::Random::Marsaglia MarsagliaRandomEngine;
    +
    157  char* e;
    +
    158  char *res = new char[(maxLen+2)*n];
    +
    159  int index = 0;
    +
    160  char next;
    +
    161  int len=0;
    +
    162  long int selection;
    +
    163  char cur;
    +
    164  long int bufferctr = 0;
    +
    165  for (int i = 0; i < n; i++) {
    +
    166  cur=199;
    +
    167  len=0;
    +
    168  while (true) {
    +
    169  e = strchr(this->matrixIndex, cur);
    +
    170  index = e - this->matrixIndex;
    +
    171  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
    +
    172  for(int j=0;j<this->matrixSize;j++){
    +
    173  selection -= this->valueMatrix[index][j];
    +
    174  if (selection < 0){
    +
    175  next = this->edgeMatrix[index][j];
    +
    176  break;
    +
    177  }
    +
    178  }
    +
    179 
    +
    180  if (len >= maxLen) break;
    +
    181  else if ((next < 0) && (len < minLen)) continue;
    +
    182  else if (next < 0) break;
    +
    183  cur = next;
    +
    184  res[bufferctr + len++] = cur;
    +
    185  }
    +
    186  res[bufferctr + len++] = '\n';
    +
    187  bufferctr+=len;
    +
    188 
    189  }
    -
    190  delete res;
    -
    191 
    -
    192 }
    +
    190  if(bFileIO){
    +
    191  mlock->lock();
    +
    192  *wordlist << res;
    +
    193  mlock->unlock();
    +
    194  }else{
    +
    195  mlock->lock();
    +
    196  std::cout << res;
    +
    197  mlock->unlock();
    +
    198  }
    +
    199  delete res;
    +
    200 
    +
    201 }
    -

    References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Random::Marsaglia::random(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

    +

    References Markov::API::ModelMatrix::edgeMatrix, Markov::API::ModelMatrix::matrixIndex, Markov::API::ModelMatrix::matrixSize, Markov::Random::Marsaglia::random(), Markov::API::ModelMatrix::totalEdgeWeights, and Markov::API::ModelMatrix::valueMatrix.

    -

    Referenced by Markov::API::ModelMatrix::FastRandomWalkPartition().

    +

    Referenced by Markov::API::ModelMatrix::FastRandomWalkPartition().

    Here is the call graph for this function:
    @@ -1647,9 +2014,10 @@

    - - - + + + +

    @@ -1673,6 +2041,78 @@

    Definition at line 261 of file cudaModelMatrix.cu.

    +
    261  {
    +
    262  this->flatEdgeMatrix = new char[this->matrixSize*this->matrixSize];
    +
    263 
    +
    264  this->flatValueMatrix = new long int[this->matrixSize*this->matrixSize];
    +
    265  for(int i=0;i<this->matrixSize;i++){
    +
    266  memcpy(&this->flatEdgeMatrix[i*this->matrixSize], this->edgeMatrix[i], this->matrixSize );
    +
    267  memcpy(&this->flatValueMatrix[i*this->matrixSize], this->valueMatrix[i], this->matrixSize*sizeof(long int) );
    +
    268  }
    +
    269  }
    +
    +

    References flatEdgeMatrix, flatValueMatrix, and Markov::API::ModelMatrix::matrixSize.

    + +

    +

    + +

    ◆ GatherAsyncKernelOutput()

    + +
    +
    + + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    __host__ void Markov::API::CUDA::CUDAModelMatrix::GatherAsyncKernelOutput (int kernelID,
    bool bFileIO,
    std::ofstream & wordlist 
    )
    +
    +protected
    +
    + +

    Definition at line 180 of file cudaModelMatrix.cu.

    +
    180  {
    +
    181  cudaMemcpy(this->outputBuffer[kernelID],this->device_outputBuffer[kernelID],cudaPerKernelAllocationSize, cudaMemcpyDeviceToHost);
    +
    182  //std::cerr << "Kernel" << kernelID << " output copied\n";
    +
    183  if(bFileIO){
    +
    184  for(long int j=0;j<cudaPerKernelAllocationSize;j+=cudaMemPerGrid){
    +
    185  wordlist << &this->outputBuffer[kernelID][j];
    +
    186  }
    +
    187  }else{
    +
    188  for(long int j=0;j<cudaPerKernelAllocationSize;j+=cudaMemPerGrid){
    +
    189  std::cout << &this->outputBuffer[kernelID][j];
    +
    190  }
    +
    191  }
    +
    192  }
    +
    +

    References cudaMemPerGrid, cudaPerKernelAllocationSize, and outputBuffer.

    +
    @@ -1693,7 +2133,7 @@

    - const char *  + const charwordlistFileName, @@ -1741,32 +2181,32 @@

    Definition at line 110 of file markovPasswords.cpp.

    -
    110  {
    -
    111  char* res;
    -
    112  char print[100];
    -
    113  std::ofstream wordlist;
    -
    114  wordlist.open(wordlistFileName);
    -
    115  std::mutex mlock;
    -
    116  int iterationsPerThread = n/threads;
    -
    117  int iterationsCarryOver = n%threads;
    -
    118  std::vector<std::thread*> threadsV;
    -
    119  for(int i=0;i<threads;i++){
    -
    120  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
    -
    121  }
    -
    122 
    -
    123  for(int i=0;i<threads;i++){
    -
    124  threadsV[i]->join();
    -
    125  delete threadsV[i];
    -
    126  }
    -
    127 
    -
    128  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
    -
    129 
    -
    130 }
    +

    Definition at line 118 of file markovPasswords.cpp.

    +
    118  {
    +
    119  char* res;
    +
    120  char print[100];
    +
    121  std::ofstream wordlist;
    +
    122  wordlist.open(wordlistFileName);
    +
    123  std::mutex mlock;
    +
    124  int iterationsPerThread = n/threads;
    +
    125  int iterationsCarryOver = n%threads;
    +
    126  std::vector<std::thread*> threadsV;
    +
    127  for(int i=0;i<threads;i++){
    +
    128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
    +
    129  }
    +
    130 
    +
    131  for(int i=0;i<threads;i++){
    +
    132  threadsV[i]->join();
    +
    133  delete threadsV[i];
    +
    134  }
    +
    135 
    +
    136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
    +
    137 
    +
    138 }
    -

    References Markov::API::MarkovPasswords::GenerateThread().

    +

    References Markov::API::MarkovPasswords::GenerateThread().

    -

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

    +

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

    Here is the call graph for this function:
    @@ -1782,8 +2222,9 @@

    - + +

    @@ -1854,23 +2295,23 @@

    Definition at line 132 of file markovPasswords.cpp.

    -
    132  {
    -
    133  char* res = new char[maxLen+5];
    -
    134  if(n==0) return;
    -
    135 
    -
    136  Markov::Random::Marsaglia MarsagliaRandomEngine;
    -
    137  for (int i = 0; i < n; i++) {
    -
    138  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
    -
    139  outputLock->lock();
    -
    140  *wordlist << res << "\n";
    -
    141  outputLock->unlock();
    -
    142  }
    -
    143 }
    +

    Definition at line 140 of file markovPasswords.cpp.

    +
    140  {
    +
    141  char* res = new char[maxLen+5];
    +
    142  if(n==0) return;
    +
    143 
    +
    144  Markov::Random::Marsaglia MarsagliaRandomEngine;
    +
    145  for (int i = 0; i < n; i++) {
    +
    146  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
    +
    147  outputLock->lock();
    +
    148  *wordlist << res << "\n";
    +
    149  outputLock->unlock();
    +
    150  }
    +
    151 }
    -

    References Markov::Model< NodeStorageType >::RandomWalk().

    +

    References Markov::Model< NodeStorageType >::RandomWalk().

    -

    Referenced by Markov::API::MarkovPasswords::Generate().

    +

    Referenced by Markov::API::MarkovPasswords::Generate().

    Here is the call graph for this function:
    @@ -1885,9 +2326,10 @@

    - - + + +

    @@ -1905,7 +2347,7 @@

    void Markov::API::ModelMatrix::Import ( - const char *  + const charfilename) @@ -1919,20 +2361,20 @@

    Model::Import with std::ifstream.

    Returns
    True if successful, False for incomplete models or corrupt file formats
    -

    Example Use: Import a file with filename

    -
    model.Import("test.mdl");
    +

    Example Use: Import a file with filename

    +
    model.Import("test.mdl");

    Construct the matrix when done.

    -

    Definition at line 10 of file modelMatrix.cpp.

    -
    10  {
    -
    11  this->DeallocateMatrix();
    - -
    13  this->ConstructMatrix();
    -
    14 }
    +

    Definition at line 19 of file modelMatrix.cpp.

    +
    19  {
    +
    20  this->DeallocateMatrix();
    + +
    22  this->ConstructMatrix();
    +
    23 }
    -

    References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

    +

    References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

    -

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

    +

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

    Here is the call graph for this function:
    @@ -1957,7 +2399,7 @@

    - +

    @@ -1973,7 +2415,7 @@

    - + @@ -1990,73 +2432,115 @@

    Returns
    True if successful, False for incomplete models or corrupt file formats
    -

    Example Use: Import a file from ifstream

    +

    Example Use: Import a file from ifstream

    std::ifstream file("test.mdl");
    -
    model.Import(&file);
    +
    model.Import(&file);
    -

    Definition at line 207 of file model.h.

    -
    207  {
    -
    208  std::string cell;
    -
    209 
    -
    210  char src;
    -
    211  char target;
    -
    212  long int oc;
    -
    213 
    -
    214  while (std::getline(*f, cell)) {
    -
    215  //std::cout << "cell: " << cell << std::endl;
    -
    216  src = cell[0];
    -
    217  target = cell[cell.length() - 1];
    -
    218  char* j;
    -
    219  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
    -
    220  //std::cout << oc << "\n";
    - - - -
    224  if (this->nodes.find(src) == this->nodes.end()) {
    -
    225  srcN = new Markov::Node<NodeStorageType>(src);
    -
    226  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
    -
    227  //std::cout << "Creating new node at start.\n";
    -
    228  }
    -
    229  else {
    -
    230  srcN = this->nodes.find(src)->second;
    -
    231  }
    -
    232 
    -
    233  if (this->nodes.find(target) == this->nodes.end()) {
    -
    234  targetN = new Markov::Node<NodeStorageType>(target);
    -
    235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
    -
    236  //std::cout << "Creating new node at end.\n";
    +

    Definition at line 216 of file model.h.

    +
    216  {
    +
    217  std::string cell;
    +
    218 
    +
    219  char src;
    +
    220  char target;
    +
    221  long int oc;
    +
    222 
    +
    223  while (std::getline(*f, cell)) {
    +
    224  //std::cout << "cell: " << cell << std::endl;
    +
    225  src = cell[0];
    +
    226  target = cell[cell.length() - 1];
    +
    227  char* j;
    +
    228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
    +
    229  //std::cout << oc << "\n";
    + + + +
    233  if (this->nodes.find(src) == this->nodes.end()) {
    +
    234  srcN = new Markov::Node<NodeStorageType>(src);
    +
    235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
    +
    236  //std::cout << "Creating new node at start.\n";
    237  }
    238  else {
    -
    239  targetN = this->nodes.find(target)->second;
    +
    239  srcN = this->nodes.find(src)->second;
    240  }
    -
    241  e = srcN->Link(targetN);
    -
    242  e->AdjustEdge(oc);
    -
    243  this->edges.push_back(e);
    -
    244 
    -
    245  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
    -
    246 
    -
    247 
    -
    248  }
    -
    249 
    -
    250  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
    -
    251  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
    -
    252  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
    -
    253  return lhs->EdgeWeight() > rhs->EdgeWeight();
    -
    254  });
    -
    255  //for(int i=0;i<x.second->edgesV.size();i++)
    -
    256  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
    -
    257  //std::cout << "\n";
    -
    258  }
    -
    259  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
    -
    260  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
    -
    261 
    -
    262  return true;
    -
    263 }
    +
    241 
    +
    242  if (this->nodes.find(target) == this->nodes.end()) {
    +
    243  targetN = new Markov::Node<NodeStorageType>(target);
    +
    244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
    +
    245  //std::cout << "Creating new node at end.\n";
    +
    246  }
    +
    247  else {
    +
    248  targetN = this->nodes.find(target)->second;
    +
    249  }
    +
    250  e = srcN->Link(targetN);
    +
    251  e->AdjustEdge(oc);
    +
    252  this->edges.push_back(e);
    +
    253 
    +
    254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
    +
    255 
    +
    256 
    +
    257  }
    +
    258 
    +
    259  this->OptimizeEdgeOrder();
    +
    260 
    +
    261  return true;
    +
    262 }
    +
    +
    +
    + +

    ◆ LaunchAsyncKernel()

    + +
    +
    +

    bool Markov::Model< char >::Import bool Markov::Model< char >::Import ( std::ifstream *  f)
    + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    __host__ void Markov::API::CUDA::CUDAModelMatrix::LaunchAsyncKernel (int kernelID,
    int minLen,
    int maxLen 
    )
    +
    +protected
    +

    + +

    Definition at line 171 of file cudaModelMatrix.cu.

    +
    171  {
    +
    172 
    +
    173  //if(kernelID == 0);// cudaStreamSynchronize(this->cudastreams[2]);
    +
    174  //else cudaStreamSynchronize(this->cudastreams[kernelID-1]);
    + + +
    177  //std::cerr << "Started kernel" << kernelID << "\n";
    +
    178  }
    - -

    ◆ ListCudaDevices()

    + +

    ◆ ListCudaDevices()

    @@ -2065,7 +2549,7 @@

    - + @@ -2087,6 +2571,23 @@

    Peak Memory Bandwidth (GB/s): 448.064
    Max Linear Threads: 1024
    +

    Definition at line 16 of file cudaDeviceController.cu.

    +
    16  { //list cuda Capable devices on host.
    +
    17  int nDevices;
    +
    18  cudaGetDeviceCount(&nDevices);
    +
    19  for (int i = 0; i < nDevices; i++) {
    +
    20  cudaDeviceProp prop;
    +
    21  cudaGetDeviceProperties(&prop, i);
    +
    22  std::cerr << "Device Number: " << i << "\n";
    +
    23  std::cerr << "Device name: " << prop.name << "\n";
    +
    24  std::cerr << "Memory Clock Rate (KHz): " << prop.memoryClockRate << "\n";
    +
    25  std::cerr << "Memory Bus Width (bits): " << prop.memoryBusWidth << "\n";
    +
    26  std::cerr << "Peak Memory Bandwidth (GB/s): " << 2.0 * prop.memoryClockRate * (prop.memoryBusWidth / 8) / 1.0e6 << "\n";
    +
    27  std::cerr << "Max Linear Threads: " << prop.maxThreadsDim[0] << "\n";
    +
    28 
    +
    29  }
    +
    30  }
    +
    @@ -2108,6 +2609,35 @@

    Markov::API::ModelMatrix::ConstructMatrix at least once. This function will manage the memory allocation and data transfer from CPU RAM to GPU VRAM.

    Newly allocated VRAM pointers are set in the class member variables.

    +

    Definition at line 20 of file cudaModelMatrix.cu.

    +
    20  {
    +
    21  cudaError_t cudastatus;
    +
    22 
    +
    23  cudastatus = cudaMalloc((char**)&(this->device_matrixIndex),
    +
    24  this->matrixSize*sizeof(char));
    +
    25  CudaCheckNotifyErr(cudastatus, "Cuda failed to initialize device_matrixIndex.");
    +
    26 
    +
    27  cudastatus = cudaMalloc((long int **)&(this->device_totalEdgeWeights), this->matrixSize*sizeof(long int));
    +
    28  CudaCheckNotifyErr(cudastatus, "Cuda failed to initialize device_totalEdgeWeights.");
    +
    29 
    +
    30  cudastatus = cudaMemcpy(this->device_matrixIndex, this->matrixIndex,
    +
    31  this->matrixSize*sizeof(char), cudaMemcpyHostToDevice);
    +
    32  CudaCheckNotifyErr(cudastatus, "Cuda failed to copy to device memory. (Index)");
    +
    33 
    +
    34  cudastatus = cudaMemcpy(this->device_totalEdgeWeights, this->totalEdgeWeights,
    +
    35  this->matrixSize*sizeof(long int), cudaMemcpyHostToDevice);
    +
    36  CudaCheckNotifyErr(cudastatus, "Cuda failed to copy to device memory. (Total Edge Values)");
    +
    37 
    +
    38  cudastatus = CudaMigrate2DFlat<char>(
    +
    39  &(this->device_edgeMatrix), this->edgeMatrix, this->matrixSize, this->matrixSize);
    +
    40  CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize edge matrix.");
    +
    41 
    +
    42  cudastatus = CudaMigrate2DFlat<long int>(
    +
    43  &(this->device_valueMatrix), this->valueMatrix, this->matrixSize, this->matrixSize);
    +
    44  CudaCheckNotifyErr(cudastatus, " Cuda failed to initialize value matrix row.");
    +
    45 
    +
    46  }
    +
    @@ -2120,7 +2650,7 @@

    static __host__ void Markov::API::CUDA::CUDADeviceController::ListCudaDevices __host__ void Markov::API::CUDA::CUDADeviceController::ListCudaDevices ( )
    - + @@ -2136,8 +2666,8 @@

    Node.

    Returns
    starter node with 00 NodeValue
    -

    Definition at line 177 of file model.h.

    -
    177 { return &nodes;}
    +

    Definition at line 181 of file model.h.

    +
    181 { return &nodes;}
    @@ -2153,7 +2683,7 @@

    std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile

    - + @@ -2174,20 +2704,20 @@

    Returns
    ifstream* to the the dataset file
    -

    Definition at line 43 of file markovPasswords.cpp.

    -
    43  {
    -
    44 
    -
    45  std::ifstream* datasetFile;
    -
    46 
    -
    47  std::ifstream newFile(filename);
    -
    48 
    -
    49  datasetFile = &newFile;
    -
    50 
    -
    51  this->Import(datasetFile);
    -
    52  return datasetFile;
    -
    53 }
    +

    Definition at line 51 of file markovPasswords.cpp.

    +
    51  {
    +
    52 
    +
    53  std::ifstream* datasetFile;
    +
    54 
    +
    55  std::ifstream newFile(filename);
    +
    56 
    +
    57  datasetFile = &newFile;
    +
    58 
    +
    59  this->Import(datasetFile);
    +
    60  return datasetFile;
    +
    61 }
    -

    References Markov::Model< NodeStorageType >::Import().

    +

    References Markov::Model< NodeStorageType >::Import().

    Here is the call graph for this function:
    @@ -2200,8 +2730,8 @@

    -

    ◆ RandomWalk()

    + +

    ◆ OptimizeEdgeOrder()

    @@ -2210,7 +2740,110 @@

    std::map<char , Node<char >*>* Markov::Model< char >::Nodes std::map<char , Node<char >*>* Markov::Model< char >::Nodes ( ) (const char * const char filename)
    - + + +
    char * Markov::Model< char >::RandomWalk void Markov::Model< char >::OptimizeEdgeOrder
    + + +inherited + + +

    + +

    Sort edges of all nodes in the model ordered by edge weights.

    + +

    Definition at line 265 of file model.h.

    +
    265  {
    +
    266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
    +
    267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
    +
    268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
    +
    269  return lhs->EdgeWeight() > rhs->EdgeWeight();
    +
    270  });
    +
    271  //for(int i=0;i<x.second->edgesV.size();i++)
    +
    272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
    +
    273  //std::cout << "\n";
    +
    274  }
    +
    275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
    +
    276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
    +
    277 }
    +
    +
    +
    + +

    ◆ prepKernelMemoryChannel()

    + +
    +
    + + + + + +
    + + + + + + + + +
    __host__ void Markov::API::CUDA::CUDAModelMatrix::prepKernelMemoryChannel (int numberOfStreams)
    +
    +protected
    +
    + +

    Definition at line 145 of file cudaModelMatrix.cu.

    +
    145  {
    +
    146 
    +
    147  this->cudastreams = new cudaStream_t[numberOfStreams];
    +
    148  for(int i=0;i<numberOfStreams;i++)
    +
    149  cudaStreamCreate(&this->cudastreams[i]);
    +
    150 
    +
    151  this-> outputBuffer = new char*[numberOfStreams];
    +
    152  for(int i=0;i<numberOfStreams;i++)
    +
    153  this->outputBuffer[i]= new char[cudaPerKernelAllocationSize];
    +
    154 
    +
    155  cudaError_t cudastatus;
    +
    156  this-> device_outputBuffer = new char*[numberOfStreams];
    +
    157  for(int i=0;i<numberOfStreams;i++){
    +
    158  cudastatus = cudaMalloc((char**)&(device_outputBuffer[i]), cudaPerKernelAllocationSize);
    +
    159  CudaCheckNotifyErr(cudastatus, "Failed to establish memory channel. Possibly out of VRAM?");
    +
    160  }
    +
    161 
    +
    162  this-> device_seeds = new unsigned long*[numberOfStreams];
    +
    163  for(int i=0;i<numberOfStreams;i++){
    + + +
    166  delete[] MEarr;
    +
    167  }
    +
    168 
    +
    169  }
    +
    +

    References cudaGridSize, cudaPerKernelAllocationSize, device_outputBuffer, device_seeds, Markov::API::CUDA::Random::Marsaglia::MigrateToVRAM(), and outputBuffer.

    +
    +Here is the call graph for this function:
    +
    +
    + + + + +
    + +
    +
    + +

    ◆ RandomWalk()

    + +
    +
    + + + @@ -2627,9 +3440,9 @@

    -

    VRAM Address pointer of edge matrix (from modelMatrix.h)

    +

    VRAM Address pointer of edge matrix (from modelMatrix.h)

    -

    Definition at line 73 of file cudaModelMatrix.h.

    +

    Definition at line 88 of file cudaModelMatrix.h.

    @@ -2643,7 +3456,7 @@

    + + + @@ -2251,7 +2884,7 @@

    Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

    This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

    This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

    -

    Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

    +

    Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

    Model.import("model.mdl");
    char* res = new char[11];
    Markov::Random::Marsaglia MarsagliaRandomEngine;
    @@ -2270,35 +2903,35 @@

    Returns
    Null terminated string that was generated.
    -

    Definition at line 293 of file model.h.

    -
    293  {
    - -
    295  int len = 0;
    - -
    297  while (true) {
    -
    298  temp_node = n->RandomNext(randomEngine);
    -
    299  if (len >= maxSetting) {
    -
    300  break;
    -
    301  }
    -
    302  else if ((temp_node == NULL) && (len < minSetting)) {
    -
    303  continue;
    -
    304  }
    -
    305 
    -
    306  else if (temp_node == NULL){
    -
    307  break;
    -
    308  }
    -
    309 
    -
    310  n = temp_node;
    -
    311 
    -
    312  buffer[len++] = n->NodeValue();
    -
    313  }
    -
    314 
    -
    315  //null terminate the string
    -
    316  buffer[len] = 0x00;
    -
    317 
    -
    318  //do something with the generated string
    -
    319  return buffer; //for now
    -
    320 }
    +

    Definition at line 307 of file model.h.

    +
    307  {
    + +
    309  int len = 0;
    + +
    311  while (true) {
    +
    312  temp_node = n->RandomNext(randomEngine);
    +
    313  if (len >= maxSetting) {
    +
    314  break;
    +
    315  }
    +
    316  else if ((temp_node == NULL) && (len < minSetting)) {
    +
    317  continue;
    +
    318  }
    +
    319 
    +
    320  else if (temp_node == NULL){
    +
    321  break;
    +
    322  }
    +
    323 
    +
    324  n = temp_node;
    +
    325 
    +
    326  buffer[len++] = n->NodeValue();
    +
    327  }
    +
    328 
    +
    329  //null terminate the string
    +
    330  buffer[len] = 0x00;
    +
    331 
    +
    332  //do something with the generated string
    +
    333  return buffer; //for now
    +
    334 }

    @@ -2314,7 +2947,7 @@

    std::ofstream * Markov::API::MarkovPasswords::Save

    - + @@ -2335,19 +2968,19 @@

    Returns
    std::ofstream* of the exported file.
    -

    Definition at line 98 of file markovPasswords.cpp.

    -
    98  {
    -
    99  std::ofstream* exportFile;
    -
    100 
    -
    101  std::ofstream newFile(filename);
    -
    102 
    -
    103  exportFile = &newFile;
    -
    104 
    -
    105  this->Export(exportFile);
    -
    106  return exportFile;
    -
    107 }
    +

    Definition at line 106 of file markovPasswords.cpp.

    +
    106  {
    +
    107  std::ofstream* exportFile;
    +
    108 
    +
    109  std::ofstream newFile(filename);
    +
    110 
    +
    111  exportFile = &newFile;
    +
    112 
    +
    113  this->Export(exportFile);
    +
    114  return exportFile;
    +
    115 }
    -

    References Markov::Model< NodeStorageType >::Export().

    +

    References Markov::Model< NodeStorageType >::Export().

    Here is the call graph for this function:
    @@ -2370,7 +3003,7 @@

    char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine, (const char * const char filename)
    - + @@ -2386,8 +3019,8 @@

    Node.

    Returns
    starter node with 00 NodeValue
    -

    Definition at line 167 of file model.h.

    -
    167 { return starterNode;}
    +

    Definition at line 171 of file model.h.

    +
    171 { return starterNode;}
    @@ -2403,13 +3036,13 @@

    void Markov::API::ModelMatrix::Train

    - + - + @@ -2445,16 +3078,16 @@

    mp.Train("password.corpus");

    Construct the matrix when done.

    -

    Definition at line 16 of file modelMatrix.cpp.

    -
    16  {
    -
    17  this->DeallocateMatrix();
    -
    18  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
    -
    19  this->ConstructMatrix();
    -
    20 }
    +

    Definition at line 25 of file modelMatrix.cpp.

    +
    25  {
    +
    26  this->DeallocateMatrix();
    +
    27  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
    +
    28  this->ConstructMatrix();
    +
    29 }
    -

    References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

    +

    References Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

    -

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

    +

    Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

    Here is the call graph for this function:
    @@ -2482,9 +3115,8 @@

    - + -

    @@ -2508,7 +3140,7 @@

    - + @@ -2533,30 +3165,30 @@

    Definition at line 77 of file markovPasswords.cpp.

    -
    77  {
    -
    78  char format_str[] ="%ld,%s";
    -
    79  format_str[3]=delimiter;
    -
    80  std::string line;
    -
    81  while (listhandler->next(&line) && keepRunning) {
    -
    82  long int oc;
    -
    83  if (line.size() > 100) {
    -
    84  line = line.substr(0, 100);
    -
    85  }
    -
    86  char* linebuf = new char[line.length()+5];
    -
    87 #ifdef _WIN32
    -
    88  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
    -
    89 #else
    -
    90  sscanf(line.c_str(), format_str, &oc, linebuf);
    -
    91 #endif
    -
    92  this->AdjustEdge((const char*)linebuf, oc);
    -
    93  delete linebuf;
    -
    94  }
    -
    95 }
    +

    Definition at line 85 of file markovPasswords.cpp.

    +
    85  {
    +
    86  char format_str[] ="%ld,%s";
    +
    87  format_str[3]=delimiter;
    +
    88  std::string line;
    +
    89  while (listhandler->next(&line) && keepRunning) {
    +
    90  long int oc;
    +
    91  if (line.size() > 100) {
    +
    92  line = line.substr(0, 100);
    +
    93  }
    +
    94  char* linebuf = new char[line.length()+5];
    +
    95 #ifdef _WIN32
    +
    96  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
    +
    97 #else
    +
    98  sscanf(line.c_str(), format_str, &oc, linebuf);
    +
    99 #endif
    +
    100  this->AdjustEdge((const char*)linebuf, oc);
    +
    101  delete linebuf;
    +
    102  }
    +
    103 }
    -

    References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

    +

    References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

    -

    Referenced by Markov::API::MarkovPasswords::Train().

    +

    Referenced by Markov::API::MarkovPasswords::Train().

    Here is the call graph for this function:
    @@ -2572,17 +3204,198 @@

    - - - - - + + + + + +

    Member Data Documentation

    +
    +

    ◆ alternatingKernels

    + +
    +
    +
    Node<char >* Markov::Model< char >::StarterNode Node<char >* Markov::Model< char >::StarterNode ( ) (const char * const char datasetFileName,
    char char  delimiter,
    char char  delimiter 
    + + + + +
    + + + + +
    int Markov::API::CUDA::CUDAModelMatrix::alternatingKernels
    +
    +private
    +
    + +

    Definition at line 135 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk().

    + +
    + + +

    ◆ cudaBlocks

    + +
    +
    + + + + + +
    + + + + +
    int Markov::API::CUDA::CUDAModelMatrix::cudaBlocks
    +
    +private
    +
    + +

    Definition at line 125 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk().

    + +
    +
    + +

    ◆ cudaGridSize

    + +
    +
    + + + + + +
    + + + + +
    int Markov::API::CUDA::CUDAModelMatrix::cudaGridSize
    +
    +private
    +
    + +

    Definition at line 131 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk(), and prepKernelMemoryChannel().

    + +
    +
    + +

    ◆ cudaMemPerGrid

    + +
    +
    + + + + + +
    + + + + +
    int Markov::API::CUDA::CUDAModelMatrix::cudaMemPerGrid
    +
    +private
    +
    + +

    Definition at line 132 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk(), and GatherAsyncKernelOutput().

    + +
    +
    + +

    ◆ cudaPerKernelAllocationSize

    + +
    +
    + + + + + +
    + + + + +
    long int Markov::API::CUDA::CUDAModelMatrix::cudaPerKernelAllocationSize
    +
    +private
    +
    + +

    Definition at line 133 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk(), GatherAsyncKernelOutput(), and prepKernelMemoryChannel().

    + +
    +
    + +

    ◆ cudastreams

    + +
    +
    + + + + + +
    + + + + +
    cudaStream_t* Markov::API::CUDA::CUDAModelMatrix::cudastreams
    +
    +private
    +
    + +

    Definition at line 139 of file cudaModelMatrix.h.

    + +
    +
    + +

    ◆ cudaThreads

    + +
    +
    + + + + + +
    + + + + +
    int Markov::API::CUDA::CUDAModelMatrix::cudaThreads
    +
    +private
    +
    + +

    Definition at line 126 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk().

    + +
    +

    ◆ datasetFile

    @@ -2603,7 +3416,7 @@

    -

    Definition at line 106 of file markovPasswords.h.

    +

    Definition at line 123 of file markovPasswords.h.

    @@ -2617,7 +3430,7 @@

    - +
    char* Markov::API::CUDA::CUDAModelMatrix::device_edgeMatrixchar* Markov::API::CUDA::CUDAModelMatrix::device_edgeMatrix

    - +
    char* Markov::API::CUDA::CUDAModelMatrix::device_matrixIndexchar* Markov::API::CUDA::CUDAModelMatrix::device_matrixIndex
    @@ -2653,14 +3466,14 @@

    -

    VRAM Address pointer of matrixIndex (from modelMatrix.h)

    +

    VRAM Address pointer of matrixIndex (from modelMatrix.h)

    -

    Definition at line 83 of file cudaModelMatrix.h.

    +

    Definition at line 98 of file cudaModelMatrix.h.

    - -

    ◆ device_outputBuffer

    + +

    ◆ device_outputBuffer

    + +

    ◆ device_seeds

    + +
    +
    + + + + + +
    + + + + +
    unsigned long** Markov::API::CUDA::CUDAModelMatrix::device_seeds
    +
    +private
    +
    + +

    Definition at line 137 of file cudaModelMatrix.h.

    + +

    Referenced by prepKernelMemoryChannel().

    @@ -2705,9 +3546,9 @@

    -

    VRAM Address pointer of total edge weights (from modelMatrix.h)

    +

    VRAM Address pointer of total edge weights (from modelMatrix.h)

    -

    Definition at line 88 of file cudaModelMatrix.h.

    +

    Definition at line 103 of file cudaModelMatrix.h.

    @@ -2731,9 +3572,9 @@

    -

    VRAM Address pointer of value matrix (from modelMatrix.h)

    +

    VRAM Address pointer of value matrix (from modelMatrix.h)

    -

    Definition at line 78 of file cudaModelMatrix.h.

    +

    Definition at line 93 of file cudaModelMatrix.h.

    @@ -2747,7 +3588,7 @@

    - +
    char** Markov::API::ModelMatrix::edgeMatrixchar** Markov::API::ModelMatrix::edgeMatrix
    @@ -2759,9 +3600,9 @@

    Definition at line 136 of file modelMatrix.h.

    +

    Definition at line 175 of file modelMatrix.h.

    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    @@ -2775,7 +3616,7 @@

    - +
    std::vector<Edge<char >*> Markov::Model< char >::edgesstd::vector<Edge<char >*> Markov::Model< char >::edges
    @@ -2787,7 +3628,7 @@

    Definition at line 195 of file model.h.

    +

    Definition at line 204 of file model.h.

    @@ -2801,7 +3642,7 @@

    - +
    char* Markov::API::CUDA::CUDAModelMatrix::flatEdgeMatrixchar* Markov::API::CUDA::CUDAModelMatrix::flatEdgeMatrix
    @@ -2813,7 +3654,9 @@

    Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.

    -

    Definition at line 104 of file cudaModelMatrix.h.

    +

    Definition at line 118 of file cudaModelMatrix.h.

    + +

    Referenced by FlattenMatrix().

    @@ -2839,7 +3682,35 @@

    Definition at line 109 of file cudaModelMatrix.h.

    +

    Definition at line 123 of file cudaModelMatrix.h.

    + +

    Referenced by FlattenMatrix().

    + + + + +

    ◆ iterationsPerKernelThread

    + +
    +
    + + + + + +
    + + + + +
    int Markov::API::CUDA::CUDAModelMatrix::iterationsPerKernelThread
    +
    +private
    +
    + +

    Definition at line 127 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk().

    @@ -2853,7 +3724,7 @@

    - +
    char* Markov::API::ModelMatrix::matrixIndexchar* Markov::API::ModelMatrix::matrixIndex
    @@ -2865,9 +3736,9 @@

    Definition at line 151 of file modelMatrix.h.

    +

    Definition at line 190 of file modelMatrix.h.

    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    @@ -2893,9 +3764,9 @@

    Definition at line 146 of file modelMatrix.h.

    +

    Definition at line 185 of file modelMatrix.h.

    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), Markov::API::ModelMatrix::FastRandomWalkThread(), and FlattenMatrix().

    @@ -2922,7 +3793,7 @@

    Definition at line 107 of file markovPasswords.h.

    +

    Definition at line 124 of file markovPasswords.h.

    @@ -2936,7 +3807,7 @@

    - +
    std::map<char , Node<char >*> Markov::Model< char >::nodesstd::map<char , Node<char >*> Markov::Model< char >::nodes
    @@ -2948,12 +3819,12 @@

    Definition at line 184 of file model.h.

    +

    Definition at line 193 of file model.h.

    - -

    ◆ outputBuffer

    + +

    ◆ numberOfPartitions

    + +

    ◆ outputBuffer

    + +
    +
    + + + @@ -2974,7 +3871,9 @@

    Definition at line 99 of file cudaModelMatrix.h.

    +

    Definition at line 113 of file cudaModelMatrix.h.

    + +

    Referenced by GatherAsyncKernelOutput(), and prepKernelMemoryChannel().

    @@ -3001,7 +3900,7 @@

    Definition at line 108 of file markovPasswords.h.

    +

    Definition at line 125 of file markovPasswords.h.

    @@ -3027,9 +3926,9 @@

    Definition at line 161 of file modelMatrix.h.

    +

    Definition at line 200 of file modelMatrix.h.

    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::ModelMatrix().

    @@ -3043,7 +3942,7 @@

    + + +
    char** Markov::API::CUDA::CUDAModelMatrix::outputBuffer
    - +
    Node<char >* Markov::Model< char >::starterNodeNode<char >* Markov::Model< char >::starterNode
    @@ -3055,7 +3954,7 @@

    Node of this model.

    -

    Definition at line 189 of file model.h.

    +

    Definition at line 198 of file model.h.

    @@ -3081,9 +3980,61 @@

    Edge Weights.

    -

    Definition at line 156 of file modelMatrix.h.

    +

    Definition at line 195 of file modelMatrix.h.

    + +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    + + + + +

    ◆ totalOutputPerKernel

    + +
    +
    + + + + + +
    + + + + +
    long int Markov::API::CUDA::CUDAModelMatrix::totalOutputPerKernel
    +
    +private
    +
    + +

    Definition at line 129 of file cudaModelMatrix.h.

    + +

    Referenced by FastRandomWalk().

    + +
    +
    + +

    ◆ totalOutputPerSync

    + +
    +
    + + + + + +
    + + + + +
    long int Markov::API::CUDA::CUDAModelMatrix::totalOutputPerSync
    +
    +private
    +
    @@ -3109,69 +4060,98 @@

    Definition at line 141 of file modelMatrix.h.

    +

    Definition at line 180 of file modelMatrix.h.

    -

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    +

    Referenced by Markov::API::ModelMatrix::ConstructMatrix(), Markov::API::ModelMatrix::DeallocateMatrix(), Markov::API::ModelMatrix::DumpJSON(), and Markov::API::ModelMatrix::FastRandomWalkThread().

    -
    The documentation for this class was generated from the following file:
      +
      The documentation for this class was generated from the following files: -
      void AdjustEdge(const char *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:323
      -
      std::map< char, Node< char > * > * Nodes()
      Return starter Node.
      Definition: model.h:177
      -
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:10
      -
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:156
      -
      void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      -
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:226
      -
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:158
      -
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:13
      -
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:207
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      Markov::Model with char represented nodes.
      -
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:141
      -
      std::vector< Edge< storageType > * > edgesV
      Definition: node.h:165
      -
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:153
      -
      char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
      Do a random walk on this model.
      Definition: model.h:293
      -
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:274
      - -
      static __host__ int CudaCheckNotifyErr(cudaError_t _status, const char *msg, bool bExit=true)
      Check results of the last operation on GPU.
      -
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:161
      +
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:337
      + +
      std::map< char, Node< char > * > * Nodes()
      Return starter Node.
      Definition: model.h:181
      + +
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:19
      +
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:195
      +
      char ** outputBuffer
      RandomWalk results in host.
      + +
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:234
      +
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:165
      + +
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:23
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      Markov::Model with char represented nodes.
      + +
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:180
      +
      long int * flatValueMatrix
      Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing.
      + +
      std::vector< Edge< storageType > * > edgesV
      Definition: node.h:173
      +
      void OptimizeEdgeOrder()
      Sort edges of all nodes in the model ordered by edge weights.
      Definition: model.h:265
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      Extension of Markov::Random::Marsaglia which is capable o working on device space.
      Definition: cudarandom.h:20
      +
      char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
      Do a random walk on this model.
      Definition: model.h:307
      +
      __device__ char * strchr(char *p, char c, int s_len)
      srtchr implementation on device space
      +
      __host__ void GatherAsyncKernelOutput(int kernelID, bool bFileIO, std::ofstream &wordlist)
      +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      + +
      __host__ void MigrateMatrix()
      Migrate the class members to the VRAM.
      +
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:200
      -
      Node< char > * StarterNode()
      Return starter Node.
      Definition: model.h:167
      -
      unsigned long random()
      Generate Random Number.
      Definition: random.h:131
      -
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:146
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      -
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:130
      -
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:212
      -
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:207
      -
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:201
      -
      std::vector< Edge< char > * > edges
      A list of all edges in this model.
      Definition: model.h:195
      -
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      -
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:252
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      -
      bool next(std::string *line)
      Read the next line from the file.
      -
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      +
      Node< char > * StarterNode()
      Return starter Node.
      Definition: model.h:171
      +
      unsigned long random()
      Generate Random Number.
      Definition: random.h:140
      +
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:185
      + +
      long int * device_valueMatrix
      VRAM Address pointer of value matrix (from modelMatrix.h)
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      + +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      + +
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:220
      +
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:215
      +
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:210
      +
      std::vector< Edge< char > * > edges
      A list of all edges in this model.
      Definition: model.h:204
      +
      __host__ void FlattenMatrix()
      Flatten migrated matrix from 2d to 1d.
      +
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      +
      __host__ void LaunchAsyncKernel(int kernelID, int minLen, int maxLen)
      +
      static unsigned long * MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize)
      Migrate a Marsaglia[] to VRAM as seedChunk.
      Definition: cudarandom.h:28
      +
      char * device_matrixIndex
      VRAM Address pointer of matrixIndex (from modelMatrix.h)
      +
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:260
      +
      int FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      bool next(std::string *line)
      Read the next line from the file.
      +
      long int * device_totalEdgeWeights
      VRAM Address pointer of total edge weights (from modelMatrix.h)
      +
      char * flatEdgeMatrix
      Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.
      +
      char * device_edgeMatrix
      VRAM Address pointer of edge matrix (from modelMatrix.h)
      +
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      f
      output file handle
      Definition: model_2gram.py:16
      -
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:72
      +
      __global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
      CUDA kernel for the FastRandomWalk operation.
      +
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:81
      -
      __device__ char * strchr(char *p, char c, int s_len)
      srtchr implementation on device space
      -
      std::map< char, Node< char > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:184
      -
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:22
      -
      Node< char > * starterNode
      Starter Node of this model.
      Definition: model.h:189
      -
      static volatile int keepRunning
      - -
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      -
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:151
      -
      Edge class used to link nodes in the model together.
      Definition: model.h:26
      -
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:136
      +
      char ** device_outputBuffer
      RandomWalk results in device.
      +
      std::map< char, Node< char > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:193
      +
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:31
      + +
      __host__ void prepKernelMemoryChannel(int numberOfStreams)
      +
      Node< char > * starterNode
      Starter Node of this model.
      Definition: model.h:198
      +
      static volatile int keepRunning
      + +
      static __host__ int CudaCheckNotifyErr(cudaError_t _status, const char *msg, bool bExit=true)
      Check results of the last operation on GPU.
      + +
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      +
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:190
      +
      Edge class used to link nodes in the model together.
      Definition: model.h:30
      +
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:175
      @@ -421,9 +520,9 @@

      - + - + @@ -437,15 +536,15 @@

      Model::Export with std::ofstream.

      Returns
      True if successful, False for incomplete models or corrupt file formats
      -

      Example Use: Export file to filename

      -
      model.Export("test.mdl");
      +

      Example Use: Export file to filename

      +
      model.Export("test.mdl");
      -

      Definition at line 286 of file model.h.

      -
      286  {
      -
      287  std::ofstream exportfile;
      -
      288  exportfile.open(filename);
      -
      289  return this->Export(&exportfile);
      -
      290 }
      +

      Definition at line 300 of file model.h.

      +
      300  {
      +
      301  std::ofstream exportfile;
      +
      302  exportfile.open(filename);
      +
      303  return this->Export(&exportfile);
      +
      304 }
      @@ -459,7 +558,7 @@

      bool Markov::Model< char >::Export bool Markov::Model< char >::Export (const char * const char filename)
      - + @@ -476,21 +575,21 @@

      Returns
      True if successful, False for incomplete models.
      -

      Example Use: Export file to ofstream

      +

      Example Use: Export file to ofstream

      std::ofstream file("test.mdl");
      -
      model.Export(&file);
      +
      model.Export(&file);
      -

      Definition at line 274 of file model.h.

      -
      274  {
      - -
      276  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
      -
      277  e = this->edges[i];
      -
      278  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      -
      279  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      -
      280  }
      -
      281 
      -
      282  return true;
      -
      283 }
      +

      Definition at line 288 of file model.h.

      +
      288  {
      + +
      290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
      +
      291  e = this->edges[i];
      +
      292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      +
      293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      +
      294  }
      +
      295 
      +
      296  return true;
      +
      297 }
      @@ -509,7 +608,7 @@

      - + @@ -552,32 +651,32 @@

      Definition at line 110 of file markovPasswords.cpp.

      -
      110  {
      -
      111  char* res;
      -
      112  char print[100];
      -
      113  std::ofstream wordlist;
      -
      114  wordlist.open(wordlistFileName);
      -
      115  std::mutex mlock;
      -
      116  int iterationsPerThread = n/threads;
      -
      117  int iterationsCarryOver = n%threads;
      -
      118  std::vector<std::thread*> threadsV;
      -
      119  for(int i=0;i<threads;i++){
      -
      120  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
      -
      121  }
      -
      122 
      -
      123  for(int i=0;i<threads;i++){
      -
      124  threadsV[i]->join();
      -
      125  delete threadsV[i];
      -
      126  }
      -
      127 
      -
      128  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
      -
      129 
      -
      130 }
      +

      Definition at line 118 of file markovPasswords.cpp.

      +
      118  {
      +
      119  char* res;
      +
      120  char print[100];
      +
      121  std::ofstream wordlist;
      +
      122  wordlist.open(wordlistFileName);
      +
      123  std::mutex mlock;
      +
      124  int iterationsPerThread = n/threads;
      +
      125  int iterationsCarryOver = n%threads;
      +
      126  std::vector<std::thread*> threadsV;
      +
      127  for(int i=0;i<threads;i++){
      +
      128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
      +
      129  }
      +
      130 
      +
      131  for(int i=0;i<threads;i++){
      +
      132  threadsV[i]->join();
      +
      133  delete threadsV[i];
      +
      134  }
      +
      135 
      +
      136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
      +
      137 
      +
      138 }
      -

      References GenerateThread().

      +

      References GenerateThread().

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

      Here is the call graph for this function:
      @@ -593,8 +692,9 @@

      - + +

      @@ -665,23 +765,23 @@

      Definition at line 132 of file markovPasswords.cpp.

      -
      132  {
      -
      133  char* res = new char[maxLen+5];
      -
      134  if(n==0) return;
      -
      135 
      -
      136  Markov::Random::Marsaglia MarsagliaRandomEngine;
      -
      137  for (int i = 0; i < n; i++) {
      -
      138  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
      -
      139  outputLock->lock();
      -
      140  *wordlist << res << "\n";
      -
      141  outputLock->unlock();
      -
      142  }
      -
      143 }
      +

      Definition at line 140 of file markovPasswords.cpp.

      +
      140  {
      +
      141  char* res = new char[maxLen+5];
      +
      142  if(n==0) return;
      +
      143 
      +
      144  Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      145  for (int i = 0; i < n; i++) {
      +
      146  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
      +
      147  outputLock->lock();
      +
      148  *wordlist << res << "\n";
      +
      149  outputLock->unlock();
      +
      150  }
      +
      151 }
      -

      References Markov::Model< NodeStorageType >::RandomWalk().

      +

      References Markov::Model< NodeStorageType >::RandomWalk().

      -

      Referenced by Generate().

      +

      Referenced by Generate().

      Here is the call graph for this function:
      @@ -696,9 +796,10 @@

      - - + + +

      @@ -714,9 +815,9 @@

      bool Markov::Model< char >::Export bool Markov::Model< char >::Export ( std::ofstream *  f)const char * const char wordlistFileName,
      - + - + @@ -730,16 +831,16 @@

      Model::Import with std::ifstream.

      Returns
      True if successful, False for incomplete models or corrupt file formats
      -

      Example Use: Import a file with filename

      -
      model.Import("test.mdl");
      +

      Example Use: Import a file with filename

      +
      model.Import("test.mdl");
      -

      Definition at line 266 of file model.h.

      -
      266  {
      -
      267  std::ifstream importfile;
      -
      268  importfile.open(filename);
      -
      269  return this->Import(&importfile);
      -
      270 
      -
      271 }
      +

      Definition at line 280 of file model.h.

      +
      280  {
      +
      281  std::ifstream importfile;
      +
      282  importfile.open(filename);
      +
      283  return this->Import(&importfile);
      +
      284 
      +
      285 }
      @@ -753,7 +854,7 @@

      bool Markov::Model< char >::Import bool Markov::Model< char >::Import (const char * const char filename)
      - + @@ -770,68 +871,58 @@

      Returns
      True if successful, False for incomplete models or corrupt file formats
      -

      Example Use: Import a file from ifstream

      +

      Example Use: Import a file from ifstream

      std::ifstream file("test.mdl");
      -
      model.Import(&file);
      +
      model.Import(&file);
      -

      Definition at line 207 of file model.h.

      -
      207  {
      -
      208  std::string cell;
      -
      209 
      -
      210  char src;
      -
      211  char target;
      -
      212  long int oc;
      -
      213 
      -
      214  while (std::getline(*f, cell)) {
      -
      215  //std::cout << "cell: " << cell << std::endl;
      -
      216  src = cell[0];
      -
      217  target = cell[cell.length() - 1];
      -
      218  char* j;
      -
      219  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
      -
      220  //std::cout << oc << "\n";
      - - - -
      224  if (this->nodes.find(src) == this->nodes.end()) {
      -
      225  srcN = new Markov::Node<NodeStorageType>(src);
      -
      226  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
      -
      227  //std::cout << "Creating new node at start.\n";
      -
      228  }
      -
      229  else {
      -
      230  srcN = this->nodes.find(src)->second;
      -
      231  }
      -
      232 
      -
      233  if (this->nodes.find(target) == this->nodes.end()) {
      -
      234  targetN = new Markov::Node<NodeStorageType>(target);
      -
      235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
      -
      236  //std::cout << "Creating new node at end.\n";
      +

      Definition at line 216 of file model.h.

      +
      216  {
      +
      217  std::string cell;
      +
      218 
      +
      219  char src;
      +
      220  char target;
      +
      221  long int oc;
      +
      222 
      +
      223  while (std::getline(*f, cell)) {
      +
      224  //std::cout << "cell: " << cell << std::endl;
      +
      225  src = cell[0];
      +
      226  target = cell[cell.length() - 1];
      +
      227  char* j;
      +
      228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
      +
      229  //std::cout << oc << "\n";
      + + + +
      233  if (this->nodes.find(src) == this->nodes.end()) {
      +
      234  srcN = new Markov::Node<NodeStorageType>(src);
      +
      235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
      +
      236  //std::cout << "Creating new node at start.\n";
      237  }
      238  else {
      -
      239  targetN = this->nodes.find(target)->second;
      +
      239  srcN = this->nodes.find(src)->second;
      240  }
      -
      241  e = srcN->Link(targetN);
      -
      242  e->AdjustEdge(oc);
      -
      243  this->edges.push_back(e);
      -
      244 
      -
      245  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
      -
      246 
      -
      247 
      -
      248  }
      -
      249 
      -
      250  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      -
      251  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      -
      252  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      -
      253  return lhs->EdgeWeight() > rhs->EdgeWeight();
      -
      254  });
      -
      255  //for(int i=0;i<x.second->edgesV.size();i++)
      -
      256  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      -
      257  //std::cout << "\n";
      -
      258  }
      -
      259  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      -
      260  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      -
      261 
      -
      262  return true;
      -
      263 }
      +
      241 
      +
      242  if (this->nodes.find(target) == this->nodes.end()) {
      +
      243  targetN = new Markov::Node<NodeStorageType>(target);
      +
      244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
      +
      245  //std::cout << "Creating new node at end.\n";
      +
      246  }
      +
      247  else {
      +
      248  targetN = this->nodes.find(target)->second;
      +
      249  }
      +
      250  e = srcN->Link(targetN);
      +
      251  e->AdjustEdge(oc);
      +
      252  this->edges.push_back(e);
      +
      253 
      +
      254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
      +
      255 
      +
      256 
      +
      257  }
      +
      258 
      +
      259  this->OptimizeEdgeOrder();
      +
      260 
      +
      261  return true;
      +
      262 }
      @@ -845,7 +936,7 @@

      bool Markov::Model< char >::Import bool Markov::Model< char >::Import ( std::ifstream *  f)
      - +
      std::map<char , Node<char >*>* Markov::Model< char >::Nodesstd::map<char , Node<char >*>* Markov::Model< char >::Nodes
      @@ -858,8 +949,8 @@

      Node.

      Returns
      starter node with 00 NodeValue
      -

      Definition at line 177 of file model.h.

      -
      177 { return &nodes;}
      +

      Definition at line 181 of file model.h.

      +
      181 { return &nodes;}
      @@ -872,7 +963,7 @@

      std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile ( - const char *  + const charfilename) @@ -888,20 +979,20 @@

      Returns
      ifstream* to the the dataset file
      -

      Definition at line 43 of file markovPasswords.cpp.

      -
      43  {
      -
      44 
      -
      45  std::ifstream* datasetFile;
      -
      46 
      -
      47  std::ifstream newFile(filename);
      -
      48 
      -
      49  datasetFile = &newFile;
      -
      50 
      -
      51  this->Import(datasetFile);
      -
      52  return datasetFile;
      -
      53 }
      +

      Definition at line 51 of file markovPasswords.cpp.

      +
      51  {
      +
      52 
      +
      53  std::ifstream* datasetFile;
      +
      54 
      +
      55  std::ifstream newFile(filename);
      +
      56 
      +
      57  datasetFile = &newFile;
      +
      58 
      +
      59  this->Import(datasetFile);
      +
      60  return datasetFile;
      +
      61 }
      -

      References Markov::Model< NodeStorageType >::Import().

      +

      References Markov::Model< NodeStorageType >::Import().

      Here is the call graph for this function:
      @@ -912,6 +1003,45 @@

      +

      ◆ OptimizeEdgeOrder()

      + +
      +
      + + + + + +
      + + + + +
      void Markov::Model< char >::OptimizeEdgeOrder
      +
      +inherited
      +
      + +

      Sort edges of all nodes in the model ordered by edge weights.

      + +

      Definition at line 265 of file model.h.

      +
      265  {
      +
      266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      +
      267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      +
      268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      +
      269  return lhs->EdgeWeight() > rhs->EdgeWeight();
      +
      270  });
      +
      271  //for(int i=0;i<x.second->edgesV.size();i++)
      +
      272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      +
      273  //std::cout << "\n";
      +
      274  }
      +
      275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      +
      276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      +
      277 }
      +
      @@ -924,7 +1054,7 @@

      - + @@ -944,7 +1074,7 @@

      - + @@ -965,7 +1095,7 @@

      Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

      This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

      This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

      -

      Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

      +

      Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

      Model.import("model.mdl");
      char* res = new char[11];
      Markov::Random::Marsaglia MarsagliaRandomEngine;
      @@ -984,35 +1114,35 @@

      Returns
      Null terminated string that was generated.
      -

      Definition at line 293 of file model.h.

      -
      293  {
      - -
      295  int len = 0;
      - -
      297  while (true) {
      -
      298  temp_node = n->RandomNext(randomEngine);
      -
      299  if (len >= maxSetting) {
      -
      300  break;
      -
      301  }
      -
      302  else if ((temp_node == NULL) && (len < minSetting)) {
      -
      303  continue;
      -
      304  }
      -
      305 
      -
      306  else if (temp_node == NULL){
      -
      307  break;
      -
      308  }
      -
      309 
      -
      310  n = temp_node;
      -
      311 
      -
      312  buffer[len++] = n->NodeValue();
      -
      313  }
      -
      314 
      -
      315  //null terminate the string
      -
      316  buffer[len] = 0x00;
      -
      317 
      -
      318  //do something with the generated string
      -
      319  return buffer; //for now
      -
      320 }
      +

      Definition at line 307 of file model.h.

      +
      307  {
      + +
      309  int len = 0;
      + +
      311  while (true) {
      +
      312  temp_node = n->RandomNext(randomEngine);
      +
      313  if (len >= maxSetting) {
      +
      314  break;
      +
      315  }
      +
      316  else if ((temp_node == NULL) && (len < minSetting)) {
      +
      317  continue;
      +
      318  }
      +
      319 
      +
      320  else if (temp_node == NULL){
      +
      321  break;
      +
      322  }
      +
      323 
      +
      324  n = temp_node;
      +
      325 
      +
      326  buffer[len++] = n->NodeValue();
      +
      327  }
      +
      328 
      +
      329  //null terminate the string
      +
      330  buffer[len] = 0x00;
      +
      331 
      +
      332  //do something with the generated string
      +
      333  return buffer; //for now
      +
      334 }

      @@ -1025,7 +1155,7 @@

      std::ofstream * Markov::API::MarkovPasswords::Save

      - + @@ -1041,19 +1171,19 @@

      Returns
      std::ofstream* of the exported file.
      -

      Definition at line 98 of file markovPasswords.cpp.

      -
      98  {
      -
      99  std::ofstream* exportFile;
      -
      100 
      -
      101  std::ofstream newFile(filename);
      -
      102 
      -
      103  exportFile = &newFile;
      -
      104 
      -
      105  this->Export(exportFile);
      -
      106  return exportFile;
      -
      107 }
      +

      Definition at line 106 of file markovPasswords.cpp.

      +
      106  {
      +
      107  std::ofstream* exportFile;
      +
      108 
      +
      109  std::ofstream newFile(filename);
      +
      110 
      +
      111  exportFile = &newFile;
      +
      112 
      +
      113  this->Export(exportFile);
      +
      114  return exportFile;
      +
      115 }
      -

      References Markov::Model< NodeStorageType >::Export().

      +

      References Markov::Model< NodeStorageType >::Export().

      Here is the call graph for this function:
      @@ -1076,7 +1206,7 @@

      char * Markov::Model< char >::RandomWalk char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine, char * char buffer 
      (const char * const char filename)
      - +
      Node<char >* Markov::Model< char >::StarterNodeNode<char >* Markov::Model< char >::StarterNode
      @@ -1089,8 +1219,8 @@

      Node.

      Returns
      starter node with 00 NodeValue
      -

      Definition at line 167 of file model.h.

      -
      167 { return starterNode;}
      +

      Definition at line 171 of file model.h.

      +
      171 { return starterNode;}

      @@ -1103,13 +1233,13 @@

      void Markov::API::MarkovPasswords::Train ( - const char *  + const chardatasetFileName, - char  + char  delimiter, @@ -1139,30 +1269,30 @@

      mp.Import("models/2gram.mdl");

      mp.Train("password.corpus");
      -

      Definition at line 57 of file markovPasswords.cpp.

      -
      57  {
      -
      58  signal(SIGINT, intHandler);
      -
      59  Markov::API::Concurrency::ThreadSharedListHandler listhandler(datasetFileName);
      -
      60  auto start = std::chrono::high_resolution_clock::now();
      -
      61 
      -
      62  std::vector<std::thread*> threadsV;
      -
      63  for(int i=0;i<threads;i++){
      -
      64  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::TrainThread, this, &listhandler, delimiter));
      -
      65  }
      -
      66 
      -
      67  for(int i=0;i<threads;i++){
      -
      68  threadsV[i]->join();
      -
      69  delete threadsV[i];
      -
      70  }
      -
      71  auto finish = std::chrono::high_resolution_clock::now();
      -
      72  std::chrono::duration<double> elapsed = finish - start;
      -
      73  std::cout << "Elapsed time: " << elapsed.count() << " s\n";
      +

      Definition at line 65 of file markovPasswords.cpp.

      +
      65  {
      +
      66  signal(SIGINT, intHandler);
      +
      67  Markov::API::Concurrency::ThreadSharedListHandler listhandler(datasetFileName);
      +
      68  auto start = std::chrono::high_resolution_clock::now();
      +
      69 
      +
      70  std::vector<std::thread*> threadsV;
      +
      71  for(int i=0;i<threads;i++){
      +
      72  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::TrainThread, this, &listhandler, delimiter));
      +
      73  }
      74 
      -
      75 }
      +
      75  for(int i=0;i<threads;i++){
      +
      76  threadsV[i]->join();
      +
      77  delete threadsV[i];
      +
      78  }
      +
      79  auto finish = std::chrono::high_resolution_clock::now();
      +
      80  std::chrono::duration<double> elapsed = finish - start;
      +
      81  std::cout << "Elapsed time: " << elapsed.count() << " s\n";
      +
      82 
      +
      83 }
      -

      References intHandler(), Markov::API::Concurrency::ThreadSharedListHandler::ThreadSharedListHandler(), and TrainThread().

      +

      References intHandler(), Markov::API::Concurrency::ThreadSharedListHandler::ThreadSharedListHandler(), and TrainThread().

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::API::ModelMatrix::Train().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), Markov::GUI::Train::train(), Markov::GUI::Generate::train(), and Markov::API::ModelMatrix::Train().

      Here is the call graph for this function:
      @@ -1181,10 +1311,11 @@

      - - - - + + + + +

      @@ -1208,7 +1339,7 @@

      - char  + char  delimiter  @@ -1233,30 +1364,30 @@

      Definition at line 77 of file markovPasswords.cpp.

      -
      77  {
      -
      78  char format_str[] ="%ld,%s";
      -
      79  format_str[3]=delimiter;
      -
      80  std::string line;
      -
      81  while (listhandler->next(&line) && keepRunning) {
      -
      82  long int oc;
      -
      83  if (line.size() > 100) {
      -
      84  line = line.substr(0, 100);
      -
      85  }
      -
      86  char* linebuf = new char[line.length()+5];
      -
      87 #ifdef _WIN32
      -
      88  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
      -
      89 #else
      -
      90  sscanf(line.c_str(), format_str, &oc, linebuf);
      -
      91 #endif
      -
      92  this->AdjustEdge((const char*)linebuf, oc);
      -
      93  delete linebuf;
      -
      94  }
      -
      95 }
      +

      Definition at line 85 of file markovPasswords.cpp.

      +
      85  {
      +
      86  char format_str[] ="%ld,%s";
      +
      87  format_str[3]=delimiter;
      +
      88  std::string line;
      +
      89  while (listhandler->next(&line) && keepRunning) {
      +
      90  long int oc;
      +
      91  if (line.size() > 100) {
      +
      92  line = line.substr(0, 100);
      +
      93  }
      +
      94  char* linebuf = new char[line.length()+5];
      +
      95 #ifdef _WIN32
      +
      96  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
      +
      97 #else
      +
      98  sscanf(line.c_str(), format_str, &oc, linebuf);
      +
      99 #endif
      +
      100  this->AdjustEdge((const char*)linebuf, oc);
      +
      101  delete linebuf;
      +
      102  }
      +
      103 }
      -

      References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

      +

      References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

      -

      Referenced by Train().

      +

      Referenced by Train().

      Here is the call graph for this function:
      @@ -1272,11 +1403,12 @@

      - - - - - + + + + + +

      @@ -1303,7 +1435,7 @@

      -

      Definition at line 106 of file markovPasswords.h.

      +

      Definition at line 123 of file markovPasswords.h.

      @@ -1317,7 +1449,7 @@

      - +
      std::vector<Edge<char >*> Markov::Model< char >::edgesstd::vector<Edge<char >*> Markov::Model< char >::edges
      @@ -1329,7 +1461,7 @@

      Definition at line 195 of file model.h.

      +

      Definition at line 204 of file model.h.

      @@ -1356,7 +1488,7 @@

      Definition at line 107 of file markovPasswords.h.

      +

      Definition at line 124 of file markovPasswords.h.

      @@ -1370,7 +1502,7 @@

      - +
      std::map<char , Node<char >*> Markov::Model< char >::nodesstd::map<char , Node<char >*> Markov::Model< char >::nodes
      @@ -1382,7 +1514,7 @@

      Definition at line 184 of file model.h.

      +

      Definition at line 193 of file model.h.

      @@ -1409,7 +1541,7 @@

      Definition at line 108 of file markovPasswords.h.

      +

      Definition at line 125 of file markovPasswords.h.

      @@ -1423,7 +1555,7 @@

      - +
      Node<char >* Markov::Model< char >::starterNodeNode<char >* Markov::Model< char >::starterNode
      @@ -1435,7 +1567,7 @@

      Node of this model.

      -

      Definition at line 189 of file model.h.

      +

      Definition at line 198 of file model.h.

      @@ -1445,43 +1577,44 @@

      void AdjustEdge(const char *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:323
      -
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:226
      -
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:158
      -
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:207
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      Markov::Model with char represented nodes.
      -
      void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
      A single thread invoked by the Train function.
      -
      void intHandler(int dummy)
      -
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:153
      -
      Simple class for managing shared access to file.
      -
      char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
      Do a random walk on this model.
      Definition: model.h:293
      -
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:274
      - -
      MarkovPasswords()
      Initialize the markov model from MarkovModel::Markov::Model.
      +
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:337
      +
      std::map< char, Node< char > * > * Nodes()
      Return starter Node.
      Definition: model.h:181
      +
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:234
      +
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:165
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      Markov::Model with char represented nodes.
      +
      void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
      A single thread invoked by the Train function.
      +
      void intHandler(int dummy)
      +
      void OptimizeEdgeOrder()
      Sort edges of all nodes in the model ordered by edge weights.
      Definition: model.h:265
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      Simple class for managing shared access to file.
      +
      char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
      Do a random walk on this model.
      Definition: model.h:307
      +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      + +
      MarkovPasswords()
      Initialize the markov model from MarkovModel::Markov::Model.
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      -
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:130
      -
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:212
      -
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:207
      -
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:201
      -
      std::vector< Edge< char > * > edges
      A list of all edges in this model.
      Definition: model.h:195
      -
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      -
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:252
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      -
      bool next(std::string *line)
      Read the next line from the file.
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      +
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:220
      +
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:215
      +
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:210
      +
      std::vector< Edge< char > * > edges
      A list of all edges in this model.
      Definition: model.h:204
      +
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      +
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:260
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      bool next(std::string *line)
      Read the next line from the file.
      f
      output file handle
      Definition: model_2gram.py:16
      -
      std::map< char, Node< char > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:184
      -
      Node< char > * starterNode
      Starter Node of this model.
      Definition: model.h:189
      -
      static volatile int keepRunning
      - -
      Edge class used to link nodes in the model together.
      Definition: model.h:26
      +
      std::map< char, Node< char > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:193
      +
      Node< char > * starterNode
      Starter Node of this model.
      Definition: model.h:198
      +
      static volatile int keepRunning
      +
      Edge class used to link nodes in the model together.
      Definition: model.h:30
      @@ -308,7 +307,7 @@

      - + @@ -336,9 +335,9 @@

      +

      Example Use: Create an empty model and train it with string: "testdata"

      char test[] = "testdata";
      -
      model.AdjustEdge(test, 15);
      +
      model.AdjustEdge(test, 15);
      Parameters

      void Markov::Model< char >::AdjustEdge void Markov::Model< char >::AdjustEdge ( const NodeStorageType *  payload,
      @@ -347,27 +346,141 @@

      Definition at line 323 of file model.h.

      -
      323  {
      -
      324  NodeStorageType p = payload[0];
      - - -
      327  int i = 0;
      -
      328 
      -
      329  if (p == 0) return;
      -
      330  while (p != 0) {
      -
      331  e = curnode->FindEdge(p);
      -
      332  if (e == NULL) return;
      -
      333  e->AdjustEdge(occurrence);
      -
      334  curnode = e->RightNode();
      -
      335  p = payload[++i];
      -
      336  }
      -
      337 
      -
      338  e = curnode->FindEdge('\xff');
      -
      339  e->AdjustEdge(occurrence);
      -
      340  return;
      -
      341 }
      +

      Definition at line 337 of file model.h.

      +
      337  {
      +
      338  NodeStorageType p = payload[0];
      + + +
      341  int i = 0;
      +
      342 
      +
      343  if (p == 0) return;
      +
      344  while (p != 0) {
      +
      345  e = curnode->FindEdge(p);
      +
      346  if (e == NULL) return;
      +
      347  e->AdjustEdge(occurrence);
      +
      348  curnode = e->RightNode();
      +
      349  p = payload[++i];
      +
      350  }
      +
      351 
      +
      352  e = curnode->FindEdge('\xff');
      +
      353  e->AdjustEdge(occurrence);
      +
      354  return;
      +
      355 }
      +
      +
      + + +

      ◆ Buff()

      + +
      +
      +

      string- String that is passed from the training, and will be used to AdjustEdge the model with
      + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      void Markov::API::MarkovPasswords::Buff (const charstr,
      double multiplier,
      bool bDontAdjustSelfLoops = true,
      bool bDontAdjustExtendedLoops = false 
      )
      +
      +inherited
      +
      + +

      Buff expression of some characters in the model.

      +
      Parameters
      + + + + + +
      strA string containing all the characters to be buffed
      multiplierA constant value to buff the nodes with.
      bDontAdjustSelfEdgesDo not adjust weights if target node is same as source node
      bDontAdjustExtendedLoopsDo not adjust if both source and target nodes are in first parameter
      +
      +
      + +

      Definition at line 153 of file markovPasswords.cpp.

      +
      153  {
      +
      154  std::string buffstr(str);
      +
      155  std::map< char, Node< char > * > *nodes;
      +
      156  std::map< char, Edge< char > * > *edges;
      +
      157  nodes = this->Nodes();
      +
      158  int i=0;
      +
      159  for (auto const& [repr, node] : *nodes){
      +
      160  edges = node->Edges();
      +
      161  for (auto const& [targetrepr, edge] : *edges){
      +
      162  if(buffstr.find(targetrepr)!= std::string::npos){
      +
      163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
      +
      164  if(bDontAdjustExtendedLoops){
      +
      165  if(buffstr.find(repr)!= std::string::npos){
      +
      166  continue;
      +
      167  }
      +
      168  }
      +
      169  long int weight = edge->EdgeWeight();
      +
      170  weight = weight*multiplier;
      +
      171  edge->AdjustEdge(weight);
      +
      172  }
      +
      173 
      +
      174  }
      +
      175  i++;
      +
      176  }
      +
      177 
      +
      178  this->OptimizeEdgeOrder();
      +
      179 }
      +

      References Markov::Edge< NodeStorageType >::AdjustEdge(), Markov::Node< storageType >::Edges(), Markov::Edge< NodeStorageType >::EdgeWeight(), Markov::Model< NodeStorageType >::Nodes(), and Markov::Model< NodeStorageType >::OptimizeEdgeOrder().

      + +

      Referenced by main().

      +
      +Here is the call graph for this function:
      +
      +
      + + + + + + + + +
      +
      +Here is the caller graph for this function:
      +
      +
      + + + + +
      +
      @@ -390,60 +503,60 @@

      Node.

      Returns
      True if constructed. False if already construced.
      -

      Definition at line 22 of file modelMatrix.cpp.

      -
      22  {
      -
      23  if(this->ready) return false;
      -
      24  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
      -
      25 
      -
      26  this->matrixIndex = new char[this->matrixSize];
      -
      27  this->totalEdgeWeights = new long int[this->matrixSize];
      -
      28 
      -
      29  this->edgeMatrix = new char*[this->matrixSize];
      -
      30  for(int i=0;i<this->matrixSize;i++){
      -
      31  this->edgeMatrix[i] = new char[this->matrixSize];
      -
      32  }
      -
      33  this->valueMatrix = new long int*[this->matrixSize];
      -
      34  for(int i=0;i<this->matrixSize;i++){
      -
      35  this->valueMatrix[i] = new long int[this->matrixSize];
      -
      36  }
      -
      37  std::map< char, Node< char > * > *nodes;
      -
      38  nodes = this->Nodes();
      -
      39  int i=0;
      -
      40  for (auto const& [repr, node] : *nodes){
      -
      41  if(repr!=0) this->matrixIndex[i] = repr;
      -
      42  else this->matrixIndex[i] = 199;
      -
      43  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
      -
      44  for(int j=0;j<this->matrixSize;j++){
      -
      45  char val = node->NodeValue();
      -
      46  if(val < 0){
      -
      47  for(int k=0;k<this->matrixSize;k++){
      -
      48  this->valueMatrix[i][k] = 0;
      -
      49  this->edgeMatrix[i][k] = 255;
      -
      50  }
      -
      51  break;
      -
      52  }
      -
      53  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
      -
      54  this->valueMatrix[i][j] = 0;
      -
      55  this->edgeMatrix[i][j] = 255;
      -
      56  }else if(j==(this->matrixSize-1)) {
      -
      57  this->valueMatrix[i][j] = 0;
      -
      58  this->edgeMatrix[i][j] = 255;
      -
      59  }else{
      -
      60  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
      -
      61  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
      -
      62  }
      -
      63 
      -
      64  }
      -
      65  i++;
      -
      66  }
      -
      67  this->ready = true;
      -
      68  return true;
      -
      69  //this->DumpJSON();
      -
      70 }
      +

      Definition at line 31 of file modelMatrix.cpp.

      +
      31  {
      +
      32  if(this->ready) return false;
      +
      33  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
      +
      34 
      +
      35  this->matrixIndex = new char[this->matrixSize];
      +
      36  this->totalEdgeWeights = new long int[this->matrixSize];
      +
      37 
      +
      38  this->edgeMatrix = new char*[this->matrixSize];
      +
      39  for(int i=0;i<this->matrixSize;i++){
      +
      40  this->edgeMatrix[i] = new char[this->matrixSize];
      +
      41  }
      +
      42  this->valueMatrix = new long int*[this->matrixSize];
      +
      43  for(int i=0;i<this->matrixSize;i++){
      +
      44  this->valueMatrix[i] = new long int[this->matrixSize];
      +
      45  }
      +
      46  std::map< char, Node< char > * > *nodes;
      +
      47  nodes = this->Nodes();
      +
      48  int i=0;
      +
      49  for (auto const& [repr, node] : *nodes){
      +
      50  if(repr!=0) this->matrixIndex[i] = repr;
      +
      51  else this->matrixIndex[i] = 199;
      +
      52  this->totalEdgeWeights[i] = node->TotalEdgeWeights();
      +
      53  for(int j=0;j<this->matrixSize;j++){
      +
      54  char val = node->NodeValue();
      +
      55  if(val < 0){
      +
      56  for(int k=0;k<this->matrixSize;k++){
      +
      57  this->valueMatrix[i][k] = 0;
      +
      58  this->edgeMatrix[i][k] = 255;
      +
      59  }
      +
      60  break;
      +
      61  }
      +
      62  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
      +
      63  this->valueMatrix[i][j] = 0;
      +
      64  this->edgeMatrix[i][j] = 255;
      +
      65  }else if(j==(this->matrixSize-1)) {
      +
      66  this->valueMatrix[i][j] = 0;
      +
      67  this->edgeMatrix[i][j] = 255;
      +
      68  }else{
      +
      69  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
      +
      70  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
      +
      71  }
      +
      72 
      +
      73  }
      +
      74  i++;
      +
      75  }
      +
      76  this->ready = true;
      +
      77  return true;
      +
      78  //this->DumpJSON();
      +
      79 }
      -

      References edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), matrixIndex, matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), totalEdgeWeights, Markov::Node< storageType >::TotalEdgeWeights(), and valueMatrix.

      +

      References edgeMatrix, Markov::Edge< NodeStorageType >::EdgeWeight(), matrixIndex, matrixSize, Markov::Model< NodeStorageType >::Nodes(), Markov::Node< storageType >::NodeValue(), ready, Markov::Edge< NodeStorageType >::RightNode(), Markov::Model< NodeStorageType >::StarterNode(), Markov::Node< storageType >::TotalEdgeWeights(), totalEdgeWeights, and valueMatrix.

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), Import(), and Train().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), Import(), and Train().

      Here is the call graph for this function:
      @@ -467,7 +580,7 @@

      - +

      @@ -499,40 +612,40 @@

      Returns
      True if deallocated. False if matrix was not initialized
      -

      Definition at line 72 of file modelMatrix.cpp.

      -
      72  {
      -
      73  if(!this->ready) return false;
      -
      74  delete[] this->matrixIndex;
      -
      75  delete[] this->totalEdgeWeights;
      -
      76 
      -
      77  for(int i=0;i<this->matrixSize;i++){
      -
      78  delete[] this->edgeMatrix[i];
      -
      79  }
      -
      80  delete[] this->edgeMatrix;
      -
      81 
      -
      82  for(int i=0;i<this->matrixSize;i++){
      -
      83  delete[] this->valueMatrix[i];
      -
      84  }
      -
      85  delete[] this->valueMatrix;
      -
      86 
      -
      87  this->matrixSize = -1;
      -
      88  this->ready = false;
      -
      89  return true;
      -
      90 }
      +

      Definition at line 81 of file modelMatrix.cpp.

      +
      81  {
      +
      82  if(!this->ready) return false;
      +
      83  delete[] this->matrixIndex;
      +
      84  delete[] this->totalEdgeWeights;
      +
      85 
      +
      86  for(int i=0;i<this->matrixSize;i++){
      +
      87  delete[] this->edgeMatrix[i];
      +
      88  }
      +
      89  delete[] this->edgeMatrix;
      +
      90 
      +
      91  for(int i=0;i<this->matrixSize;i++){
      +
      92  delete[] this->valueMatrix[i];
      +
      93  }
      +
      94  delete[] this->valueMatrix;
      +
      95 
      +
      96  this->matrixSize = -1;
      +
      97  this->ready = false;
      +
      98  return true;
      +
      99 }
      -

      References edgeMatrix, matrixIndex, matrixSize, ready, totalEdgeWeights, and valueMatrix.

      +

      References edgeMatrix, matrixIndex, matrixSize, ready, totalEdgeWeights, and valueMatrix.

      -

      Referenced by Import(), and Train().

      +

      Referenced by Import(), and Train().

      Here is the caller graph for this function:
      - - - - + + + +
      @@ -556,61 +669,61 @@

      Definition at line 92 of file modelMatrix.cpp.

      -
      92  {
      -
      93 
      -
      94  std::cout << "{\n \"index\": \"";
      -
      95  for(int i=0;i<this->matrixSize;i++){
      -
      96  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
      -
      97  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
      -
      98  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
      -
      99  else if(i==0) std::cout << "\\\\xff";
      -
      100  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
      -
      101  else std::cout << this->matrixIndex[i];
      -
      102  }
      -
      103  std::cout <<
      -
      104  "\",\n"
      -
      105  " \"edgemap\": {\n";
      -
      106 
      -
      107  for(int i=0;i<this->matrixSize;i++){
      -
      108  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      -
      109  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      -
      110  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      -
      111  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      -
      112  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      -
      113  for(int j=0;j<this->matrixSize;j++){
      -
      114  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
      -
      115  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
      -
      116  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
      -
      117  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
      -
      118  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
      -
      119  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
      -
      120  if(j!=this->matrixSize-1) std::cout << ", ";
      -
      121  }
      -
      122  std::cout << "],\n";
      -
      123  }
      -
      124  std::cout << "},\n";
      -
      125 
      -
      126  std::cout << "\" weightmap\": {\n";
      -
      127  for(int i=0;i<this->matrixSize;i++){
      -
      128  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      -
      129  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      -
      130  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      -
      131  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      -
      132  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      -
      133 
      -
      134  for(int j=0;j<this->matrixSize;j++){
      -
      135  std::cout << this->valueMatrix[i][j];
      -
      136  if(j!=this->matrixSize-1) std::cout << ", ";
      -
      137  }
      -
      138  std::cout << "],\n";
      -
      139  }
      -
      140  std::cout << " }\n}\n";
      -
      141 }
      +

      Definition at line 101 of file modelMatrix.cpp.

      +
      101  {
      +
      102 
      +
      103  std::cout << "{\n \"index\": \"";
      +
      104  for(int i=0;i<this->matrixSize;i++){
      +
      105  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
      +
      106  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
      +
      107  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
      +
      108  else if(i==0) std::cout << "\\\\xff";
      +
      109  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
      +
      110  else std::cout << this->matrixIndex[i];
      +
      111  }
      +
      112  std::cout <<
      +
      113  "\",\n"
      +
      114  " \"edgemap\": {\n";
      +
      115 
      +
      116  for(int i=0;i<this->matrixSize;i++){
      +
      117  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      +
      118  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      +
      119  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      +
      120  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      +
      121  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      +
      122  for(int j=0;j<this->matrixSize;j++){
      +
      123  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
      +
      124  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
      +
      125  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
      +
      126  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
      +
      127  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
      +
      128  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
      +
      129  if(j!=this->matrixSize-1) std::cout << ", ";
      +
      130  }
      +
      131  std::cout << "],\n";
      +
      132  }
      +
      133  std::cout << "},\n";
      +
      134 
      +
      135  std::cout << "\" weightmap\": {\n";
      +
      136  for(int i=0;i<this->matrixSize;i++){
      +
      137  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      +
      138  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      +
      139  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      +
      140  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      +
      141  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      +
      142 
      +
      143  for(int j=0;j<this->matrixSize;j++){
      +
      144  std::cout << this->valueMatrix[i][j];
      +
      145  if(j!=this->matrixSize-1) std::cout << ", ";
      +
      146  }
      +
      147  std::cout << "],\n";
      +
      148  }
      +
      149  std::cout << " }\n}\n";
      +
      150 }
      -

      References edgeMatrix, matrixIndex, matrixSize, and valueMatrix.

      +

      References edgeMatrix, matrixIndex, matrixSize, and valueMatrix.

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      Here is the caller graph for this function:
      @@ -633,7 +746,7 @@

      - + @@ -649,8 +762,8 @@

      Returns
      vector of edges
      -

      Definition at line 172 of file model.h.

      -
      172 { return &edges;}
      +

      Definition at line 176 of file model.h.

      +
      176 { return &edges;}
      @@ -664,9 +777,9 @@

      std::vector<Edge<char >*>* Markov::Model< char >::Edges std::vector<Edge<char >*>* Markov::Model< char >::Edges ( )
      - + - + @@ -680,15 +793,15 @@

      Model::Export with std::ofstream.

      Returns
      True if successful, False for incomplete models or corrupt file formats
      -

      Example Use: Export file to filename

      -
      model.Export("test.mdl");
      +

      Example Use: Export file to filename

      +
      model.Export("test.mdl");
      -

      Definition at line 286 of file model.h.

      -
      286  {
      -
      287  std::ofstream exportfile;
      -
      288  exportfile.open(filename);
      -
      289  return this->Export(&exportfile);
      -
      290 }
      +

      Definition at line 300 of file model.h.

      +
      300  {
      +
      301  std::ofstream exportfile;
      +
      302  exportfile.open(filename);
      +
      303  return this->Export(&exportfile);
      +
      304 }
      @@ -702,7 +815,7 @@

      bool Markov::Model< char >::Export bool Markov::Model< char >::Export (const char * const char filename)
      - + @@ -719,32 +832,32 @@

      Returns
      True if successful, False for incomplete models.
      -

      Example Use: Export file to ofstream

      +

      Example Use: Export file to ofstream

      std::ofstream file("test.mdl");
      -
      model.Export(&file);
      +
      model.Export(&file);
      -

      Definition at line 274 of file model.h.

      -
      274  {
      - -
      276  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
      -
      277  e = this->edges[i];
      -
      278  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      -
      279  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      -
      280  }
      -
      281 
      -
      282  return true;
      -
      283 }
      +

      Definition at line 288 of file model.h.

      +
      288  {
      + +
      290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
      +
      291  e = this->edges[i];
      +
      292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      +
      293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      +
      294  }
      +
      295 
      +
      296  return true;
      +
      297 }
      - -

      ◆ FastRandomWalk()

      + +

      ◆ FastRandomWalk() [1/2]

      bool Markov::Model< char >::Export bool Markov::Model< char >::Export ( std::ofstream *  f)
      - + @@ -752,7 +865,7 @@

      - + @@ -805,35 +918,144 @@

      mp.Import("models/finished.mdl");
      -
      mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      +
      mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      + +

      Definition at line 217 of file modelMatrix.cpp.

      +
      217  {
      +
      218  std::ofstream wordlist;
      +
      219  if(bFileIO)
      +
      220  wordlist.open(wordlistFileName);
      +
      221  this->FastRandomWalk(n, &wordlist, minLen, maxLen, threads, bFileIO);
      +
      222  return 0;
      +
      223 }
      +
      +

      References FastRandomWalk().

      + +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      +
      +Here is the call graph for this function:
      +
      +
      + + + + + + + +
      +
      +Here is the caller graph for this function:
      +
      +
      + + + + +
      + + + + +

      ◆ FastRandomWalk() [2/2]

      + +
      +
      +
      void Markov::API::ModelMatrix::FastRandomWalk int Markov::API::ModelMatrix::FastRandomWalk ( unsigned long int  n, const char * const char wordlistFileName,
      + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      int Markov::API::ModelMatrix::FastRandomWalk (unsigned long int n,
      std::ofstream * wordlist,
      int minLen = 6,
      int maxLen = 12,
      int threads = 20,
      bool bFileIO = true 
      )
      +
      +protected
      +

      + +

      Random walk on the Matrix-reduced Markov::Model.

      +

      This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.

      +

      If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations. This comes at a minor performance penalty.

      +

      While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5

      +

      This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.

      +
      Parameters
      + + + + + + + +
      n- Number of passwords to generate.
      wordlistFileName- Filename to write to
      minLen- Minimum password length to generate
      maxLen- Maximum password length to generate
      threads- number of OS threads to spawn
      bFileIO- If false, filename will be ignored and will output to stdout.
      +
      +
      +
      +
      mp.Import("models/finished.mdl");
      +
      mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      -

      Definition at line 195 of file modelMatrix.cpp.

      -
      195  {
      -
      196 
      -
      197 
      -
      198  std::ofstream wordlist;
      -
      199  if(bFileIO)
      -
      200  wordlist.open(wordlistFileName);
      -
      201 
      -
      202  std::mutex mlock;
      -
      203  if(n<=50000000ull) return this->FastRandomWalkPartition(&mlock, &wordlist, n, minLen, maxLen, bFileIO, threads);
      -
      204  else{
      -
      205  int numberOfPartitions = n/50000000ull;
      -
      206  for(int i=0;i<numberOfPartitions;i++)
      -
      207  this->FastRandomWalkPartition(&mlock, &wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
      -
      208  }
      -
      209 
      -
      210 
      -
      211 }
      +

      Definition at line 204 of file modelMatrix.cpp.

      +
      204  {
      +
      205 
      +
      206 
      +
      207  std::mutex mlock;
      +
      208  if(n<=50000000ull) this->FastRandomWalkPartition(&mlock, wordlist, n, minLen, maxLen, bFileIO, threads);
      +
      209  else{
      +
      210  int numberOfPartitions = n/50000000ull;
      +
      211  for(int i=0;i<numberOfPartitions;i++)
      +
      212  this->FastRandomWalkPartition(&mlock, wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
      +
      213  }
      +
      214  return 0;
      +
      215 }
      -

      References FastRandomWalkPartition().

      +

      References FastRandomWalkPartition().

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      +

      Referenced by FastRandomWalk().

      Here is the call graph for this function:
      -
      - +
      + @@ -843,9 +1065,10 @@

      Here is the caller graph for this function:

      -
      - - +
      + + +
      @@ -937,30 +1160,30 @@

      Definition at line 214 of file modelMatrix.cpp.

      -
      214  {
      -
      215 
      -
      216  int iterationsPerThread = n/threads;
      -
      217  int iterationsPerThreadCarryOver = n%threads;
      -
      218 
      -
      219  std::vector<std::thread*> threadsV;
      -
      220 
      -
      221  int id = 0;
      -
      222  for(int i=0;i<threads;i++){
      -
      223  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
      -
      224  id++;
      -
      225  }
      -
      226 
      -
      227  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
      -
      228 
      -
      229  for(int i=0;i<threads;i++){
      -
      230  threadsV[i]->join();
      -
      231  }
      -
      232 }
      +

      Definition at line 225 of file modelMatrix.cpp.

      +
      225  {
      +
      226 
      +
      227  int iterationsPerThread = n/threads;
      +
      228  int iterationsPerThreadCarryOver = n%threads;
      +
      229 
      +
      230  std::vector<std::thread*> threadsV;
      +
      231 
      +
      232  int id = 0;
      +
      233  for(int i=0;i<threads;i++){
      +
      234  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
      +
      235  id++;
      +
      236  }
      +
      237 
      +
      238  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
      +
      239 
      +
      240  for(int i=0;i<threads;i++){
      +
      241  threadsV[i]->join();
      +
      242  }
      +
      243 }
      -

      References FastRandomWalkThread().

      +

      References FastRandomWalkThread().

      -

      Referenced by FastRandomWalk().

      +

      Referenced by FastRandomWalk().

      Here is the call graph for this function:
      @@ -976,8 +1199,9 @@

      - - + + +

      @@ -1065,60 +1289,60 @@

      Definition at line 144 of file modelMatrix.cpp.

      -
      144  {
      -
      145  if(n==0) return;
      -
      146 
      -
      147  Markov::Random::Marsaglia MarsagliaRandomEngine;
      -
      148  char* e;
      -
      149  char *res = new char[maxLen*n];
      -
      150  int index = 0;
      -
      151  char next;
      -
      152  int len=0;
      -
      153  long int selection;
      -
      154  char cur;
      -
      155  long int bufferctr = 0;
      -
      156  for (int i = 0; i < n; i++) {
      -
      157  cur=199;
      -
      158  len=0;
      -
      159  while (true) {
      -
      160  e = strchr(this->matrixIndex, cur);
      -
      161  index = e - this->matrixIndex;
      -
      162  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
      -
      163  for(int j=0;j<this->matrixSize;j++){
      -
      164  selection -= this->valueMatrix[index][j];
      -
      165  if (selection < 0){
      -
      166  next = this->edgeMatrix[index][j];
      -
      167  break;
      -
      168  }
      -
      169  }
      -
      170 
      -
      171  if (len >= maxLen) break;
      -
      172  else if ((next < 0) && (len < minLen)) continue;
      -
      173  else if (next < 0) break;
      -
      174  cur = next;
      -
      175  res[bufferctr + len++] = cur;
      -
      176  }
      -
      177  res[bufferctr + len++] = '\n';
      -
      178  bufferctr+=len;
      -
      179 
      -
      180  }
      -
      181  if(bFileIO){
      -
      182  mlock->lock();
      -
      183  *wordlist << res;
      -
      184  mlock->unlock();
      -
      185  }else{
      -
      186  mlock->lock();
      -
      187  std::cout << res;
      -
      188  mlock->unlock();
      +

      Definition at line 153 of file modelMatrix.cpp.

      +
      153  {
      +
      154  if(n==0) return;
      +
      155 
      +
      156  Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      157  char* e;
      +
      158  char *res = new char[(maxLen+2)*n];
      +
      159  int index = 0;
      +
      160  char next;
      +
      161  int len=0;
      +
      162  long int selection;
      +
      163  char cur;
      +
      164  long int bufferctr = 0;
      +
      165  for (int i = 0; i < n; i++) {
      +
      166  cur=199;
      +
      167  len=0;
      +
      168  while (true) {
      +
      169  e = strchr(this->matrixIndex, cur);
      +
      170  index = e - this->matrixIndex;
      +
      171  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
      +
      172  for(int j=0;j<this->matrixSize;j++){
      +
      173  selection -= this->valueMatrix[index][j];
      +
      174  if (selection < 0){
      +
      175  next = this->edgeMatrix[index][j];
      +
      176  break;
      +
      177  }
      +
      178  }
      +
      179 
      +
      180  if (len >= maxLen) break;
      +
      181  else if ((next < 0) && (len < minLen)) continue;
      +
      182  else if (next < 0) break;
      +
      183  cur = next;
      +
      184  res[bufferctr + len++] = cur;
      +
      185  }
      +
      186  res[bufferctr + len++] = '\n';
      +
      187  bufferctr+=len;
      +
      188 
      189  }
      -
      190  delete res;
      -
      191 
      -
      192 }
      +
      190  if(bFileIO){
      +
      191  mlock->lock();
      +
      192  *wordlist << res;
      +
      193  mlock->unlock();
      +
      194  }else{
      +
      195  mlock->lock();
      +
      196  std::cout << res;
      +
      197  mlock->unlock();
      +
      198  }
      +
      199  delete res;
      +
      200 
      +
      201 }
      -

      References edgeMatrix, matrixIndex, matrixSize, Markov::Random::Marsaglia::random(), totalEdgeWeights, and valueMatrix.

      +

      References edgeMatrix, matrixIndex, matrixSize, Markov::Random::Marsaglia::random(), totalEdgeWeights, and valueMatrix.

      -

      Referenced by FastRandomWalkPartition().

      +

      Referenced by FastRandomWalkPartition().

      Here is the call graph for this function:
      @@ -1133,9 +1357,10 @@

      - - - + + + +

      @@ -1160,7 +1385,7 @@

      - const char *  + const charwordlistFileName, @@ -1208,32 +1433,32 @@

      Definition at line 110 of file markovPasswords.cpp.

      -
      110  {
      -
      111  char* res;
      -
      112  char print[100];
      -
      113  std::ofstream wordlist;
      -
      114  wordlist.open(wordlistFileName);
      -
      115  std::mutex mlock;
      -
      116  int iterationsPerThread = n/threads;
      -
      117  int iterationsCarryOver = n%threads;
      -
      118  std::vector<std::thread*> threadsV;
      -
      119  for(int i=0;i<threads;i++){
      -
      120  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
      -
      121  }
      -
      122 
      -
      123  for(int i=0;i<threads;i++){
      -
      124  threadsV[i]->join();
      -
      125  delete threadsV[i];
      -
      126  }
      -
      127 
      -
      128  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
      -
      129 
      -
      130 }
      +

      Definition at line 118 of file markovPasswords.cpp.

      +
      118  {
      +
      119  char* res;
      +
      120  char print[100];
      +
      121  std::ofstream wordlist;
      +
      122  wordlist.open(wordlistFileName);
      +
      123  std::mutex mlock;
      +
      124  int iterationsPerThread = n/threads;
      +
      125  int iterationsCarryOver = n%threads;
      +
      126  std::vector<std::thread*> threadsV;
      +
      127  for(int i=0;i<threads;i++){
      +
      128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
      +
      129  }
      +
      130 
      +
      131  for(int i=0;i<threads;i++){
      +
      132  threadsV[i]->join();
      +
      133  delete threadsV[i];
      +
      134  }
      +
      135 
      +
      136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
      +
      137 
      +
      138 }
      -

      References Markov::API::MarkovPasswords::GenerateThread().

      +

      References Markov::API::MarkovPasswords::GenerateThread().

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and Markov::GUI::Generate::generation().

      Here is the call graph for this function:
      @@ -1249,8 +1474,9 @@

      - + +

      @@ -1321,23 +1547,23 @@

      Definition at line 132 of file markovPasswords.cpp.

      -
      132  {
      -
      133  char* res = new char[maxLen+5];
      -
      134  if(n==0) return;
      -
      135 
      -
      136  Markov::Random::Marsaglia MarsagliaRandomEngine;
      -
      137  for (int i = 0; i < n; i++) {
      -
      138  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
      -
      139  outputLock->lock();
      -
      140  *wordlist << res << "\n";
      -
      141  outputLock->unlock();
      -
      142  }
      -
      143 }
      +

      Definition at line 140 of file markovPasswords.cpp.

      +
      140  {
      +
      141  char* res = new char[maxLen+5];
      +
      142  if(n==0) return;
      +
      143 
      +
      144  Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      145  for (int i = 0; i < n; i++) {
      +
      146  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
      +
      147  outputLock->lock();
      +
      148  *wordlist << res << "\n";
      +
      149  outputLock->unlock();
      +
      150  }
      +
      151 }
      -

      References Markov::Model< NodeStorageType >::RandomWalk().

      +

      References Markov::Model< NodeStorageType >::RandomWalk().

      -

      Referenced by Markov::API::MarkovPasswords::Generate().

      +

      Referenced by Markov::API::MarkovPasswords::Generate().

      Here is the call graph for this function:
      @@ -1352,9 +1578,10 @@

      - - + + +

      @@ -1369,7 +1596,7 @@

      void Markov::API::ModelMatrix::Import ( - const char *  + const charfilename) @@ -1378,20 +1605,20 @@

      Model::Import with std::ifstream.

      Returns
      True if successful, False for incomplete models or corrupt file formats
      -

      Example Use: Import a file with filename

      -
      model.Import("test.mdl");
      +

      Example Use: Import a file with filename

      +
      model.Import("test.mdl");

      Construct the matrix when done.

      -

      Definition at line 10 of file modelMatrix.cpp.

      -
      10  {
      -
      11  this->DeallocateMatrix();
      - -
      13  this->ConstructMatrix();
      -
      14 }
      +

      Definition at line 19 of file modelMatrix.cpp.

      +
      19  {
      +
      20  this->DeallocateMatrix();
      + +
      22  this->ConstructMatrix();
      +
      23 }
      -

      References ConstructMatrix(), DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

      +

      References ConstructMatrix(), DeallocateMatrix(), and Markov::Model< NodeStorageType >::Import().

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

      Here is the call graph for this function:
      @@ -1416,7 +1643,7 @@

      - +

      @@ -1432,7 +1659,7 @@

      - + @@ -1449,68 +1676,58 @@

      Returns
      True if successful, False for incomplete models or corrupt file formats
      -

      Example Use: Import a file from ifstream

      +

      Example Use: Import a file from ifstream

      std::ifstream file("test.mdl");
      -
      model.Import(&file);
      +
      model.Import(&file);
      -

      Definition at line 207 of file model.h.

      -
      207  {
      -
      208  std::string cell;
      -
      209 
      -
      210  char src;
      -
      211  char target;
      -
      212  long int oc;
      -
      213 
      -
      214  while (std::getline(*f, cell)) {
      -
      215  //std::cout << "cell: " << cell << std::endl;
      -
      216  src = cell[0];
      -
      217  target = cell[cell.length() - 1];
      -
      218  char* j;
      -
      219  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
      -
      220  //std::cout << oc << "\n";
      - - - -
      224  if (this->nodes.find(src) == this->nodes.end()) {
      -
      225  srcN = new Markov::Node<NodeStorageType>(src);
      -
      226  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
      -
      227  //std::cout << "Creating new node at start.\n";
      -
      228  }
      -
      229  else {
      -
      230  srcN = this->nodes.find(src)->second;
      -
      231  }
      -
      232 
      -
      233  if (this->nodes.find(target) == this->nodes.end()) {
      -
      234  targetN = new Markov::Node<NodeStorageType>(target);
      -
      235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
      -
      236  //std::cout << "Creating new node at end.\n";
      +

      Definition at line 216 of file model.h.

      +
      216  {
      +
      217  std::string cell;
      +
      218 
      +
      219  char src;
      +
      220  char target;
      +
      221  long int oc;
      +
      222 
      +
      223  while (std::getline(*f, cell)) {
      +
      224  //std::cout << "cell: " << cell << std::endl;
      +
      225  src = cell[0];
      +
      226  target = cell[cell.length() - 1];
      +
      227  char* j;
      +
      228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
      +
      229  //std::cout << oc << "\n";
      + + + +
      233  if (this->nodes.find(src) == this->nodes.end()) {
      +
      234  srcN = new Markov::Node<NodeStorageType>(src);
      +
      235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
      +
      236  //std::cout << "Creating new node at start.\n";
      237  }
      238  else {
      -
      239  targetN = this->nodes.find(target)->second;
      +
      239  srcN = this->nodes.find(src)->second;
      240  }
      -
      241  e = srcN->Link(targetN);
      -
      242  e->AdjustEdge(oc);
      -
      243  this->edges.push_back(e);
      -
      244 
      -
      245  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
      -
      246 
      -
      247 
      -
      248  }
      -
      249 
      -
      250  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      -
      251  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      -
      252  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      -
      253  return lhs->EdgeWeight() > rhs->EdgeWeight();
      -
      254  });
      -
      255  //for(int i=0;i<x.second->edgesV.size();i++)
      -
      256  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      -
      257  //std::cout << "\n";
      -
      258  }
      -
      259  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      -
      260  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      -
      261 
      -
      262  return true;
      -
      263 }
      +
      241 
      +
      242  if (this->nodes.find(target) == this->nodes.end()) {
      +
      243  targetN = new Markov::Node<NodeStorageType>(target);
      +
      244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
      +
      245  //std::cout << "Creating new node at end.\n";
      +
      246  }
      +
      247  else {
      +
      248  targetN = this->nodes.find(target)->second;
      +
      249  }
      +
      250  e = srcN->Link(targetN);
      +
      251  e->AdjustEdge(oc);
      +
      252  this->edges.push_back(e);
      +
      253 
      +
      254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
      +
      255 
      +
      256 
      +
      257  }
      +
      258 
      +
      259  this->OptimizeEdgeOrder();
      +
      260 
      +
      261  return true;
      +
      262 }
      @@ -1524,7 +1741,7 @@

      bool Markov::Model< char >::Import bool Markov::Model< char >::Import ( std::ifstream *  f)
      - + @@ -1540,8 +1757,8 @@

      Node.

      Returns
      starter node with 00 NodeValue
      -

      Definition at line 177 of file model.h.

      -
      177 { return &nodes;}
      +

      Definition at line 181 of file model.h.

      +
      181 { return &nodes;}
      @@ -1557,7 +1774,7 @@

      std::ifstream * Markov::API::MarkovPasswords::OpenDatasetFile

      - + @@ -1578,20 +1795,20 @@

      Returns
      ifstream* to the the dataset file
      -

      Definition at line 43 of file markovPasswords.cpp.

      -
      43  {
      -
      44 
      -
      45  std::ifstream* datasetFile;
      -
      46 
      -
      47  std::ifstream newFile(filename);
      -
      48 
      -
      49  datasetFile = &newFile;
      -
      50 
      -
      51  this->Import(datasetFile);
      -
      52  return datasetFile;
      -
      53 }
      +

      Definition at line 51 of file markovPasswords.cpp.

      +
      51  {
      +
      52 
      +
      53  std::ifstream* datasetFile;
      +
      54 
      +
      55  std::ifstream newFile(filename);
      +
      56 
      +
      57  datasetFile = &newFile;
      +
      58 
      +
      59  this->Import(datasetFile);
      +
      60  return datasetFile;
      +
      61 }
      -

      References Markov::Model< NodeStorageType >::Import().

      +

      References Markov::Model< NodeStorageType >::Import().

      Here is the call graph for this function:
      @@ -1602,6 +1819,45 @@

      +

      ◆ OptimizeEdgeOrder()

      + +
      +
      +

      std::map<char , Node<char >*>* Markov::Model< char >::Nodes std::map<char , Node<char >*>* Markov::Model< char >::Nodes ( ) (const char * const char filename)
      + + + + +
      + + + + +
      void Markov::Model< char >::OptimizeEdgeOrder
      +
      +inherited
      +

      + +

      Sort edges of all nodes in the model ordered by edge weights.

      + +

      Definition at line 265 of file model.h.

      +
      265  {
      +
      266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      +
      267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      +
      268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      +
      269  return lhs->EdgeWeight() > rhs->EdgeWeight();
      +
      270  });
      +
      271  //for(int i=0;i<x.second->edgesV.size();i++)
      +
      272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      +
      273  //std::cout << "\n";
      +
      274  }
      +
      275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      +
      276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      +
      277 }
      +
      @@ -1614,7 +1870,7 @@

      - + @@ -1655,7 +1911,7 @@

      Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

      This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

      This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

      -

      Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

      +

      Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

      Model.import("model.mdl");
      char* res = new char[11];
      Markov::Random::Marsaglia MarsagliaRandomEngine;
      @@ -1674,35 +1930,35 @@

      Returns
      Null terminated string that was generated.
      -

      Definition at line 293 of file model.h.

      -
      293  {
      - -
      295  int len = 0;
      - -
      297  while (true) {
      -
      298  temp_node = n->RandomNext(randomEngine);
      -
      299  if (len >= maxSetting) {
      -
      300  break;
      -
      301  }
      -
      302  else if ((temp_node == NULL) && (len < minSetting)) {
      -
      303  continue;
      -
      304  }
      -
      305 
      -
      306  else if (temp_node == NULL){
      -
      307  break;
      -
      308  }
      -
      309 
      -
      310  n = temp_node;
      -
      311 
      -
      312  buffer[len++] = n->NodeValue();
      -
      313  }
      -
      314 
      -
      315  //null terminate the string
      -
      316  buffer[len] = 0x00;
      -
      317 
      -
      318  //do something with the generated string
      -
      319  return buffer; //for now
      -
      320 }
      +

      Definition at line 307 of file model.h.

      +
      307  {
      + +
      309  int len = 0;
      + +
      311  while (true) {
      +
      312  temp_node = n->RandomNext(randomEngine);
      +
      313  if (len >= maxSetting) {
      +
      314  break;
      +
      315  }
      +
      316  else if ((temp_node == NULL) && (len < minSetting)) {
      +
      317  continue;
      +
      318  }
      +
      319 
      +
      320  else if (temp_node == NULL){
      +
      321  break;
      +
      322  }
      +
      323 
      +
      324  n = temp_node;
      +
      325 
      +
      326  buffer[len++] = n->NodeValue();
      +
      327  }
      +
      328 
      +
      329  //null terminate the string
      +
      330  buffer[len] = 0x00;
      +
      331 
      +
      332  //do something with the generated string
      +
      333  return buffer; //for now
      +
      334 }

      @@ -1718,7 +1974,7 @@

      std::ofstream * Markov::API::MarkovPasswords::Save

      - + @@ -1739,19 +1995,19 @@

      Returns
      std::ofstream* of the exported file.
      -

      Definition at line 98 of file markovPasswords.cpp.

      -
      98  {
      -
      99  std::ofstream* exportFile;
      -
      100 
      -
      101  std::ofstream newFile(filename);
      -
      102 
      -
      103  exportFile = &newFile;
      -
      104 
      -
      105  this->Export(exportFile);
      -
      106  return exportFile;
      -
      107 }
      +

      Definition at line 106 of file markovPasswords.cpp.

      +
      106  {
      +
      107  std::ofstream* exportFile;
      +
      108 
      +
      109  std::ofstream newFile(filename);
      +
      110 
      +
      111  exportFile = &newFile;
      +
      112 
      +
      113  this->Export(exportFile);
      +
      114  return exportFile;
      +
      115 }
      -

      References Markov::Model< NodeStorageType >::Export().

      +

      References Markov::Model< NodeStorageType >::Export().

      Here is the call graph for this function:
      @@ -1774,7 +2030,7 @@

      char * Markov::Model< char >::RandomWalk char * Markov::Model< char >::RandomWalk ( Markov::Random::RandomEngine randomEngine, (const char * const char filename)
      - + @@ -1790,8 +2046,8 @@

      Node.

      Returns
      starter node with 00 NodeValue
      -

      Definition at line 167 of file model.h.

      -
      167 { return starterNode;}
      +

      Definition at line 171 of file model.h.

      +
      171 { return starterNode;}
      @@ -1804,13 +2060,13 @@

      void Markov::API::ModelMatrix::Train

      - + - + @@ -1841,16 +2097,16 @@

      mp.Train("password.corpus");

      Construct the matrix when done.

      -

      Definition at line 16 of file modelMatrix.cpp.

      -
      16  {
      -
      17  this->DeallocateMatrix();
      -
      18  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
      -
      19  this->ConstructMatrix();
      -
      20 }
      +

      Definition at line 25 of file modelMatrix.cpp.

      +
      25  {
      +
      26  this->DeallocateMatrix();
      +
      27  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
      +
      28  this->ConstructMatrix();
      +
      29 }
      -

      References ConstructMatrix(), DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

      +

      References ConstructMatrix(), DeallocateMatrix(), and Markov::API::MarkovPasswords::Train().

      -

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE(), and main().

      +

      Referenced by Markov::Markopy::BOOST_PYTHON_MODULE().

      Here is the call graph for this function:
      @@ -1878,9 +2134,8 @@

      - + -

      @@ -1904,7 +2159,7 @@

      - + @@ -1929,30 +2184,30 @@

      Definition at line 77 of file markovPasswords.cpp.

      -
      77  {
      -
      78  char format_str[] ="%ld,%s";
      -
      79  format_str[3]=delimiter;
      -
      80  std::string line;
      -
      81  while (listhandler->next(&line) && keepRunning) {
      -
      82  long int oc;
      -
      83  if (line.size() > 100) {
      -
      84  line = line.substr(0, 100);
      -
      85  }
      -
      86  char* linebuf = new char[line.length()+5];
      -
      87 #ifdef _WIN32
      -
      88  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
      -
      89 #else
      -
      90  sscanf(line.c_str(), format_str, &oc, linebuf);
      -
      91 #endif
      -
      92  this->AdjustEdge((const char*)linebuf, oc);
      -
      93  delete linebuf;
      -
      94  }
      -
      95 }
      +

      Definition at line 85 of file markovPasswords.cpp.

      +
      85  {
      +
      86  char format_str[] ="%ld,%s";
      +
      87  format_str[3]=delimiter;
      +
      88  std::string line;
      +
      89  while (listhandler->next(&line) && keepRunning) {
      +
      90  long int oc;
      +
      91  if (line.size() > 100) {
      +
      92  line = line.substr(0, 100);
      +
      93  }
      +
      94  char* linebuf = new char[line.length()+5];
      +
      95 #ifdef _WIN32
      +
      96  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
      +
      97 #else
      +
      98  sscanf(line.c_str(), format_str, &oc, linebuf);
      +
      99 #endif
      +
      100  this->AdjustEdge((const char*)linebuf, oc);
      +
      101  delete linebuf;
      +
      102  }
      +
      103 }
      -

      References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

      +

      References Markov::Model< NodeStorageType >::AdjustEdge(), keepRunning, and Markov::API::Concurrency::ThreadSharedListHandler::next().

      -

      Referenced by Markov::API::MarkovPasswords::Train().

      +

      Referenced by Markov::API::MarkovPasswords::Train().

      Here is the call graph for this function:
      @@ -1968,11 +2223,12 @@

      - - - - - + + + + + +

      @@ -1999,7 +2255,7 @@

      -

      Definition at line 106 of file markovPasswords.h.

      +

      Definition at line 123 of file markovPasswords.h.

      @@ -2013,7 +2269,7 @@

      Node<char >* Markov::Model< char >::StarterNode Node<char >* Markov::Model< char >::StarterNode ( ) (const char * const char datasetFileName,
      char char  delimiter,
      char char  delimiter 
      - +
      char** Markov::API::ModelMatrix::edgeMatrixchar** Markov::API::ModelMatrix::edgeMatrix
      @@ -2025,9 +2281,9 @@

      Definition at line 136 of file modelMatrix.h.

      +

      Definition at line 175 of file modelMatrix.h.

      -

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      +

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      @@ -2041,7 +2297,7 @@

      - +
      std::vector<Edge<char >*> Markov::Model< char >::edgesstd::vector<Edge<char >*> Markov::Model< char >::edges
      @@ -2053,7 +2309,7 @@

      Definition at line 195 of file model.h.

      +

      Definition at line 204 of file model.h.

      @@ -2067,7 +2323,7 @@

      - +
      char* Markov::API::ModelMatrix::matrixIndexchar* Markov::API::ModelMatrix::matrixIndex
      @@ -2079,9 +2335,9 @@

      Definition at line 151 of file modelMatrix.h.

      +

      Definition at line 190 of file modelMatrix.h.

      -

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      +

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      @@ -2107,9 +2363,9 @@

      Definition at line 146 of file modelMatrix.h.

      +

      Definition at line 185 of file modelMatrix.h.

      -

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      +

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), FastRandomWalkThread(), and Markov::API::CUDA::CUDAModelMatrix::FlattenMatrix().

      @@ -2136,7 +2392,7 @@

      Definition at line 107 of file markovPasswords.h.

      +

      Definition at line 124 of file markovPasswords.h.

      @@ -2150,7 +2406,7 @@

      - +
      std::map<char , Node<char >*> Markov::Model< char >::nodesstd::map<char , Node<char >*> Markov::Model< char >::nodes
      @@ -2162,7 +2418,7 @@

      Definition at line 184 of file model.h.

      +

      Definition at line 193 of file model.h.

      @@ -2189,7 +2445,7 @@

      Definition at line 108 of file markovPasswords.h.

      +

      Definition at line 125 of file markovPasswords.h.

      @@ -2215,9 +2471,9 @@

      Definition at line 161 of file modelMatrix.h.

      +

      Definition at line 200 of file modelMatrix.h.

      -

      Referenced by ConstructMatrix(), DeallocateMatrix(), and ModelMatrix().

      +

      Referenced by ConstructMatrix(), DeallocateMatrix(), and ModelMatrix().

      @@ -2231,7 +2487,7 @@

      - +
      Node<char >* Markov::Model< char >::starterNodeNode<char >* Markov::Model< char >::starterNode
      @@ -2243,7 +2499,7 @@

      Node of this model.

      -

      Definition at line 189 of file model.h.

      +

      Definition at line 198 of file model.h.

      @@ -2269,9 +2525,9 @@

      Edge Weights.

      -

      Definition at line 156 of file modelMatrix.h.

      +

      Definition at line 195 of file modelMatrix.h.

      -

      Referenced by ConstructMatrix(), DeallocateMatrix(), and FastRandomWalkThread().

      +

      Referenced by ConstructMatrix(), DeallocateMatrix(), and FastRandomWalkThread().

      @@ -2297,9 +2553,9 @@

      Definition at line 141 of file modelMatrix.h.

      +

      Definition at line 180 of file modelMatrix.h.

      -

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      +

      Referenced by ConstructMatrix(), DeallocateMatrix(), DumpJSON(), and FastRandomWalkThread().

      @@ -2309,57 +2565,57 @@

      void AdjustEdge(const char *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:323
      -
      std::map< char, Node< char > * > * Nodes()
      Return starter Node.
      Definition: model.h:177
      -
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:10
      -
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:156
      -
      void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      -
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:226
      -
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:158
      -
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:13
      -
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:207
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      Markov::Model with char represented nodes.
      -
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:141
      -
      std::vector< Edge< storageType > * > edgesV
      Definition: node.h:165
      -
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:153
      -
      char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
      Do a random walk on this model.
      Definition: model.h:293
      -
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:274
      - -
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:161
      +
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:337
      +
      std::map< char, Node< char > * > * Nodes()
      Return starter Node.
      Definition: model.h:181
      +
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:19
      +
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:195
      +
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:234
      +
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:165
      +
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:23
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      Markov::Model with char represented nodes.
      +
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:180
      +
      std::vector< Edge< storageType > * > edgesV
      Definition: node.h:173
      +
      void OptimizeEdgeOrder()
      Sort edges of all nodes in the model ordered by edge weights.
      Definition: model.h:265
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      char * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, char *buffer)
      Do a random walk on this model.
      Definition: model.h:307
      +
      __device__ char * strchr(char *p, char c, int s_len)
      srtchr implementation on device space
      +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      + +
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:200
      -
      Node< char > * StarterNode()
      Return starter Node.
      Definition: model.h:167
      -
      unsigned long random()
      Generate Random Number.
      Definition: random.h:131
      -
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:146
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      -
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:130
      -
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:212
      -
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:207
      -
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:201
      -
      std::vector< Edge< char > * > edges
      A list of all edges in this model.
      Definition: model.h:195
      -
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      -
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:252
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      -
      bool next(std::string *line)
      Read the next line from the file.
      -
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      +
      Node< char > * StarterNode()
      Return starter Node.
      Definition: model.h:171
      +
      unsigned long random()
      Generate Random Number.
      Definition: random.h:140
      +
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:185
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      +
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:220
      +
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:215
      +
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:210
      +
      std::vector< Edge< char > * > edges
      A list of all edges in this model.
      Definition: model.h:204
      +
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      +
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:260
      +
      int FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      bool next(std::string *line)
      Read the next line from the file.
      +
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      f
      output file handle
      Definition: model_2gram.py:16
      -
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:72
      +
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:81
      -
      __device__ char * strchr(char *p, char c, int s_len)
      srtchr implementation on device space
      -
      std::map< char, Node< char > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:184
      -
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:22
      -
      Node< char > * starterNode
      Starter Node of this model.
      Definition: model.h:189
      -
      static volatile int keepRunning
      - -
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      -
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:151
      -
      Edge class used to link nodes in the model together.
      Definition: model.h:26
      -
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:136
      +
      std::map< char, Node< char > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:193
      +
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:31
      +
      Node< char > * starterNode
      Starter Node of this model.
      Definition: model.h:198
      +
      static volatile int keepRunning
      +
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      +
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:190
      +
      Edge class used to link nodes in the model together.
      Definition: model.h:30
      +
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:175
      +
      + +
      +
      +
      + +
      + +
      +
      + + +
      + +
      + +
      +
      +
      Markov::GUI::Generate Member List
      +
      +
      + +

      This is the complete list of members for Markov::GUI::Generate, including all inherited members.

      + + + + + + + +
      Generate(QWidget *parent=Q_NULLPTR)Markov::GUI::Generate
      generation()Markov::GUI::Generateslot
      home()Markov::GUI::Generateslot
      train()Markov::GUI::Generateslot
      uiMarkov::GUI::Generateprivate
      vis()Markov::GUI::Generateslot
      +
      + + + + diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate.html b/docs/dark/class_markov_1_1_g_u_i_1_1_generate.html new file mode 100644 index 00000000..de2dd76b --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate.html @@ -0,0 +1,464 @@ + + + + + + + +Markopy: Markov::GUI::Generate Class Reference + + + + + + + + + + + + + + +
      +
      + + + + + + +
      +
      Markopy +
      +
      Utilizing Markov Models for brute forcing attacks
      +
      +
      + + + + + + + +
      +
      + +
      +
      +
      + +
      + +
      +
      + + +
      + +
      + +
      + +
      +
      Markov::GUI::Generate Class Reference
      +
      +
      + +

      QT Generation page class. + More...

      + +

      #include <Generate.h>

      +
      +Inheritance diagram for Markov::GUI::Generate:
      +
      +
      Inheritance graph
      + + + + +
      [legend]
      +
      +Collaboration diagram for Markov::GUI::Generate:
      +
      +
      Collaboration graph
      + + + + + +
      [legend]
      + + + + + + + + + + +

      +Public Slots

      void home ()
       
      void generation ()
       
      void train ()
       
      void vis ()
       
      + + + +

      +Public Member Functions

       Generate (QWidget *parent=Q_NULLPTR)
       
      + + + +

      +Private Attributes

      Ui::Generate ui
       
      +

      Detailed Description

      +

      QT Generation page class.

      + +

      Definition at line 15 of file Generate.h.

      +

      Constructor & Destructor Documentation

      + +

      ◆ Generate()

      + +
      +
      + + + + + + + + +
      Generate::Generate (QWidget * parent = Q_NULLPTR)
      +
      + +

      Definition at line 20 of file Generate.cpp.

      +
      21  : QMainWindow(parent)
      +
      22 {
      +
      23  ui.setupUi(this);
      +
      24 
      +
      25  QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {generation(); });
      +
      26  QObject::connect(ui.pushButton_4, &QPushButton::clicked, this, [this] {home(); });
      +
      27  QObject::connect(ui.pushButton_3, &QPushButton::clicked, this, [this] {train(); });
      +
      28  QObject::connect(ui.pushButton_2, &QPushButton::clicked, this, [this] {vis(); });
      +
      29 
      +
      30 
      +
      31  ui.pushButton->setVisible(false);
      +
      32  ui.lineEdit->setVisible(false);
      +
      33  ui.lineEdit_2->setVisible(false);
      +
      34  ui.lineEdit_3->setVisible(false);
      +
      35  ui.label_3->setVisible(false);
      +
      36  ui.label_4->setVisible(false);
      +
      37  ui.label_5->setVisible(false);
      +
      38 
      +
      39 
      +
      40 }
      +
      +

      References ui.

      + +
      +
      +

      Member Function Documentation

      + +

      ◆ generation

      + +
      +
      + + + + + +
      + + + + + + + +
      void Generate::generation ()
      +
      +slot
      +
      + +

      Definition at line 42 of file Generate.cpp.

      +
      42  {
      +
      43 
      +
      44 
      +
      45 
      +
      46 
      +
      47  QString file_name = QFileDialog::getOpenFileName(this, "Open a File", QDir::homePath());
      +
      48  QFile file(file_name);
      +
      49 
      +
      50 
      +
      51 
      +
      52  int numberPass = ui.lineEdit->text().toInt();
      +
      53  int minLen = ui.lineEdit_2->text().toInt();
      +
      54  int maxLen = ui.lineEdit_3->text().toInt();
      +
      55  char* cstr;
      +
      56  std::string fname = file_name.toStdString();
      +
      57  cstr = new char[fname.size() + 1];
      +
      58  strcpy(cstr, fname.c_str());
      +
      59 
      +
      60  ui.label_6->setText("GENERATING!");
      +
      61 
      + +
      63  mp.Import("src\\CLI\\sample_models\\2gram-trained.mdl");
      +
      64 
      +
      65  mp.Generate(numberPass,cstr,minLen,maxLen);
      +
      66 
      +
      67  if (!file.open(QFile::ReadOnly | QFile::Text)) {
      +
      68  QMessageBox::warning(this, "Error", "File Not Open!");
      +
      69  }
      +
      70  QTextStream in(&file);
      +
      71  QString text = in.readAll();
      +
      72  ui.plainTextEdit->setPlainText(text);
      +
      73 
      +
      74  ui.label_6->setText("DONE!");
      +
      75 
      +
      76 
      +
      77 
      +
      78  file.close();
      +
      79 }
      +
      +

      References Markov::API::MarkovPasswords::Generate(), and ui.

      +
      +Here is the call graph for this function:
      +
      +
      + + + + + + +
      + +
      +
      + +

      ◆ home

      + +
      +
      + + + + + +
      + + + + + + + +
      void Generate::home ()
      +
      +slot
      +
      + +

      Definition at line 121 of file Generate.cpp.

      +
      121  {
      +
      122  CLI* w = new CLI;
      +
      123  w->show();
      +
      124  this->close();
      +
      125 }
      +
      +
      +
      + +

      ◆ train

      + +
      +
      + + + + + +
      + + + + + + + +
      void Generate::train ()
      +
      +slot
      +
      + +

      Definition at line 82 of file Generate.cpp.

      +
      82  {
      +
      83  QString file_name = QFileDialog::getOpenFileName(this, "Open a File", QDir::homePath());
      +
      84  QFile file(file_name);
      +
      85 
      +
      86  if (!file.open(QFile::ReadOnly | QFile::Text)) {
      +
      87  QMessageBox::warning(this, "Error", "File Not Open!");
      +
      88  }
      +
      89  QTextStream in(&file);
      +
      90  QString text = in.readAll();
      +
      91 
      +
      92 
      +
      93  char* cstr;
      +
      94  std::string fname = file_name.toStdString();
      +
      95  cstr = new char[fname.size() + 1];
      +
      96  strcpy(cstr, fname.c_str());
      +
      97 
      +
      98 
      +
      99 
      +
      100  char a = ',';
      + +
      102  mp.Import("models\\2gram.mdl");
      +
      103  mp.Train(cstr, a,10);
      +
      104  mp.Export("models\\finished.mdl");
      +
      105 
      +
      106 
      +
      107 
      +
      108  ui.pushButton->setVisible(true);
      +
      109  ui.lineEdit->setVisible(true);
      +
      110  ui.lineEdit_2->setVisible(true);
      +
      111  ui.lineEdit_3->setVisible(true);
      +
      112  ui.label_3->setVisible(true);
      +
      113  ui.label_4->setVisible(true);
      +
      114  ui.label_5->setVisible(true);
      +
      115 
      +
      116  file.close();
      +
      117 
      +
      118 
      +
      119 }
      +
      +

      References Markov::API::MarkovPasswords::Train(), and ui.

      +
      +Here is the call graph for this function:
      +
      +
      + + + + + + + + + +
      + +
      +
      + +

      ◆ vis

      + +
      +
      + + + + + +
      + + + + + + + +
      void Generate::vis ()
      +
      +slot
      +
      + +

      Definition at line 126 of file Generate.cpp.

      +
      126  {
      + +
      128  w->show();
      +
      129  this->close();
      +
      130 }
      +
      +
      +
      +

      Member Data Documentation

      + +

      ◆ ui

      + +
      +
      + + + + + +
      + + + + +
      Ui::Generate Markov::GUI::Generate::ui
      +
      +private
      +
      + +

      Definition at line 21 of file Generate.h.

      + +

      Referenced by Generate(), generation(), and train().

      + +
      +
      +
      The documentation for this class was generated from the following files: +
      +
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Markov::Model with char represented nodes.
      +
      void Generate(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
      Call Markov::Model::RandomWalk n times, and collect output.
      + +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      +
      QT CLI Class.
      Definition: CLI.h:14
      + +
      Ui::Generate ui
      Definition: Generate.h:21
      + + + + diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate.js b/docs/dark/class_markov_1_1_g_u_i_1_1_generate.js new file mode 100644 index 00000000..6c411661 --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate.js @@ -0,0 +1,9 @@ +var class_markov_1_1_g_u_i_1_1_generate = +[ + [ "Generate", "class_markov_1_1_g_u_i_1_1_generate.html#a104406389ae61bab2e3d87f771a2e353", null ], + [ "generation", "class_markov_1_1_g_u_i_1_1_generate.html#abc3c4aa5bf5afc2d56f0f95a355b1984", null ], + [ "home", "class_markov_1_1_g_u_i_1_1_generate.html#a333b11d559e0ef49ea79626c97fbaeb3", null ], + [ "train", "class_markov_1_1_g_u_i_1_1_generate.html#af5f5d0fcc5530157d882e35e35d1649e", null ], + [ "vis", "class_markov_1_1_g_u_i_1_1_generate.html#afbab410a7d15a59d42be45705f32e0fa", null ], + [ "ui", "class_markov_1_1_g_u_i_1_1_generate.html#a3c360d52d5d94e30bd3cf946d681b1cb", null ] +]; \ No newline at end of file diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.map b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.map new file mode 100644 index 00000000..f3300a6c --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.map @@ -0,0 +1,5 @@ + + + + + diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.md5 b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.md5 new file mode 100644 index 00000000..b6177966 --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.md5 @@ -0,0 +1 @@ +cc6affff82c20f192fa052f8c5967017 \ No newline at end of file diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.png b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.png new file mode 100644 index 00000000..1ca15b36 Binary files /dev/null and b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__coll__graph.png differ diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.map b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.map new file mode 100644 index 00000000..d36aa41b --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.map @@ -0,0 +1,4 @@ + + + + diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.md5 b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.md5 new file mode 100644 index 00000000..3b7c58c0 --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.md5 @@ -0,0 +1 @@ +d53029b92240585fc01e554f34944018 \ No newline at end of file diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.png b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.png new file mode 100644 index 00000000..bdef8644 Binary files /dev/null and b/docs/dark/class_markov_1_1_g_u_i_1_1_generate__inherit__graph.png differ diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.map b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.map new file mode 100644 index 00000000..d90b99ff --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.map @@ -0,0 +1,6 @@ + + + + + + diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.md5 b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.md5 new file mode 100644 index 00000000..1e4d53cf --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.md5 @@ -0,0 +1 @@ +1178034060955ef0ad067213e6771d42 \ No newline at end of file diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.png b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.png new file mode 100644 index 00000000..2b7fee88 Binary files /dev/null and b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_abc3c4aa5bf5afc2d56f0f95a355b1984_cgraph.png differ diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.map b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.map new file mode 100644 index 00000000..e851c427 --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.md5 b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.md5 new file mode 100644 index 00000000..fec1bb23 --- /dev/null +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.md5 @@ -0,0 +1 @@ +3e2176b72522fd1cb89ff135658f7e45 \ No newline at end of file diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.png b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.png new file mode 100644 index 00000000..d39480b3 Binary files /dev/null and b/docs/dark/class_markov_1_1_g_u_i_1_1_generate_af5f5d0fcc5530157d882e35e35d1649e_cgraph.png differ diff --git a/docs/dark/class_markov_1_1_g_u_i_1_1_markov_passwords_g_u_i-members.html b/docs/dark/class_markov_1_1_g_u_i_1_1_markov_passwords_g_u_i-members.html index a127fb37..f0489294 100644 --- a/docs/dark/class_markov_1_1_g_u_i_1_1_markov_passwords_g_u_i-members.html +++ b/docs/dark/class_markov_1_1_g_u_i_1_1_markov_passwords_g_u_i-members.html @@ -90,20 +90,18 @@

      This is the complete list of members for Markov::GUI::MarkovPasswordsGUI, including all inherited members.

      - - - - - - - + + + + +
      MarkovPasswordsGUI ::pass()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI::benchmarkSelected()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI::comparisonSelected()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI::home()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI::model()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI::modelvisSelected()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI::visualDebugSelected()Markov::GUI::MarkovPasswordsGUIslot
      benchmarkSelected()Markov::GUI::MarkovPasswordsGUIslot
      home()Markov::GUI::MarkovPasswordsGUIslot
      MarkovPasswordsGUI(QWidget *parent=Q_NULLPTR)Markov::GUI::MarkovPasswordsGUI
      model()Markov::GUI::MarkovPasswordsGUIslot
      pass()Markov::GUI::MarkovPasswordsGUIslot
      uiMarkov::GUI::MarkovPasswordsGUIprivate

      Member Data Documentation

      @@ -241,7 +264,7 @@

      - +
      Ui::main Markov::GUI::menu::uiUi::main Markov::GUI::menu::ui
      @@ -251,7 +274,9 @@

      -

      Definition at line 15 of file menu.h.

      +

      Definition at line 21 of file menu.h.

      + +

      Referenced by menu().

      @@ -261,13 +286,14 @@

      Ui::main ui
      Definition: menu.h:15
      - +
      Ui::main ui
      Definition: menu.h:21
      + +
      + +

      Sort edges of all nodes in the model ordered by edge weights.

      + +

      Definition at line 265 of file model.h.

      +
      265  {
      +
      266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      +
      267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      +
      268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      +
      269  return lhs->EdgeWeight() > rhs->EdgeWeight();
      +
      270  });
      +
      271  //for(int i=0;i<x.second->edgesV.size();i++)
      +
      272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      +
      273  //std::cout << "\n";
      +
      274  }
      +
      275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      +
      276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      +
      277 }
      +
      +

      Referenced by Markov::API::MarkovPasswords::Buff().

      +
      +Here is the caller graph for this function:
      +
      +
      + + + +
      @@ -656,7 +678,7 @@

      Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from

      This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.

      This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.

      -

      Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

      +

      Example Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia

      Model.import("model.mdl");
      char* res = new char[11];
      Markov::Random::Marsaglia MarsagliaRandomEngine;
      @@ -675,46 +697,47 @@

      Returns
      Null terminated string that was generated.
      -

      Definition at line 293 of file model.h.

      -
      293  {
      - -
      295  int len = 0;
      - -
      297  while (true) {
      -
      298  temp_node = n->RandomNext(randomEngine);
      -
      299  if (len >= maxSetting) {
      -
      300  break;
      -
      301  }
      -
      302  else if ((temp_node == NULL) && (len < minSetting)) {
      -
      303  continue;
      -
      304  }
      -
      305 
      -
      306  else if (temp_node == NULL){
      -
      307  break;
      -
      308  }
      -
      309 
      -
      310  n = temp_node;
      -
      311 
      -
      312  buffer[len++] = n->NodeValue();
      -
      313  }
      -
      314 
      -
      315  //null terminate the string
      -
      316  buffer[len] = 0x00;
      -
      317 
      -
      318  //do something with the generated string
      -
      319  return buffer; //for now
      -
      320 }
      +

      Definition at line 307 of file model.h.

      +
      307  {
      + +
      309  int len = 0;
      + +
      311  while (true) {
      +
      312  temp_node = n->RandomNext(randomEngine);
      +
      313  if (len >= maxSetting) {
      +
      314  break;
      +
      315  }
      +
      316  else if ((temp_node == NULL) && (len < minSetting)) {
      +
      317  continue;
      +
      318  }
      +
      319 
      +
      320  else if (temp_node == NULL){
      +
      321  break;
      +
      322  }
      +
      323 
      +
      324  n = temp_node;
      +
      325 
      +
      326  buffer[len++] = n->NodeValue();
      +
      327  }
      +
      328 
      +
      329  //null terminate the string
      +
      330  buffer[len] = 0x00;
      +
      331 
      +
      332  //do something with the generated string
      +
      333  return buffer; //for now
      +
      334 }
      -

      Referenced by Markov::API::MarkovPasswords::GenerateThread().

      +

      Referenced by Markov::API::MarkovPasswords::GenerateThread().

      Here is the caller graph for this function:
      - - - + + + +
      @@ -748,10 +771,10 @@

      Node.

      Returns
      starter node with 00 NodeValue
      -

      Definition at line 167 of file model.h.

      -
      167 { return starterNode;}
      +

      Definition at line 171 of file model.h.

      +
      171 { return starterNode;}
      -

      Referenced by Markov::API::ModelMatrix::ConstructMatrix().

      +

      Referenced by Markov::API::ModelMatrix::ConstructMatrix().

      Here is the caller graph for this function:
      @@ -762,7 +785,7 @@

      - +

      @@ -793,9 +816,9 @@

      Definition at line 195 of file model.h.

      +

      Definition at line 204 of file model.h.

      -

      Referenced by Markov::Model< char >::Edges().

      +

      Referenced by Markov::Model< char >::Edges().

      @@ -823,9 +846,9 @@

      Definition at line 184 of file model.h.

      +

      Definition at line 193 of file model.h.

      -

      Referenced by Markov::Model< char >::Nodes().

      +

      Referenced by Markov::Model< char >::Nodes().

      @@ -853,9 +876,9 @@

      Node of this model.

      -

      Definition at line 189 of file model.h.

      +

      Definition at line 198 of file model.h.

      -

      Referenced by Markov::Model< char >::StarterNode().

      +

      Referenced by Markov::Model< char >::StarterNode().

      @@ -864,32 +887,33 @@

      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:226
      -
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:158
      -
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:207
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:153
      -
      NodeStorageType * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer)
      Do a random walk on this model.
      Definition: model.h:293
      -
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:274
      +
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:337
      +
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:234
      +
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:165
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      void OptimizeEdgeOrder()
      Sort edges of all nodes in the model ordered by edge weights.
      Definition: model.h:265
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      NodeStorageType * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer)
      Do a random walk on this model.
      Definition: model.h:307
      +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      -
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:130
      -
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:212
      -
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:207
      -
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:201
      -
      std::vector< Edge< NodeStorageType > * > edges
      A list of all edges in this model.
      Definition: model.h:195
      -
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:252
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      +
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:220
      +
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:215
      +
      Model()
      Initialize a model with only start and end nodes.
      Definition: model.h:210
      +
      std::vector< Edge< NodeStorageType > * > edges
      A list of all edges in this model.
      Definition: model.h:204
      +
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:260
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      f
      output file handle
      Definition: model_2gram.py:16
      -
      std::map< NodeStorageType, Node< NodeStorageType > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:184
      -
      Node< NodeStorageType > * starterNode
      Starter Node of this model.
      Definition: model.h:189
      - -
      Edge class used to link nodes in the model together.
      Definition: model.h:26
      +
      std::map< NodeStorageType, Node< NodeStorageType > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:193
      +
      Node< NodeStorageType > * starterNode
      Starter Node of this model.
      Definition: model.h:198
      +
      Edge class used to link nodes in the model together.
      Definition: model.h:30
      -

      Definition at line 244 of file node.h.

      -
      244  {
      -
      245  this->edges.insert({ v->RightNode()->NodeValue(), v });
      -
      246  this->edgesV.push_back(v);
      -
      247  //this->total_edge_weights += v->EdgeWeight();
      -
      248  return v->TraverseNode();
      -
      249 }
      +

      Definition at line 252 of file node.h.

      +
      252  {
      +
      253  this->edges.insert({ v->RightNode()->NodeValue(), v });
      +
      254  this->edgesV.push_back(v);
      +
      255  //this->total_edge_weights += v->EdgeWeight();
      +
      256  return v->TraverseNode();
      +
      257 }
      @@ -666,10 +663,10 @@

      Definition at line 259 of file node.h.

      -
      259  {
      -
      260  this->total_edge_weights += offset;
      -
      261 }
      +

      Definition at line 267 of file node.h.

      +
      267  {
      +
      268  this->total_edge_weights += offset;
      +
      269 }
      @@ -698,9 +695,9 @@

      Definition at line 171 of file node.h.

      +

      Definition at line 179 of file node.h.

      -

      Referenced by Markov::Node< NodeStorageType >::NodeValue().

      +

      Referenced by Markov::Node< NodeStorageType >::NodeValue().

      @@ -728,7 +725,7 @@

      Definition at line 182 of file node.h.

      +

      Definition at line 190 of file node.h.

      @@ -746,7 +743,7 @@

      -

      Definition at line 165 of file node.h.

      +

      Definition at line 173 of file node.h.

      @@ -774,7 +771,7 @@

      Definition at line 176 of file node.h.

      +

      Definition at line 184 of file node.h.

      @@ -784,29 +781,30 @@

      storageType _value
      Character representation of this node. 0 for starter, 0xff for terminator.
      Definition: node.h:171
      -
      void SetLeftEdge(Node< NodeStorageType > *)
      Set LeftNode of this edge.
      Definition: edge.h:143
      -
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:226
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      std::vector< Edge< storageType > * > edgesV
      Definition: node.h:165
      -
      std::map< storageType, Edge< storageType > * > edges
      A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsi...
      Definition: node.h:182
      -
      A node class that for the vertices of model. Connected with eachother using Edge.
      Definition: model.h:23
      +
      storageType _value
      Character representation of this node. 0 for starter, 0xff for terminator.
      Definition: node.h:179
      +
      void SetLeftEdge(Node< NodeStorageType > *)
      Set LeftNode of this edge.
      Definition: edge.h:150
      +
      Node< storageType > * RandomNext(Markov::Random::RandomEngine *randomEngine)
      Chose a random node from the list of edges, with regards to its EdgeWeight, and TraverseNode to that.
      Definition: node.h:234
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      std::vector< Edge< storageType > * > edgesV
      Definition: node.h:173
      +
      std::map< storageType, Edge< storageType > * > edges
      A map of all edges connected to this node, where this node is at the LeftNode. Map is indexed by unsi...
      Definition: node.h:190
      +
      A node class that for the vertices of model. Connected with eachother using Edge.
      Definition: model.h:27
      virtual unsigned long random()=0
      -
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:130
      -
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:212
      -
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:207
      -
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:252
      -
      long int total_edge_weights
      Total weights of the vertices, required by RandomNext.
      Definition: node.h:176
      -
      Node< NodeStorageType > * TraverseNode()
      Traverse this edge to RightNode.
      Definition: edge.h:136
      +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      +
      Edge< storageType > * Link(Node< storageType > *)
      Link this node with another, with this node as its source.
      Definition: node.h:220
      +
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:215
      +
      Edge< storageType > * FindEdge(storageType repr)
      Find an edge with its character representation.
      Definition: node.h:260
      +
      long int total_edge_weights
      Total weights of the vertices, required by RandomNext.
      Definition: node.h:184
      +
      Node< NodeStorageType > * TraverseNode()
      Traverse this edge to RightNode.
      Definition: edge.h:143
      -
      bool UpdateEdges(Edge< storageType > *)
      Insert a new edge to the this.edges.
      Definition: node.h:244
      - -
      Edge class used to link nodes in the model together.
      Definition: model.h:26
      +
      bool UpdateEdges(Edge< storageType > *)
      Insert a new edge to the this.edges.
      Definition: node.h:252
      +
      Node< NodeStorageType > * starterNode
      Starter Node of this model.
      Definition: model.h:198
      +
      Edge class used to link nodes in the model together.
      Definition: model.h:30
      -
      #include "MarkovPasswords/src/modelMatrix.h"
      + +

      CUDA accelerated extension of Markov::API::ModelMatrix. +More...

      +
      Include dependency graph for cudaModelMatrix.h:
      - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + +
      +
      +This graph shows which files directly or indirectly include this file:
      +
      +
      + + + +
      @@ -148,20 +157,28 @@ - + - - - + + +

      Functions

      __global__ void Markov::API::CUDA::FastRandomWalkCUDAKernel (unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
      __global__ void Markov::API::CUDA::FastRandomWalkCUDAKernel (unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
       CUDA kernel for the FastRandomWalk operation. More...
       
      __device__ char * Markov::API::CUDA::strchr (char *p, char c, int s_len)
       srtchr implementation on device space More...
       
      __device__ charMarkov::API::CUDA::strchr (char *p, char c, int s_len)
       srtchr implementation on device space More...
       
      -
      +

      Detailed Description

      +

      CUDA accelerated extension of Markov::API::ModelMatrix.

      +
      Authors
      Ata Hakçıl
      +

      Extension of Markov::API::ModelMatrix which is modified to run on GPU devices. This implementation only supports Nvidia devices.

      +

      Class to flatten and reduce Markov::Model to a Matrix. Matrix level operations can be used for Generation events, with a significant performance optimization at the cost of O(N) memory complexity (O(1) memory space for slow mode)

      +

      To limit the maximum memory usage, each generation operation is partitioned into 50M chunks for allocation. Threads are sychronized and files are flushed every 50M operations.

      + +

      Definition in file cudaModelMatrix.h.

      +
      -Go to the documentation of this file.
      1 #include "MarkovPasswords/src/modelMatrix.h"
      - -
      3 
      -
      4 /** @brief Namespace for objects requiring CUDA libraries.
      -
      5 */
      -
      6 namespace Markov::API::CUDA{
      -
      7  /** @brief Extension of Markov::API::ModelMatrix which is modified to run on GPU devices.
      -
      8  *
      -
      9  * This implementation only supports Nvidia devices.
      -
      10  */
      - -
      12  public:
      -
      13 
      -
      14  /** @brief Migrate the class members to the VRAM
      -
      15  *
      -
      16  * Cannot be used without calling Markov::API::ModelMatrix::ConstructMatrix at least once.
      -
      17  * This function will manage the memory allocation and data transfer from CPU RAM to GPU VRAM.
      -
      18  *
      -
      19  * Newly allocated VRAM pointers are set in the class member variables.
      -
      20  *
      -
      21  */
      -
      22  __host__ void MigrateMatrix();
      -
      23 
      -
      24  /** @brief Flatten migrated matrix from 2d to 1d
      -
      25  *
      +Go to the documentation of this file.
      1 /** @file cudaModelMatrix.h
      +
      2  * @brief CUDA accelerated extension of Markov::API::ModelMatrix
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::API::CUDA::CUDAModelMatrix
      +
      6  */
      +
      7 
      +
      8 #include "MarkovAPI/src/modelMatrix.h"
      + +
      10 
      +
      11 /** @brief Namespace for objects requiring CUDA libraries.
      +
      12 */
      +
      13 namespace Markov::API::CUDA{
      +
      14  /** @brief Extension of Markov::API::ModelMatrix which is modified to run on GPU devices.
      +
      15  *
      +
      16  * This implementation only supports Nvidia devices.
      +
      17  * @copydoc Markov::API::ModelMatrix
      +
      18  */
      + +
      20  public:
      +
      21 
      +
      22  /** @brief Migrate the class members to the VRAM
      +
      23  *
      +
      24  * Cannot be used without calling Markov::API::ModelMatrix::ConstructMatrix at least once.
      +
      25  * This function will manage the memory allocation and data transfer from CPU RAM to GPU VRAM.
      26  *
      -
      27  */
      -
      28  __host__ void FlattenMatrix();
      -
      29 
      -
      30  /** @brief Random walk on the Matrix-reduced Markov::Model
      -
      31  *
      -
      32  * TODO
      -
      33  *
      +
      27  * Newly allocated VRAM pointers are set in the class member variables.
      +
      28  *
      +
      29  */
      +
      30  __host__ void MigrateMatrix();
      +
      31 
      +
      32  /** @brief Flatten migrated matrix from 2d to 1d
      +
      33  *
      34  *
      -
      35  * @param n - Number of passwords to generate.
      -
      36  * @param wordlistFileName - Filename to write to
      -
      37  * @param minLen - Minimum password length to generate
      -
      38  * @param maxLen - Maximum password length to generate
      -
      39  * @param threads - number of OS threads to spawn
      -
      40  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      +
      35  */
      +
      36  __host__ void FlattenMatrix();
      +
      37 
      +
      38  /** @brief Random walk on the Matrix-reduced Markov::Model
      +
      39  *
      +
      40  * TODO
      41  *
      42  *
      -
      43  * @code{.cpp}
      -
      44  * Markov::API::ModelMatrix mp;
      -
      45  * mp.Import("models/finished.mdl");
      -
      46  * mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      -
      47  * @endcode
      -
      48  *
      -
      49  */
      -
      50  __host__ void FastRandomWalk(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen, bool bFileIO);
      -
      51 
      -
      52  protected:
      -
      53 
      -
      54  /** @brief Allocate the output buffer for kernel operation
      -
      55  *
      -
      56  * TODO
      -
      57  *
      -
      58  *
      -
      59  * @param n - Number of passwords to generate.
      -
      60  * @param singleGenMaxLen - maximum string length for a single generation
      -
      61  * @param CUDAKernelGridSize - Total number of grid members in CUDA kernel
      -
      62  * @param sizePerGrid - Size to allocate per grid member
      -
      63  * @return pointer to the allocation on VRAM
      -
      64  *
      +
      43  * @param n - Number of passwords to generate.
      +
      44  * @param wordlistFileName - Filename to write to
      +
      45  * @param minLen - Minimum password length to generate
      +
      46  * @param maxLen - Maximum password length to generate
      +
      47  * @param threads - number of OS threads to spawn
      +
      48  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      +
      49  *
      +
      50  *
      +
      51  * @code{.cpp}
      +
      52  * Markov::API::ModelMatrix mp;
      +
      53  * mp.Import("models/finished.mdl");
      +
      54  * mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      +
      55  * @endcode
      +
      56  *
      +
      57  */
      +
      58  __host__ void FastRandomWalk(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen, bool bFileIO, bool bInfinite);
      +
      59 
      +
      60  protected:
      +
      61 
      +
      62  /** @brief Allocate the output buffer for kernel operation
      +
      63  *
      +
      64  * TODO
      65  *
      -
      66  */
      -
      67  __host__ char* AllocVRAMOutputBuffer(long int n, long int singleGenMaxLen, long int CUDAKernelGridSize,long int sizePerGrid);
      -
      68  private:
      -
      69 
      -
      70  /**
      -
      71  @brief VRAM Address pointer of edge matrix (from modelMatrix.h)
      -
      72  */
      - -
      74 
      -
      75  /**
      -
      76  @brief VRAM Address pointer of value matrix (from modelMatrix.h)
      -
      77  */
      -
      78  long int *device_valueMatrix;
      -
      79 
      -
      80  /**
      -
      81  @brief VRAM Address pointer of matrixIndex (from modelMatrix.h)
      -
      82  */
      - +
      66  *
      +
      67  * @param n - Number of passwords to generate.
      +
      68  * @param singleGenMaxLen - maximum string length for a single generation
      +
      69  * @param CUDAKernelGridSize - Total number of grid members in CUDA kernel
      +
      70  * @param sizePerGrid - Size to allocate per grid member
      +
      71  * @return pointer to the allocation on VRAM
      +
      72  *
      +
      73  *
      +
      74  */
      +
      75  __host__ char* AllocVRAMOutputBuffer(long int n, long int singleGenMaxLen, long int CUDAKernelGridSize,long int sizePerGrid);
      +
      76 
      +
      77  __host__ void LaunchAsyncKernel(int kernelID, int minLen, int maxLen);
      +
      78 
      + +
      80 
      + +
      82 
      +
      83  private:
      84 
      85  /**
      -
      86  @brief VRAM Address pointer of total edge weights (from modelMatrix.h)
      +
      86  @brief VRAM Address pointer of edge matrix (from modelMatrix.h)
      87  */
      - +
      89 
      -
      90 
      -
      91  /**
      -
      92  @brief RandomWalk results in device
      -
      93  */
      - -
      95 
      -
      96  /**
      -
      97  @brief RandomWalk results in host
      -
      98  */
      -
      99  char* outputBuffer;
      -
      100 
      -
      101  /**
      -
      102  @brief Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing
      -
      103  */
      - -
      105 
      -
      106  /**
      -
      107  @brief Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing
      -
      108  */
      -
      109  long int* flatValueMatrix;
      -
      110 
      -
      111  };
      -
      112 
      -
      113  /** @brief CUDA kernel for the FastRandomWalk operation
      -
      114  *
      -
      115  * Will be initiated by CPU and continued by GPU (__global__ tag)
      -
      116  *
      -
      117  *
      -
      118  * @param n - Number of passwords to generate.
      -
      119  * @param minlen - minimum string length for a single generation
      -
      120  * @param maxLen - maximum string length for a single generation
      -
      121  * @param outputBuffer - VRAM ptr to the output buffer
      -
      122  * @param matrixIndex - VRAM ptr to the matrix indices
      -
      123  * @param totalEdgeWeights - VRAM ptr to the totalEdgeWeights array
      -
      124  * @param valueMatrix - VRAM ptr to the edge weights array
      -
      125  * @param edgeMatrix - VRAM ptr to the edge representations array
      -
      126  * @param matrixSize - Size of the matrix dimensions
      -
      127  * @param memoryPerKernelGrid - Maximum memory usage per kernel grid
      -
      128  * @param seed - seed chunk to generate the random from (generated & used by Marsaglia)
      -
      129  *
      -
      130  *
      -
      131  *
      -
      132  */
      -
      133  __global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char* outputBuffer,
      -
      134  char* matrixIndex, long int* totalEdgeWeights, long int* valueMatrix, char *edgeMatrix,
      -
      135  int matrixSize, int memoryPerKernelGrid, unsigned long *seed);//, unsigned long mex, unsigned long mey, unsigned long mez);
      +
      90  /**
      +
      91  @brief VRAM Address pointer of value matrix (from modelMatrix.h)
      +
      92  */
      +
      93  long int *device_valueMatrix;
      +
      94 
      +
      95  /**
      +
      96  @brief VRAM Address pointer of matrixIndex (from modelMatrix.h)
      +
      97  */
      + +
      99 
      +
      100  /**
      +
      101  @brief VRAM Address pointer of total edge weights (from modelMatrix.h)
      +
      102  */
      + +
      104 
      +
      105  /**
      +
      106  @brief RandomWalk results in device
      +
      107  */
      + +
      109 
      +
      110  /**
      +
      111  @brief RandomWalk results in host
      +
      112  */
      +
      113  char** outputBuffer;
      +
      114 
      +
      115  /**
      +
      116  @brief Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing
      +
      117  */
      + +
      119 
      +
      120  /**
      +
      121  @brief Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing
      +
      122  */
      +
      123  long int* flatValueMatrix;
      +
      124 
      + + + + + + + + + +
      134 
      +
      136 
      -
      137 
      -
      138  /** @brief srtchr implementation on __device__ space
      -
      139  *
      -
      140  * Fint the first matching index of a string
      -
      141  *
      -
      142  *
      -
      143  * @param p - string to check
      -
      144  * @param c - character to match
      -
      145  * @param s_len - maximum string length
      -
      146  * @returns pointer to the match
      -
      147  */
      -
      148  __device__ char* strchr(char* p, char c, int s_len);
      -
      149 
      -
      150 };
      +
      137  unsigned long** device_seeds;
      +
      138 
      + +
      140 
      +
      141  };
      +
      142 
      +
      143  /** @brief CUDA kernel for the FastRandomWalk operation
      +
      144  *
      +
      145  * Will be initiated by CPU and continued by GPU (__global__ tag)
      +
      146  *
      +
      147  *
      +
      148  * @param n - Number of passwords to generate.
      +
      149  * @param minlen - minimum string length for a single generation
      +
      150  * @param maxLen - maximum string length for a single generation
      +
      151  * @param outputBuffer - VRAM ptr to the output buffer
      +
      152  * @param matrixIndex - VRAM ptr to the matrix indices
      +
      153  * @param totalEdgeWeights - VRAM ptr to the totalEdgeWeights array
      +
      154  * @param valueMatrix - VRAM ptr to the edge weights array
      +
      155  * @param edgeMatrix - VRAM ptr to the edge representations array
      +
      156  * @param matrixSize - Size of the matrix dimensions
      +
      157  * @param memoryPerKernelGrid - Maximum memory usage per kernel grid
      +
      158  * @param seed - seed chunk to generate the random from (generated & used by Marsaglia)
      +
      159  *
      +
      160  *
      +
      161  *
      +
      162  */
      +
      163  __global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char* outputBuffer,
      +
      164  char* matrixIndex, long int* totalEdgeWeights, long int* valueMatrix, char *edgeMatrix,
      +
      165  int matrixSize, int memoryPerKernelGrid, unsigned long *seed);//, unsigned long mex, unsigned long mey, unsigned long mez);
      +
      166 
      +
      167 
      +
      168  /** @brief srtchr implementation on __device__ space
      +
      169  *
      +
      170  * Fint the first matching index of a string
      +
      171  *
      +
      172  *
      +
      173  * @param p - string to check
      +
      174  * @param c - character to match
      +
      175  * @param s_len - maximum string length
      +
      176  * @returns pointer to the match
      +
      177  */
      +
      178  __device__ char* strchr(char* p, char c, int s_len);
      +
      179 
      +
      180 };
      -
      __host__ void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen, int maxLen, bool bFileIO)
      Random walk on the Matrix-reduced Markov::Model.
      -
      char * device_outputBuffer
      RandomWalk results in device.
      -
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:13
      -
      long int * flatValueMatrix
      Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing.
      -
      __host__ void MigrateMatrix()
      Migrate the class members to the VRAM.
      -
      static __host__ cudaError_t CudaMigrate2DFlat(T **dst, T **src, int row, int col)
      Both malloc and memcpy a 2D array into device VRAM.
      -
      long int * device_valueMatrix
      VRAM Address pointer of value matrix (from modelMatrix.h)
      + + +
      char ** outputBuffer
      RandomWalk results in host.
      + + +
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:23
      + +
      long int * flatValueMatrix
      Adding Value matrix end-to-end and resize to 1-D array for better perfomance on traversing.
      + +
      Namespace for the MarkovPasswords API.
      +
      __device__ char * strchr(char *p, char c, int s_len)
      srtchr implementation on device space
      +
      __host__ void GatherAsyncKernelOutput(int kernelID, bool bFileIO, std::ofstream &wordlist)
      +
      __host__ void MigrateMatrix()
      Migrate the class members to the VRAM.
      + +
      static __host__ cudaError_t CudaMigrate2DFlat(T **dst, T **src, int row, int col)
      Both malloc and memcpy a 2D array into device VRAM.
      +
      long int * device_valueMatrix
      VRAM Address pointer of value matrix (from modelMatrix.h)
      + +
      __host__ char * AllocVRAMOutputBuffer(long int n, long int singleGenMaxLen, long int CUDAKernelGridSize, long int sizePerGrid)
      Allocate the output buffer for kernel operation.
      -
      Extension of Markov::API::ModelMatrix which is modified to run on GPU devices.
      -
      __host__ void FlattenMatrix()
      Flatten migrated matrix from 2d to 1d.
      -
      char * outputBuffer
      RandomWalk results in host.
      -
      char * device_matrixIndex
      VRAM Address pointer of matrixIndex (from modelMatrix.h)
      -
      Namespace for objects requiring CUDA libraries.
      -
      long int * device_totalEdgeWeights
      VRAM Address pointer of total edge weights (from modelMatrix.h)
      -
      char * flatEdgeMatrix
      Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.
      -
      char * device_edgeMatrix
      VRAM Address pointer of edge matrix (from modelMatrix.h)
      -
      __global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
      CUDA kernel for the FastRandomWalk operation.
      -
      __device__ char * strchr(char *p, char c, int s_len)
      srtchr implementation on device space
      +
      Extension of Markov::API::ModelMatrix which is modified to run on GPU devices.
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      __host__ void FlattenMatrix()
      Flatten migrated matrix from 2d to 1d.
      +
      __host__ void LaunchAsyncKernel(int kernelID, int minLen, int maxLen)
      +
      char * device_matrixIndex
      VRAM Address pointer of matrixIndex (from modelMatrix.h)
      +
      Namespace for objects requiring CUDA libraries.
      +
      long int * device_totalEdgeWeights
      VRAM Address pointer of total edge weights (from modelMatrix.h)
      +
      char * flatEdgeMatrix
      Adding Edge matrix end-to-end and resize to 1-D array for better perfomance on traversing.
      +
      char * device_edgeMatrix
      VRAM Address pointer of edge matrix (from modelMatrix.h)
      +
      __global__ void FastRandomWalkCUDAKernel(unsigned long int n, int minLen, int maxLen, char *outputBuffer, char *matrixIndex, long int *totalEdgeWeights, long int *valueMatrix, char *edgeMatrix, int matrixSize, int memoryPerKernelGrid, unsigned long *seed)
      CUDA kernel for the FastRandomWalk operation.
      +
      char ** device_outputBuffer
      RandomWalk results in device.
      + +
      __host__ void prepKernelMemoryChannel(int numberOfStreams)
      + + +
      __host__ void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen, int maxLen, bool bFileIO, bool bInfinite)
      Random walk on the Matrix-reduced Markov::Model.
      + +

      Extension of Markov::Random::Marsaglia for CUDA. +More...

      Include dependency graph for cudarandom.h:
      - - - - - - - - - + + + + + + +
      +
      +This graph shows which files directly or indirectly include this file:
      +
      +
      + + +
      @@ -139,13 +147,33 @@  Marsaglia Random Generation function operable in device space. More...
        -
      +

      Detailed Description

      +

      Extension of Markov::Random::Marsaglia for CUDA.

      +
      Authors
      Ata Hakçıl
      +

      Implementation of Marsaglia Random Engine. This is an implementation of Marsaglia Random engine, which for most use cases is a better fit than other solutions. Very simple mathematical formula to generate pseudorandom integer, so its crazy fast.

      +

      This implementation of the Marsaglia Engine is seeded by random.h default random engine. RandomEngine is only seeded once so its not a performance issue.

      +

      Example Use: Using Marsaglia Engine with RandomWalk

      +
      Model.import("model.mdl");
      +
      char* res = new char[11];
      +
      Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      for (int i = 0; i < 10; i++) {
      +
      this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
      +
      std::cout << res << "\n";
      +
      }
      +

      Example Use: Generating a random number with Marsaglia Engine

      +
      std::cout << me.random();
      +
      +

      Definition in file cudarandom.h.

      +
      +
      unsigned long random()
      Generate Random Number.
      Definition: random.h:140
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      -Go to the documentation of this file.
      1 #pragma once
      -
      2 #include "MarkovModel/src/random.h"
      -
      3 #include "CudaMarkovPasswords/src/cudaDeviceController.h"
      -
      4 
      -
      5 /** @brief Namespace for Random engines operable under __device__ space.
      -
      6 */
      -
      7 namespace Markov::API::CUDA::Random{
      -
      8 
      -
      9  /** @brief Extension of Markov::Random::Marsaglia which is capable o working on __device__ space.
      -
      10  */
      -
      11  class Marsaglia : public Markov::Random::Marsaglia, public CUDADeviceController{
      -
      12  public:
      -
      13 
      -
      14  /** @brief Migrate a Marsaglia[] to VRAM as seedChunk
      -
      15  * @param MEarr Array of Marsaglia Engines
      -
      16  * @param gridSize GridSize of the CUDA Kernel, aka size of array
      -
      17  * @returns pointer to the resulting seed chunk in device VRAM.
      -
      18  */
      -
      19  static unsigned long* MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize){
      -
      20  cudaError_t cudastatus;
      -
      21  unsigned long* seedChunk;
      -
      22  cudastatus = cudaMalloc((unsigned long**)&seedChunk, gridSize*3*sizeof(unsigned long));
      -
      23  CudaCheckNotifyErr(cudastatus, "Failed to allocate seed buffer");
      -
      24  unsigned long *temp = new unsigned long[gridSize*3];
      -
      25  for(int i=0;i<gridSize;i++){
      -
      26  temp[i*3] = MEarr[i].x;
      -
      27  temp[i*3+1] = MEarr[i].y;
      -
      28  temp[i*3+2] = MEarr[i].z;
      -
      29  }
      -
      30  //for(int i=0;i<gridSize*3;i++) std::cout << temp[i] << "\n";
      -
      31  cudaMemcpy(seedChunk, temp, gridSize*3*sizeof(unsigned long), cudaMemcpyHostToDevice);
      -
      32  CudaCheckNotifyErr(cudastatus, "Failed to memcpy seed buffer.");
      -
      33  return seedChunk;
      -
      34  }
      -
      35  };
      -
      36 
      -
      37  /** @brief Marsaglia Random Generation function operable in __device__ space
      -
      38  * @param x marsaglia internal x. Not constant, (ref)
      -
      39  * @param y marsaglia internal y. Not constant, (ref)
      -
      40  * @param z marsaglia internal z. Not constant, (ref)
      -
      41  * @returns returns z
      -
      42  */
      -
      43  __device__ unsigned long devrandom(unsigned long &x, unsigned long &y, unsigned long &z){
      -
      44  unsigned long t;
      -
      45  x ^= x << 16;
      -
      46  x ^= x >> 5;
      -
      47  x ^= x << 1;
      -
      48 
      -
      49  t = x;
      -
      50  x = y;
      -
      51  y = z;
      -
      52  z = t ^ x ^ y;
      -
      53 
      -
      54  return z;
      -
      55  }
      -
      56 };
      +Go to the documentation of this file.
      1 /** @file cudarandom.h
      +
      2  * @brief Extension of Markov::Random::Marsaglia for CUDA
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::Random::Marsaglia
      +
      6  */
      +
      7 
      +
      8 #pragma once
      +
      9 #include "MarkovModel/src/random.h"
      + +
      11 
      +
      12 /** @brief Namespace for Random engines operable under __device__ space.
      +
      13 */
      +
      14 namespace Markov::API::CUDA::Random{
      +
      15 
      +
      16  /** @brief Extension of Markov::Random::Marsaglia which is capable o working on __device__ space.
      +
      17  *
      +
      18  * @copydoc Markov::Random::Marsaglia
      +
      19  */
      + +
      21  public:
      +
      22 
      +
      23  /** @brief Migrate a Marsaglia[] to VRAM as seedChunk
      +
      24  * @param MEarr Array of Marsaglia Engines
      +
      25  * @param gridSize GridSize of the CUDA Kernel, aka size of array
      +
      26  * @returns pointer to the resulting seed chunk in device VRAM.
      +
      27  */
      +
      28  static unsigned long* MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize){
      +
      29  cudaError_t cudastatus;
      +
      30  unsigned long* seedChunk;
      +
      31  cudastatus = cudaMalloc((unsigned long**)&seedChunk, gridSize*3*sizeof(unsigned long));
      +
      32  CudaCheckNotifyErr(cudastatus, "Failed to allocate seed buffer");
      +
      33  unsigned long *temp = new unsigned long[gridSize*3];
      +
      34  for(int i=0;i<gridSize;i++){
      +
      35  temp[i*3] = MEarr[i].x;
      +
      36  temp[i*3+1] = MEarr[i].y;
      +
      37  temp[i*3+2] = MEarr[i].z;
      +
      38  }
      +
      39  //for(int i=0;i<gridSize*3;i++) std::cout << temp[i] << "\n";
      +
      40  cudaMemcpy(seedChunk, temp, gridSize*3*sizeof(unsigned long), cudaMemcpyHostToDevice);
      +
      41  CudaCheckNotifyErr(cudastatus, "Failed to memcpy seed buffer.");
      +
      42 
      +
      43  delete[] temp;
      +
      44  return seedChunk;
      +
      45  }
      +
      46  };
      +
      47 
      +
      48  /** @brief Marsaglia Random Generation function operable in __device__ space
      +
      49  * @param x marsaglia internal x. Not constant, (ref)
      +
      50  * @param y marsaglia internal y. Not constant, (ref)
      +
      51  * @param z marsaglia internal z. Not constant, (ref)
      +
      52  * @returns returns z
      +
      53  */
      +
      54  __device__ unsigned long devrandom(unsigned long &x, unsigned long &y, unsigned long &z){
      +
      55  unsigned long t;
      +
      56  x ^= x << 16;
      +
      57  x ^= x >> 5;
      +
      58  x ^= x << 1;
      +
      59 
      +
      60  t = x;
      +
      61  x = y;
      +
      62  y = z;
      +
      63  z = t ^ x ^ y;
      +
      64 
      +
      65  return z;
      +
      66  }
      +
      67 };
      -
      Objects related to RNG.
      Definition: random.h:9
      -
      unsigned long x
      Definition: random.h:146
      -
      Extension of Markov::Random::Marsaglia which is capable o working on device space.
      Definition: cudarandom.h:11
      -
      static __host__ cudaError_t CudaMigrate2DFlat(T **dst, T **src, int row, int col)
      Both malloc and memcpy a 2D array into device VRAM.
      -
      static unsigned long * MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize)
      Migrate a Marsaglia[] to VRAM as seedChunk.
      Definition: cudarandom.h:19
      -
      Namespace for objects requiring CUDA libraries.
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      -
      __device__ unsigned long devrandom(unsigned long &x, unsigned long &y, unsigned long &z)
      Marsaglia Random Generation function operable in device space.
      Definition: cudarandom.h:43
      -
      unsigned long y
      Definition: random.h:147
      -
      unsigned long z
      Definition: random.h:148
      -
      Namespace for Random engines operable under device space.
      Definition: cudarandom.h:7
      +
      Objects related to RNG.
      Definition: random.h:18
      +
      unsigned long x
      Definition: random.h:155
      +
      Namespace for the MarkovPasswords API.
      +
      Extension of Markov::Random::Marsaglia which is capable o working on device space.
      Definition: cudarandom.h:20
      +
      static __host__ cudaError_t CudaMigrate2DFlat(T **dst, T **src, int row, int col)
      Both malloc and memcpy a 2D array into device VRAM.
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      static unsigned long * MigrateToVRAM(Markov::API::CUDA::Random::Marsaglia *MEarr, long int gridSize)
      Migrate a Marsaglia[] to VRAM as seedChunk.
      Definition: cudarandom.h:28
      +
      Namespace for objects requiring CUDA libraries.
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      __device__ unsigned long devrandom(unsigned long &x, unsigned long &y, unsigned long &z)
      Marsaglia Random Generation function operable in device space.
      Definition: cudarandom.h:54
      +
      unsigned long y
      Definition: random.h:156
      +
      unsigned long z
      Definition: random.h:157
      +
      Namespace for Random engines operable under device space.
      Definition: cudarandom.h:14
      @@ -83,13 +83,13 @@
      -

      src → MarkovModel Relation

      File in CudaMarkovPasswords/srcIncludes file in MarkovModel
      cudarandom.hsrc / random.h
      +

      src → MarkovModel Relation

      File in CudaMarkovAPI/srcIncludes file in MarkovModel
      cudarandom.hsrc / random.h
      -

      src → MarkovPasswords Relation

      File in Markopy/srcIncludes file in MarkovPasswords
      Module / markopy.cppsrc / markovPasswords.h
      Module / markopy.cppsrc / modelMatrix.h
      +

      src → MarkovAPI Relation

      File in Markopy/srcIncludes file in MarkovAPI
      Module / markopy.cppsrc / modelMatrix.h
      -

      Module → MarkovPasswords Relation

      File in Markopy/src/ModuleIncludes file in MarkovPasswords
      markopy.cppsrc / markovPasswords.h
      markopy.cppsrc / modelMatrix.h
      +

      Module → MarkovAPI Relation

      File in Markopy/src/ModuleIncludes file in MarkovAPI
      markopy.cppsrc / modelMatrix.h
      @@ -83,13 +83,13 @@
      -

      src → MarkovPasswords Relation

      File in CudaMarkovPasswords/srcIncludes file in MarkovPasswords
      cudaModelMatrix.hsrc / modelMatrix.h
      +

      MarkovAPI → MarkovModel Relation

      File in MarkovAPIIncludes file in MarkovModel
      src / markovPasswords.hsrc / model.h
      @@ -83,13 +83,13 @@
      -

      UnitTests → MarkovModel Relation

      File in UnitTestsIncludes file in MarkovModel
      UnitTests.cppsrc / model.h
      +

      src → MarkovModel Relation

      File in MarkovAPI/srcIncludes file in MarkovModel
      markovPasswords.hsrc / model.h
      @@ -100,8 +100,8 @@
      @@ -84,27 +84,27 @@
      -
      CudaMarkovPasswords Directory Reference
      +
      CudaMarkovAPI Directory Reference
      -Directory dependency graph for CudaMarkovPasswords:
      +Directory dependency graph for CudaMarkovAPI:
      -
      CudaMarkovPasswords
      - - - - - - - - +
      CudaMarkovAPI
      + + + + + + + +
      - +

      Directories

      directory  src
      directory  src
       
      @@ -112,8 +112,8 @@ @@ -109,8 +109,8 @@ @@ -113,7 +121,7 @@
      +
      +Directory dependency graph for src:
      +
      +
      src
      + + + + + + +
      + + + + + + + + - + + + + + + + + + + + + + + + +

      Files

      file  about.cpp [code]
       About page.
       
      file  about.h [code]
       About page.
       
      file  CLI.cpp [code]
       CLI page.
       
      file  CLI.h [code]
       CLI page.
       
      file  UI/src/main.cpp [code]
      file  Generate.cpp [code]
       Generation Page.
       
      file  Generate.h [code]
       Generation Page.
       
      file  MarkovPasswordsGUI/src/main.cpp [code]
       Entry point for GUI.
       
      file  MarkovPasswordsGUI.cpp [code]
       Main activity page for GUI.
       
      file  MarkovPasswordsGUI.h [code]
       Main activity page for GUI.
       
      file  menu.cpp [code]
       menu page
       
      file  menu.h [code]
       menu page
       
      file  Train.cpp [code]
       training page for GUI
       
      file  Train.h [code]
       training page for GUI
       
      @@ -113,7 +147,7 @@
      @@ -91,8 +91,10 @@

      Files

      file  term.cpp [code] + Terminal handler for pretty stuff like colors.
        file  term.h [code] + Terminal handler for pretty stuff like colors.
       
      @@ -100,8 +102,8 @@
      + +

      DLLMain for dynamic windows library. +More...

      #include "pch.h"
      #include "model.h"
      #include <iostream>
      @@ -95,21 +98,21 @@
      - - - + + + - + - - + + - + @@ -117,13 +120,20 @@

      Go to the source code of this file.

      -
      +

      Detailed Description

      +

      DLLMain for dynamic windows library.

      +
      Authors
      Ata Hakçıl
      +

      class for the final Markov Model, constructed from nodes and edges. Each atomic piece of the generation result is stored in a node, while edges contain the relation weights. Extending: To extend the class, implement the template and inherit from it, as "class MyModel : public Markov::Model<char>". For a complete demonstration of how to extend the class, see MarkovPasswords.

      +

      Whole model can be defined as a list of the edges, as dangling nodes are pointless. This approach is used for the import/export operations. For more information on importing/exporting model, check out the github readme and wiki page.

      + +

      Definition in file dllmain.cpp.

      +
      -Go to the documentation of this file.
      1 #include "pch.h"
      -
      2 #include "model.h"
      -
      3 #include <iostream>
      -
      4 
      -
      5 
      -
      6 #ifdef _WIN32
      -
      7 __declspec(dllexport) void dll_loadtest() {
      -
      8  std::cout << "External function called.\n";
      -
      9  //cudaTestEntry();
      -
      10 }
      +Go to the documentation of this file.
      1 /** @file dllmain.cpp
      +
      2  * @brief DLLMain for dynamic windows library
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::Model
      +
      6  */
      +
      7 
      +
      8 #include "pch.h"
      +
      9 #include "model.h"
      +
      10 #include <iostream>
      11 
      -
      12 BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
      -
      13 {
      -
      14  switch (ul_reason_for_call)
      -
      15  {
      -
      16  case DLL_PROCESS_ATTACH:
      -
      17  case DLL_THREAD_ATTACH:
      -
      18  case DLL_THREAD_DETACH:
      -
      19  case DLL_PROCESS_DETACH:
      -
      20  break;
      -
      21  }
      -
      22  return TRUE;
      -
      23 }
      -
      24 
      -
      25 #endif
      +
      12 
      +
      13 #ifdef _WIN32
      +
      14 __declspec(dllexport) void dll_loadtest() {
      +
      15  std::cout << "External function called.\n";
      +
      16  //cudaTestEntry();
      +
      17 }
      +
      18 
      +
      19 BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
      +
      20 {
      +
      21  switch (ul_reason_for_call)
      +
      22  {
      +
      23  case DLL_PROCESS_ATTACH:
      +
      24  case DLL_THREAD_ATTACH:
      +
      25  case DLL_THREAD_DETACH:
      +
      26  case DLL_PROCESS_DETACH:
      +
      27  break;
      +
      28  }
      +
      29  return TRUE;
      +
      30 }
      +
      31 
      +
      32 #endif
      + +

      Edge class template. +More...

      #include <cstdint>
      #include <cstddef>
      @@ -97,7 +100,7 @@
      - + @@ -107,18 +110,22 @@
      - - - - - - - - - - - - + + + + + + + + + + + + + + + +
      @@ -139,13 +146,19 @@  Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
        -
      +

      Detailed Description

      +

      Edge class template.

      +
      Authors
      Ata Hakçıl, Osman Ömer Yıldıztugay
      +

      Edge class used to link nodes in the model together. Has LeftNode, RightNode, and EdgeWeight of the edge. Edges are UNIDIRECTIONAL in this model. They can only be traversed LeftNode to RightNode.

      + +

      Definition in file edge.h.

      +
      -Go to the documentation of this file.
      1 #pragma once
      -
      2 #include <cstdint>
      -
      3 #include <cstddef>
      -
      4 
      -
      5 namespace Markov {
      -
      6 
      -
      7  template <typename NodeStorageType>
      -
      8  class Node;
      -
      9 
      -
      10  /** @brief Edge class used to link nodes in the model together.
      -
      11  *
      -
      12  Has LeftNode, RightNode, and EdgeWeight of the edge.
      -
      13  Edges are *UNIDIRECTIONAL* in this model. They can only be traversed LeftNode to RightNode.
      -
      14  */
      -
      15  template <typename NodeStorageType>
      -
      16  class Edge {
      -
      17  public:
      -
      18 
      -
      19  /** @brief Default constructor.
      -
      20  */
      -
      21  Edge<NodeStorageType>();
      -
      22 
      -
      23  /** @brief Constructor. Initialize edge with given RightNode and LeftNode
      -
      24  * @param _left - Left node of this edge.
      -
      25  * @param _right - Right node of this edge.
      -
      26  *
      -
      27  * @b Example @b Use: Construct edge
      -
      28  * @code{.cpp}
      -
      29  * Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
      -
      30  * Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
      -
      31  * Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
      -
      32  * @endcode
      -
      33  *
      -
      34  */
      -
      35  Edge<NodeStorageType>(Node<NodeStorageType>* _left, Node<NodeStorageType>* _right);
      -
      36 
      -
      37  /** @brief Adjust the edge EdgeWeight with offset.
      -
      38  * Adds the offset parameter to the edge EdgeWeight.
      -
      39  * @param offset - NodeValue to be added to the EdgeWeight
      -
      40  *
      -
      41  * @b Example @b Use: Construct edge
      -
      42  * @code{.cpp}
      -
      43  * Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
      -
      44  * Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
      -
      45  * Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
      -
      46  *
      -
      47  * e1->AdjustEdge(25);
      -
      48  *
      -
      49  * @endcode
      -
      50  */
      -
      51  void AdjustEdge(long int offset);
      -
      52 
      -
      53  /** @brief Traverse this edge to RightNode.
      -
      54  * @return Right node. If this is a terminator node, return NULL
      +Go to the documentation of this file.
      1 /** @file edge.h
      +
      2  * @brief Edge class template
      +
      3  * @authors Ata Hakçıl, Osman Ömer Yıldıztugay
      +
      4  *
      +
      5  * @copydoc Markov::Edge
      +
      6  */
      +
      7 
      +
      8 #pragma once
      +
      9 #include <cstdint>
      +
      10 #include <cstddef>
      +
      11 
      +
      12 namespace Markov {
      +
      13 
      +
      14  template <typename NodeStorageType>
      +
      15  class Node;
      +
      16 
      +
      17  /** @brief Edge class used to link nodes in the model together.
      +
      18  *
      +
      19  Has LeftNode, RightNode, and EdgeWeight of the edge.
      +
      20  Edges are *UNIDIRECTIONAL* in this model. They can only be traversed LeftNode to RightNode.
      +
      21  */
      +
      22  template <typename NodeStorageType>
      +
      23  class Edge {
      +
      24  public:
      +
      25 
      +
      26  /** @brief Default constructor.
      +
      27  */
      +
      28  Edge<NodeStorageType>();
      +
      29 
      +
      30  /** @brief Constructor. Initialize edge with given RightNode and LeftNode
      +
      31  * @param _left - Left node of this edge.
      +
      32  * @param _right - Right node of this edge.
      +
      33  *
      +
      34  * @b Example @b Use: Construct edge
      +
      35  * @code{.cpp}
      +
      36  * Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
      +
      37  * Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
      +
      38  * Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
      +
      39  * @endcode
      +
      40  *
      +
      41  */
      +
      42  Edge<NodeStorageType>(Node<NodeStorageType>* _left, Node<NodeStorageType>* _right);
      +
      43 
      +
      44  /** @brief Adjust the edge EdgeWeight with offset.
      +
      45  * Adds the offset parameter to the edge EdgeWeight.
      +
      46  * @param offset - NodeValue to be added to the EdgeWeight
      +
      47  *
      +
      48  * @b Example @b Use: Construct edge
      +
      49  * @code{.cpp}
      +
      50  * Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
      +
      51  * Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
      +
      52  * Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
      +
      53  *
      +
      54  * e1->AdjustEdge(25);
      55  *
      -
      56  *
      -
      57  * @b Example @b Use: Traverse a node
      -
      58  * @code{.cpp}
      -
      59  * Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
      -
      60  * Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
      -
      61  * Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
      +
      56  * @endcode
      +
      57  */
      +
      58  void AdjustEdge(long int offset);
      +
      59 
      +
      60  /** @brief Traverse this edge to RightNode.
      +
      61  * @return Right node. If this is a terminator node, return NULL
      62  *
      -
      63  * e1->AdjustEdge(25);
      -
      64  * Markov::Edge<unsigned char>* e2 = e1->traverseNode();
      -
      65  * @endcode
      -
      66  *
      -
      67  */
      -
      68  inline Node<NodeStorageType>* TraverseNode();
      -
      69 
      -
      70  /** @brief Set LeftNode of this edge.
      -
      71  * @param node - Node to be linked with.
      -
      72  */
      -
      73  void SetLeftEdge (Node<NodeStorageType>*);
      -
      74  /** @brief Set RightNode of this edge.
      -
      75  * @param node - Node to be linked with.
      -
      76  */
      -
      77  void SetRightEdge(Node<NodeStorageType>*);
      -
      78 
      -
      79  /** @brief return edge's EdgeWeight.
      -
      80  * @return edge's EdgeWeight.
      -
      81  */
      -
      82  inline uint64_t EdgeWeight();
      -
      83 
      -
      84  /** @brief return edge's LeftNode
      -
      85  * @return edge's LeftNode.
      -
      86  */
      -
      87  Node<NodeStorageType>* LeftNode();
      -
      88 
      -
      89  /** @brief return edge's RightNode
      -
      90  * @return edge's RightNode.
      -
      91  */
      -
      92  inline Node<NodeStorageType>* RightNode();
      -
      93 
      -
      94  private:
      -
      95  /**
      -
      96  @brief source node
      -
      97  */
      -
      98  Node<NodeStorageType>* _left;
      -
      99 
      -
      100  /**
      -
      101  @brief target node
      -
      102  */
      -
      103  Node<NodeStorageType>* _right;
      -
      104 
      -
      105  /** @brief
      -
      106  Edge Edge Weight
      -
      107  */
      -
      108  long int _weight;
      -
      109  };
      -
      110 
      +
      63  *
      +
      64  * @b Example @b Use: Traverse a node
      +
      65  * @code{.cpp}
      +
      66  * Markov::Node<unsigned char>* src = new Markov::Node<unsigned char>('a');
      +
      67  * Markov::Node<unsigned char>* target1 = new Markov::Node<unsigned char>('b');
      +
      68  * Markov::Edge<unsigned char>* e1 = new Markov::Edge<unsigned char>(src, target1);
      +
      69  *
      +
      70  * e1->AdjustEdge(25);
      +
      71  * Markov::Edge<unsigned char>* e2 = e1->traverseNode();
      +
      72  * @endcode
      +
      73  *
      +
      74  */
      +
      75  inline Node<NodeStorageType>* TraverseNode();
      +
      76 
      +
      77  /** @brief Set LeftNode of this edge.
      +
      78  * @param node - Node to be linked with.
      +
      79  */
      +
      80  void SetLeftEdge (Node<NodeStorageType>*);
      +
      81  /** @brief Set RightNode of this edge.
      +
      82  * @param node - Node to be linked with.
      +
      83  */
      +
      84  void SetRightEdge(Node<NodeStorageType>*);
      +
      85 
      +
      86  /** @brief return edge's EdgeWeight.
      +
      87  * @return edge's EdgeWeight.
      +
      88  */
      +
      89  inline uint64_t EdgeWeight();
      +
      90 
      +
      91  /** @brief return edge's LeftNode
      +
      92  * @return edge's LeftNode.
      +
      93  */
      +
      94  Node<NodeStorageType>* LeftNode();
      +
      95 
      +
      96  /** @brief return edge's RightNode
      +
      97  * @return edge's RightNode.
      +
      98  */
      +
      99  inline Node<NodeStorageType>* RightNode();
      +
      100 
      +
      101  private:
      +
      102  /**
      +
      103  @brief source node
      +
      104  */
      +
      105  Node<NodeStorageType>* _left;
      +
      106 
      +
      107  /**
      +
      108  @brief target node
      +
      109  */
      +
      110  Node<NodeStorageType>* _right;
      111 
      -
      112 };
      -
      113 
      -
      114 //default constructor of edge
      -
      115 template <typename NodeStorageType>
      -
      116 Markov::Edge<NodeStorageType>::Edge() {
      -
      117  this->_left = NULL;
      -
      118  this->_right = NULL;
      -
      119  this->_weight = 0;
      -
      120 }
      -
      121 //constructor of edge
      +
      112  /** @brief
      +
      113  Edge Edge Weight
      +
      114  */
      +
      115  long int _weight;
      +
      116  };
      +
      117 
      +
      118 
      +
      119 };
      +
      120 
      +
      121 //default constructor of edge
      122 template <typename NodeStorageType>
      -
      123 Markov::Edge<NodeStorageType>::Edge(Markov::Node<NodeStorageType>* _left, Markov::Node<NodeStorageType>* _right) {
      -
      124  this->_left = _left;
      -
      125  this->_right = _right;
      +
      123 Markov::Edge<NodeStorageType>::Edge() {
      +
      124  this->_left = NULL;
      +
      125  this->_right = NULL;
      126  this->_weight = 0;
      127 }
      -
      128 //to AdjustEdge the edges by the edge with its offset
      +
      128 //constructor of edge
      129 template <typename NodeStorageType>
      -
      130 void Markov::Edge<NodeStorageType>::AdjustEdge(long int offset) {
      -
      131  this->_weight += offset;
      -
      132  this->LeftNode()->UpdateTotalVerticeWeight(offset);
      -
      133 }
      -
      134 //to TraverseNode the node
      -
      135 template <typename NodeStorageType>
      -
      136 inline Markov::Node<NodeStorageType>* Markov::Edge<NodeStorageType>::TraverseNode() {
      -
      137  if (this->RightNode()->NodeValue() == 0xff) //terminator node
      -
      138  return NULL;
      -
      139  return _right;
      +
      130 Markov::Edge<NodeStorageType>::Edge(Markov::Node<NodeStorageType>* _left, Markov::Node<NodeStorageType>* _right) {
      +
      131  this->_left = _left;
      +
      132  this->_right = _right;
      +
      133  this->_weight = 0;
      +
      134 }
      +
      135 //to AdjustEdge the edges by the edge with its offset
      +
      136 template <typename NodeStorageType>
      +
      137 void Markov::Edge<NodeStorageType>::AdjustEdge(long int offset) {
      +
      138  this->_weight += offset;
      +
      139  this->LeftNode()->UpdateTotalVerticeWeight(offset);
      140 }
      -
      141 //to set the LeftNode of the node
      +
      141 //to TraverseNode the node
      142 template <typename NodeStorageType>
      -
      143 void Markov::Edge<NodeStorageType>::SetLeftEdge(Markov::Node<NodeStorageType>* n) {
      -
      144  this->_left = n;
      -
      145 }
      -
      146 //to set the RightNode of the node
      -
      147 template <typename NodeStorageType>
      -
      148 void Markov::Edge<NodeStorageType>::SetRightEdge(Markov::Node<NodeStorageType>* n) {
      -
      149  this->_right = n;
      -
      150 }
      -
      151 //to get the EdgeWeight of the node
      -
      152 template <typename NodeStorageType>
      -
      153 inline uint64_t Markov::Edge<NodeStorageType>::EdgeWeight() {
      -
      154  return this->_weight;
      -
      155 }
      -
      156 //to get the LeftNode of the node
      -
      157 template <typename NodeStorageType>
      -
      158 Markov::Node<NodeStorageType>* Markov::Edge<NodeStorageType>::LeftNode() {
      -
      159  return this->_left;
      -
      160 }
      -
      161 //to get the RightNode of the node
      -
      162 template <typename NodeStorageType>
      -
      163 inline Markov::Node<NodeStorageType>* Markov::Edge<NodeStorageType>::RightNode() {
      -
      164  return this->_right;
      -
      165 }
      +
      143 inline Markov::Node<NodeStorageType>* Markov::Edge<NodeStorageType>::TraverseNode() {
      +
      144  if (this->RightNode()->NodeValue() == 0xff) //terminator node
      +
      145  return NULL;
      +
      146  return _right;
      +
      147 }
      +
      148 //to set the LeftNode of the node
      +
      149 template <typename NodeStorageType>
      +
      150 void Markov::Edge<NodeStorageType>::SetLeftEdge(Markov::Node<NodeStorageType>* n) {
      +
      151  this->_left = n;
      +
      152 }
      +
      153 //to set the RightNode of the node
      +
      154 template <typename NodeStorageType>
      +
      155 void Markov::Edge<NodeStorageType>::SetRightEdge(Markov::Node<NodeStorageType>* n) {
      +
      156  this->_right = n;
      +
      157 }
      +
      158 //to get the EdgeWeight of the node
      +
      159 template <typename NodeStorageType>
      +
      160 inline uint64_t Markov::Edge<NodeStorageType>::EdgeWeight() {
      +
      161  return this->_weight;
      +
      162 }
      +
      163 //to get the LeftNode of the node
      +
      164 template <typename NodeStorageType>
      +
      165 Markov::Node<NodeStorageType>* Markov::Edge<NodeStorageType>::LeftNode() {
      +
      166  return this->_left;
      +
      167 }
      +
      168 //to get the RightNode of the node
      +
      169 template <typename NodeStorageType>
      +
      170 inline Markov::Node<NodeStorageType>* Markov::Edge<NodeStorageType>::RightNode() {
      +
      171  return this->_right;
      +
      172 }
      -
      void SetLeftEdge(Node< NodeStorageType > *)
      Set LeftNode of this edge.
      Definition: edge.h:143
      -
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:158
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:153
      -
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:130
      -
      long int _weight
      Edge Edge Weight.
      Definition: edge.h:108
      -
      Node< NodeStorageType > * TraverseNode()
      Traverse this edge to RightNode.
      Definition: edge.h:136
      -
      Node< NodeStorageType > * _left
      source node
      Definition: edge.h:98
      -
      Node< NodeStorageType > * _right
      target node
      Definition: edge.h:103
      -
      void SetRightEdge(Node< NodeStorageType > *)
      Set RightNode of this edge.
      Definition: edge.h:148
      +
      void SetLeftEdge(Node< NodeStorageType > *)
      Set LeftNode of this edge.
      Definition: edge.h:150
      +
      Node< NodeStorageType > * LeftNode()
      return edge's LeftNode
      Definition: edge.h:165
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      long int _weight
      Edge Edge Weight.
      Definition: edge.h:115
      +
      Node< NodeStorageType > * TraverseNode()
      Traverse this edge to RightNode.
      Definition: edge.h:143
      +
      Node< NodeStorageType > * _left
      source node
      Definition: edge.h:105
      +
      Node< NodeStorageType > * _right
      target node
      Definition: edge.h:110
      +
      void SetRightEdge(Node< NodeStorageType > *)
      Set RightNode of this edge.
      Definition: edge.h:155
      + +

      for windows dynamic library +More...

      This graph shows which files directly or indirectly include this file:
      - - - - + + + +
      @@ -108,7 +111,12 @@ #define WIN32_LEAN_AND_MEAN   -

      Macro Definition Documentation

      +

      Detailed Description

      +

      for windows dynamic library

      +
      Authors
      Ata Hakçıl
      + +

      Definition in file framework.h.

      +

      Macro Definition Documentation

      ◆ WIN32_LEAN_AND_MEAN

      @@ -121,7 +129,7 @@

      -

      Definition at line 3 of file framework.h.

      +

      Definition at line 9 of file framework.h.

      @@ -131,7 +139,7 @@

      diff --git a/docs/dark/framework_8h__dep__incl.map b/docs/dark/framework_8h__dep__incl.map index 193c61a5..8d52c507 100644 --- a/docs/dark/framework_8h__dep__incl.map +++ b/docs/dark/framework_8h__dep__incl.map @@ -1,6 +1,6 @@ - - - - + + + + diff --git a/docs/dark/framework_8h__dep__incl.md5 b/docs/dark/framework_8h__dep__incl.md5 index 0c7cfbb5..6f827bd6 100644 --- a/docs/dark/framework_8h__dep__incl.md5 +++ b/docs/dark/framework_8h__dep__incl.md5 @@ -1 +1 @@ -5a5e959a9c60a85aa24fc7558c92c4f8 \ No newline at end of file +b05d6f6c3b6cb629517cb688eb0e9bef \ No newline at end of file diff --git a/docs/dark/framework_8h_source.html b/docs/dark/framework_8h_source.html index b8f08a34..3e61919b 100644 --- a/docs/dark/framework_8h_source.html +++ b/docs/dark/framework_8h_source.html @@ -87,21 +87,27 @@
      framework.h
      -Go to the documentation of this file.
      1 #pragma once
      -
      2 
      -
      3 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
      -
      4 // Windows Header Files
      -
      5 
      -
      6 #ifdef _WIN32
      -
      7 #include <windows.h>
      -
      8 #endif
      +Go to the documentation of this file.
      1 /** @file framework.h
      +
      2  * @brief for windows dynamic library
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  */
      +
      6 
      +
      7 #pragma once
      +
      8 
      +
      9 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
      +
      10 // Windows Header Files
      +
      11 
      +
      12 #ifdef _WIN32
      +
      13 #include <windows.h>
      +
      14 #endif
      + +

      Wrapper for Markov::Model to use with char represented models. +More...

      #include "markovPasswords.h"
      #include <string.h>
      #include <chrono>
      @@ -104,8 +107,8 @@
      - - + + @@ -114,17 +117,17 @@ - - + + - - + + - + @@ -143,7 +146,15 @@ static volatile int keepRunning = 1   -

      Function Documentation

      +

      Detailed Description

      +

      Wrapper for Markov::Model to use with char represented models.

      +
      Authors
      Ata Hakçıl, Osman Ömer Yıldıztugay
      +

      This file contains the implementation for Markov::API::MarkovPasswords class.

      +

      Markov::Model with char represented nodes. Includes wrappers for Markov::Model and additional helper functions to handle file I/O

      +

      This class is an extension of Markov::Model<char>, with higher level abstractions such as train and generate.

      + +

      Definition in file markovPasswords.cpp.

      +

      Function Documentation

      ◆ intHandler()

      @@ -160,27 +171,28 @@

      -

      Definition at line 18 of file markovPasswords.cpp.

      -
      18  {
      -
      19  std::cout << "You wanted this man by presing CTRL-C ! Ok bye.";
      -
      20  //Sleep(5000);
      -
      21  keepRunning = 0;
      -
      22  exit(0);
      -
      23 }
      +

      Definition at line 26 of file markovPasswords.cpp.

      +
      26  {
      +
      27  std::cout << "You wanted this man by presing CTRL-C ! Ok bye.";
      +
      28  //Sleep(5000);
      +
      29  keepRunning = 0;
      +
      30  exit(0);
      +
      31 }
      -

      References keepRunning.

      +

      References keepRunning.

      -

      Referenced by Markov::API::MarkovPasswords::Train().

      +

      Referenced by Markov::API::MarkovPasswords::Train().

      Here is the caller graph for this function:
      - - - - - + + + + + +
      @@ -207,20 +219,20 @@

      -

      Definition at line 16 of file markovPasswords.cpp.

      +

      Definition at line 24 of file markovPasswords.cpp.

      -

      Referenced by intHandler(), and Markov::API::MarkovPasswords::TrainThread().

      +

      Referenced by intHandler(), and Markov::API::MarkovPasswords::TrainThread().

      -
      static volatile int keepRunning
      +
      static volatile int keepRunning
      -Go to the documentation of this file.
      1 #pragma once
      -
      2 #include "markovPasswords.h"
      -
      3 #include <string.h>
      -
      4 #include <chrono>
      -
      5 #include <thread>
      -
      6 #include <vector>
      -
      7 #include <mutex>
      -
      8 #include <string>
      -
      9 #include <signal.h>
      -
      10 #ifdef _WIN32
      -
      11 #include <Windows.h>
      -
      12 #else
      -
      13 #include <unistd.h>
      -
      14 #endif
      -
      15 
      -
      16 static volatile int keepRunning = 1;
      -
      17 
      -
      18 void intHandler(int dummy) {
      -
      19  std::cout << "You wanted this man by presing CTRL-C ! Ok bye.";
      -
      20  //Sleep(5000);
      -
      21  keepRunning = 0;
      -
      22  exit(0);
      -
      23 }
      -
      24 
      +Go to the documentation of this file.
      1 /** @file markovPasswords.cpp
      +
      2  * @brief Wrapper for Markov::Model to use with char represented models.
      +
      3  * @authors Ata Hakçıl, Osman Ömer Yıldıztugay
      +
      4  *
      +
      5  * This file contains the implementation for Markov::API::MarkovPasswords class.
      +
      6  *
      +
      7  * @copydoc Markov::API::MarkovPasswords
      +
      8  */
      +
      9 
      +
      10 #include "markovPasswords.h"
      +
      11 #include <string.h>
      +
      12 #include <chrono>
      +
      13 #include <thread>
      +
      14 #include <vector>
      +
      15 #include <mutex>
      +
      16 #include <string>
      +
      17 #include <signal.h>
      +
      18 #ifdef _WIN32
      +
      19 #include <Windows.h>
      +
      20 #else
      +
      21 #include <unistd.h>
      +
      22 #endif
      +
      23 
      +
      24 static volatile int keepRunning = 1;
      25 
      -
      26 Markov::API::MarkovPasswords::MarkovPasswords() : Markov::Model<char>(){
      -
      27 
      -
      28 
      -
      29 }
      -
      30 
      -
      31 Markov::API::MarkovPasswords::MarkovPasswords(const char* filename) {
      +
      26 void intHandler(int dummy) {
      +
      27  std::cout << "You wanted this man by presing CTRL-C ! Ok bye.";
      +
      28  //Sleep(5000);
      +
      29  keepRunning = 0;
      +
      30  exit(0);
      +
      31 }
      32 
      -
      33  std::ifstream* importFile;
      -
      34 
      -
      35  this->Import(filename);
      +
      33 
      + +
      35 
      36 
      -
      37  //std::ifstream* newFile(filename);
      +
      37 }
      38 
      -
      39  //importFile = newFile;
      +
      39 Markov::API::MarkovPasswords::MarkovPasswords(const char* filename) {
      40 
      -
      41 }
      +
      41  std::ifstream* importFile;
      42 
      -
      43 std::ifstream* Markov::API::MarkovPasswords::OpenDatasetFile(const char* filename){
      +
      43  this->Import(filename);
      44 
      -
      45  std::ifstream* datasetFile;
      +
      45  //std::ifstream* newFile(filename);
      46 
      -
      47  std::ifstream newFile(filename);
      +
      47  //importFile = newFile;
      48 
      -
      49  datasetFile = &newFile;
      +
      49 }
      50 
      -
      51  this->Import(datasetFile);
      -
      52  return datasetFile;
      -
      53 }
      +
      51 std::ifstream* Markov::API::MarkovPasswords::OpenDatasetFile(const char* filename){
      +
      52 
      +
      53  std::ifstream* datasetFile;
      54 
      -
      55 
      +
      55  std::ifstream newFile(filename);
      56 
      -
      57 void Markov::API::MarkovPasswords::Train(const char* datasetFileName, char delimiter, int threads) {
      -
      58  signal(SIGINT, intHandler);
      -
      59  Markov::API::Concurrency::ThreadSharedListHandler listhandler(datasetFileName);
      -
      60  auto start = std::chrono::high_resolution_clock::now();
      -
      61 
      -
      62  std::vector<std::thread*> threadsV;
      -
      63  for(int i=0;i<threads;i++){
      -
      64  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::TrainThread, this, &listhandler, delimiter));
      -
      65  }
      -
      66 
      -
      67  for(int i=0;i<threads;i++){
      -
      68  threadsV[i]->join();
      -
      69  delete threadsV[i];
      -
      70  }
      -
      71  auto finish = std::chrono::high_resolution_clock::now();
      -
      72  std::chrono::duration<double> elapsed = finish - start;
      -
      73  std::cout << "Elapsed time: " << elapsed.count() << " s\n";
      +
      57  datasetFile = &newFile;
      +
      58 
      +
      59  this->Import(datasetFile);
      +
      60  return datasetFile;
      +
      61 }
      +
      62 
      +
      63 
      +
      64 
      +
      65 void Markov::API::MarkovPasswords::Train(const char* datasetFileName, char delimiter, int threads) {
      +
      66  signal(SIGINT, intHandler);
      +
      67  Markov::API::Concurrency::ThreadSharedListHandler listhandler(datasetFileName);
      +
      68  auto start = std::chrono::high_resolution_clock::now();
      +
      69 
      +
      70  std::vector<std::thread*> threadsV;
      +
      71  for(int i=0;i<threads;i++){
      +
      72  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::TrainThread, this, &listhandler, delimiter));
      +
      73  }
      74 
      -
      75 }
      -
      76 
      -
      77 void Markov::API::MarkovPasswords::TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter){
      -
      78  char format_str[] ="%ld,%s";
      -
      79  format_str[3]=delimiter;
      -
      80  std::string line;
      -
      81  while (listhandler->next(&line) && keepRunning) {
      -
      82  long int oc;
      -
      83  if (line.size() > 100) {
      -
      84  line = line.substr(0, 100);
      -
      85  }
      -
      86  char* linebuf = new char[line.length()+5];
      -
      87 #ifdef _WIN32
      -
      88  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
      -
      89 #else
      -
      90  sscanf(line.c_str(), format_str, &oc, linebuf);
      -
      91 #endif
      -
      92  this->AdjustEdge((const char*)linebuf, oc);
      -
      93  delete linebuf;
      -
      94  }
      -
      95 }
      -
      96 
      -
      97 
      -
      98 std::ofstream* Markov::API::MarkovPasswords::Save(const char* filename) {
      -
      99  std::ofstream* exportFile;
      -
      100 
      -
      101  std::ofstream newFile(filename);
      -
      102 
      -
      103  exportFile = &newFile;
      +
      75  for(int i=0;i<threads;i++){
      +
      76  threadsV[i]->join();
      +
      77  delete threadsV[i];
      +
      78  }
      +
      79  auto finish = std::chrono::high_resolution_clock::now();
      +
      80  std::chrono::duration<double> elapsed = finish - start;
      +
      81  std::cout << "Elapsed time: " << elapsed.count() << " s\n";
      +
      82 
      +
      83 }
      +
      84 
      + +
      86  char format_str[] ="%ld,%s";
      +
      87  format_str[3]=delimiter;
      +
      88  std::string line;
      +
      89  while (listhandler->next(&line) && keepRunning) {
      +
      90  long int oc;
      +
      91  if (line.size() > 100) {
      +
      92  line = line.substr(0, 100);
      +
      93  }
      +
      94  char* linebuf = new char[line.length()+5];
      +
      95 #ifdef _WIN32
      +
      96  sscanf_s(line.c_str(), "%ld,%s", &oc, linebuf, line.length()+5); //<== changed format_str to-> "%ld,%s"
      +
      97 #else
      +
      98  sscanf(line.c_str(), format_str, &oc, linebuf);
      +
      99 #endif
      +
      100  this->AdjustEdge((const char*)linebuf, oc);
      +
      101  delete linebuf;
      +
      102  }
      +
      103 }
      104 
      -
      105  this->Export(exportFile);
      -
      106  return exportFile;
      -
      107 }
      +
      105 
      +
      106 std::ofstream* Markov::API::MarkovPasswords::Save(const char* filename) {
      +
      107  std::ofstream* exportFile;
      108 
      -
      109 
      -
      110 void Markov::API::MarkovPasswords::Generate(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen, int threads) {
      -
      111  char* res;
      -
      112  char print[100];
      -
      113  std::ofstream wordlist;
      -
      114  wordlist.open(wordlistFileName);
      -
      115  std::mutex mlock;
      -
      116  int iterationsPerThread = n/threads;
      -
      117  int iterationsCarryOver = n%threads;
      -
      118  std::vector<std::thread*> threadsV;
      -
      119  for(int i=0;i<threads;i++){
      -
      120  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
      -
      121  }
      -
      122 
      -
      123  for(int i=0;i<threads;i++){
      -
      124  threadsV[i]->join();
      -
      125  delete threadsV[i];
      -
      126  }
      -
      127 
      -
      128  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
      -
      129 
      -
      130 }
      -
      131 
      -
      132 void Markov::API::MarkovPasswords::GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen) {
      -
      133  char* res = new char[maxLen+5];
      -
      134  if(n==0) return;
      +
      109  std::ofstream newFile(filename);
      +
      110 
      +
      111  exportFile = &newFile;
      +
      112 
      +
      113  this->Export(exportFile);
      +
      114  return exportFile;
      +
      115 }
      +
      116 
      +
      117 
      +
      118 void Markov::API::MarkovPasswords::Generate(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen, int threads) {
      +
      119  char* res;
      +
      120  char print[100];
      +
      121  std::ofstream wordlist;
      +
      122  wordlist.open(wordlistFileName);
      +
      123  std::mutex mlock;
      +
      124  int iterationsPerThread = n/threads;
      +
      125  int iterationsCarryOver = n%threads;
      +
      126  std::vector<std::thread*> threadsV;
      +
      127  for(int i=0;i<threads;i++){
      +
      128  threadsV.push_back(new std::thread(&Markov::API::MarkovPasswords::GenerateThread, this, &mlock, iterationsPerThread, &wordlist, minLen, maxLen));
      +
      129  }
      +
      130 
      +
      131  for(int i=0;i<threads;i++){
      +
      132  threadsV[i]->join();
      +
      133  delete threadsV[i];
      +
      134  }
      135 
      -
      136  Markov::Random::Marsaglia MarsagliaRandomEngine;
      -
      137  for (int i = 0; i < n; i++) {
      -
      138  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
      -
      139  outputLock->lock();
      -
      140  *wordlist << res << "\n";
      -
      141  outputLock->unlock();
      -
      142  }
      -
      143 }
      +
      136  this->GenerateThread(&mlock, iterationsCarryOver, &wordlist, minLen, maxLen);
      +
      137 
      +
      138 }
      +
      139 
      +
      140 void Markov::API::MarkovPasswords::GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen) {
      +
      141  char* res = new char[maxLen+5];
      +
      142  if(n==0) return;
      +
      143 
      +
      144  Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      145  for (int i = 0; i < n; i++) {
      +
      146  this->RandomWalk(&MarsagliaRandomEngine, minLen, maxLen, res);
      +
      147  outputLock->lock();
      +
      148  *wordlist << res << "\n";
      +
      149  outputLock->unlock();
      +
      150  }
      +
      151 }
      +
      152 
      +
      153 void Markov::API::MarkovPasswords::Buff(const char* str, double multiplier, bool bDontAdjustSelfLoops, bool bDontAdjustExtendedLoops){
      +
      154  std::string buffstr(str);
      +
      155  std::map< char, Node< char > * > *nodes;
      +
      156  std::map< char, Edge< char > * > *edges;
      +
      157  nodes = this->Nodes();
      +
      158  int i=0;
      +
      159  for (auto const& [repr, node] : *nodes){
      +
      160  edges = node->Edges();
      +
      161  for (auto const& [targetrepr, edge] : *edges){
      +
      162  if(buffstr.find(targetrepr)!= std::string::npos){
      +
      163  if(bDontAdjustSelfLoops && repr==targetrepr) continue;
      +
      164  if(bDontAdjustExtendedLoops){
      +
      165  if(buffstr.find(repr)!= std::string::npos){
      +
      166  continue;
      +
      167  }
      +
      168  }
      +
      169  long int weight = edge->EdgeWeight();
      +
      170  weight = weight*multiplier;
      +
      171  edge->AdjustEdge(weight);
      +
      172  }
      +
      173 
      +
      174  }
      +
      175  i++;
      +
      176  }
      +
      177 
      + +
      179 }
      -
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:323
      -
      Objects related to RNG.
      Definition: random.h:9
      -
      std::ifstream * OpenDatasetFile(const char *filename)
      Open dataset file and return the ifstream pointer.
      -
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:207
      -
      Markov::Model with char represented nodes.
      -
      std::ofstream * Save(const char *filename)
      Export model to file.
      -
      void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
      A single thread invoked by the Train function.
      -
      void intHandler(int dummy)
      -
      void Generate(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
      Call Markov::Model::RandomWalk n times, and collect output.
      -
      Namespace for Concurrency related classes.
      -
      Simple class for managing shared access to file.
      -
      NodeStorageType * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer)
      Do a random walk on this model.
      Definition: model.h:293
      -
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:274
      -
      MarkovPasswords()
      Initialize the markov model from MarkovModel::Markov::Model.
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      -
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      -
      bool next(std::string *line)
      Read the next line from the file.
      -
      bool Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: model.h:266
      -
      class for the final Markov Model, constructed from nodes and edges.
      Definition: model.h:41
      -
      MarkovPasswords(const char *filename)
      Initialize the markov model from MarkovModel::Markov::Model, with an import file.
      -
      static volatile int keepRunning
      -
      ThreadSharedListHandler(const char *filename)
      Construct the Thread Handler with a filename.
      +
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:337
      +
      std::map< NodeStorageType, Node< NodeStorageType > * > * Nodes()
      Return starter Node.
      Definition: model.h:181
      +
      Objects related to RNG.
      Definition: random.h:18
      +
      std::ifstream * OpenDatasetFile(const char *filename)
      Open dataset file and return the ifstream pointer.
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      Markov::Model with char represented nodes.
      +
      std::ofstream * Save(const char *filename)
      Export model to file.
      +
      void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
      A single thread invoked by the Train function.
      +
      void intHandler(int dummy)
      +
      void Generate(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
      Call Markov::Model::RandomWalk n times, and collect output.
      +
      Namespace for Concurrency related classes.
      +
      void OptimizeEdgeOrder()
      Sort edges of all nodes in the model ordered by edge weights.
      Definition: model.h:265
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      Namespace for the MarkovPasswords API.
      +
      Simple class for managing shared access to file.
      +
      NodeStorageType * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer)
      Do a random walk on this model.
      Definition: model.h:307
      +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      +
      MarkovPasswords()
      Initialize the markov model from MarkovModel::Markov::Model.
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      +
      void AdjustEdge(long int offset)
      Adjust the edge EdgeWeight with offset. Adds the offset parameter to the edge EdgeWeight.
      Definition: edge.h:137
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      +
      std::map< storageType, Edge< storageType > * > * Edges()
      return edges
      Definition: node.h:272
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      bool next(std::string *line)
      Read the next line from the file.
      +
      bool Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: model.h:280
      +
      class for the final Markov Model, constructed from nodes and edges.
      Definition: model.h:45
      +
      MarkovPasswords(const char *filename)
      Initialize the markov model from MarkovModel::Markov::Model, with an import file.
      +
      static volatile int keepRunning
      +
      void Buff(const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
      Buff expression of some characters in the model.
      +
      ThreadSharedListHandler(const char *filename)
      Construct the Thread Handler with a filename.
      + +

      Wrapper for Markov::Model to use with char represented models. +More...

      @@ -97,9 +100,9 @@
      - - - + + + @@ -107,11 +110,11 @@ - - + + - + @@ -122,13 +125,17 @@
      - - - - - - - + + + + + + + + + + +
      @@ -149,13 +156,21 @@  Namespace for the MarkovPasswords API.
        -
      +

      Detailed Description

      +

      Wrapper for Markov::Model to use with char represented models.

      +
      Authors
      Ata Hakçıl, Osman Ömer Yıldıztugay
      +

      This file contains the declerations for Markov::API::MarkovPasswords class.

      +

      Markov::Model with char represented nodes. Includes wrappers for Markov::Model and additional helper functions to handle file I/O

      +

      This class is an extension of Markov::Model<char>, with higher level abstractions such as train and generate.

      + +

      Definition in file markovPasswords.h.

      +
      -Go to the documentation of this file.
      1 #pragma once
      - -
      3 #include "MarkovModel/src/model.h"
      -
      4 
      -
      5 
      -
      6 /** @brief Namespace for the MarkovPasswords API
      -
      7 */
      -
      8 namespace Markov::API{
      +Go to the documentation of this file.
      1 /** @file markovPasswords.h
      +
      2  * @brief Wrapper for Markov::Model to use with char represented models.
      +
      3  * @authors Ata Hakçıl, Osman Ömer Yıldıztugay
      +
      4  *
      +
      5  * This file contains the declerations for Markov::API::MarkovPasswords class.
      +
      6  *
      +
      7  * @copydoc Markov::API::MarkovPasswords
      +
      8  */
      9 
      -
      10  /** @brief Markov::Model with char represented nodes.
      -
      11  *
      -
      12  * Includes wrappers for Markov::Model and additional helper functions to handle file I/O
      -
      13  *
      -
      14  * This class is an extension of Markov::Model<char>, with higher level abstractions such as train and generate.
      -
      15  *
      -
      16  */
      -
      17  class MarkovPasswords : public Markov::Model<char>{
      -
      18  public:
      -
      19 
      -
      20  /** @brief Initialize the markov model from MarkovModel::Markov::Model.
      -
      21  *
      -
      22  * Parent constructor. Has no extra functionality.
      -
      23  */
      - -
      25 
      -
      26  /** @brief Initialize the markov model from MarkovModel::Markov::Model, with an import file.
      -
      27  *
      -
      28  * This function calls the Markov::Model::Import on the filename to construct the model.
      -
      29  * Same thing as creating and empty model, and calling MarkovPasswords::Import on the filename.
      +
      10 #pragma once
      + +
      12 #include "MarkovModel/src/model.h"
      +
      13 
      +
      14 
      +
      15 /** @brief Namespace for the MarkovPasswords API
      +
      16 */
      +
      17 namespace Markov::API{
      +
      18 
      +
      19  /** @brief Markov::Model with char represented nodes.
      +
      20  *
      +
      21  * Includes wrappers for Markov::Model and additional helper functions to handle file I/O
      +
      22  *
      +
      23  * This class is an extension of Markov::Model<char>, with higher level abstractions such as train and generate.
      +
      24  *
      +
      25  */
      +
      26  class MarkovPasswords : public Markov::Model<char>{
      +
      27  public:
      +
      28 
      +
      29  /** @brief Initialize the markov model from MarkovModel::Markov::Model.
      30  *
      -
      31  * @param filename - Filename to import
      -
      32  *
      -
      33  *
      -
      34  * @b Example @b Use: Construction via filename
      -
      35  * @code{.cpp}
      -
      36  * MarkovPasswords mp("test.mdl");
      -
      37  * @endcode
      -
      38  */
      -
      39  MarkovPasswords(const char* filename);
      -
      40 
      -
      41  /** @brief Open dataset file and return the ifstream pointer
      -
      42  * @param filename - Filename to open
      -
      43  * @return ifstream* to the the dataset file
      -
      44  */
      -
      45  std::ifstream* OpenDatasetFile(const char* filename);
      -
      46 
      -
      47 
      -
      48  /** @brief Train the model with the dataset file.
      -
      49  * @param datasetFileName - Ifstream* to the dataset. If null, use class member
      -
      50  * @param delimiter - a character, same as the delimiter in dataset content
      -
      51  * @param threads - number of OS threads to spawn
      -
      52  *
      -
      53  * @code{.cpp}
      -
      54  * Markov::API::MarkovPasswords mp;
      -
      55  * mp.Import("models/2gram.mdl");
      -
      56  * mp.Train("password.corpus");
      -
      57  * @endcode
      -
      58  */
      -
      59  void Train(const char* datasetFileName, char delimiter, int threads);
      -
      60 
      -
      61 
      -
      62 
      -
      63  /** @brief Export model to file.
      -
      64  * @param filename - Export filename.
      -
      65  * @return std::ofstream* of the exported file.
      -
      66  */
      -
      67  std::ofstream* Save(const char* filename);
      -
      68 
      -
      69  /** @brief Call Markov::Model::RandomWalk n times, and collect output.
      -
      70  *
      -
      71  * Generate from model and write results to a file.
      -
      72  * a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
      -
      73  *
      -
      74  * @deprecated See Markov::API::MatrixModel::FastRandomWalk for more information.
      -
      75  * @param n - Number of passwords to generate.
      -
      76  * @param wordlistFileName - Filename to write to
      -
      77  * @param minLen - Minimum password length to generate
      -
      78  * @param maxLen - Maximum password length to generate
      -
      79  * @param threads - number of OS threads to spawn
      -
      80  */
      -
      81  void Generate(unsigned long int n, const char* wordlistFileName, int minLen=6, int maxLen=12, int threads=20);
      -
      82 
      -
      83 
      -
      84  private:
      -
      85 
      -
      86  /** @brief A single thread invoked by the Train function.
      -
      87  * @param listhandler - Listhandler class to read corpus from
      -
      88  * @param delimiter - a character, same as the delimiter in dataset content
      -
      89  *
      -
      90  */
      -
      91  void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter);
      -
      92 
      -
      93  /** @brief A single thread invoked by the Generate function.
      -
      94  *
      -
      95  * @b DEPRECATED: See Markov::API::MatrixModel::FastRandomWalkThread for more information. This has been replaced with
      -
      96  * a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
      -
      97  *
      -
      98  * @param outputLock - shared mutex lock to lock during output operation. Prevents race condition on write.
      -
      99  * @param n number of lines to be generated by this thread
      -
      100  * @param wordlist wordlistfile
      -
      101  * @param minLen - Minimum password length to generate
      -
      102  * @param maxLen - Maximum password length to generate
      -
      103  *
      -
      104  */
      -
      105  void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen);
      -
      106  std::ifstream* datasetFile; /** @brief Dataset file input of our system */
      -
      107  std::ofstream* modelSavefile; /** @brief File to save model of our system */
      -
      108  std::ofstream* outputFile; /** @brief Generated output file of our system */
      -
      109  };
      -
      110 
      -
      111 
      -
      112 
      -
      113 };
      +
      31  * Parent constructor. Has no extra functionality.
      +
      32  */
      + +
      34 
      +
      35  /** @brief Initialize the markov model from MarkovModel::Markov::Model, with an import file.
      +
      36  *
      +
      37  * This function calls the Markov::Model::Import on the filename to construct the model.
      +
      38  * Same thing as creating and empty model, and calling MarkovPasswords::Import on the filename.
      +
      39  *
      +
      40  * @param filename - Filename to import
      +
      41  *
      +
      42  *
      +
      43  * @b Example @b Use: Construction via filename
      +
      44  * @code{.cpp}
      +
      45  * MarkovPasswords mp("test.mdl");
      +
      46  * @endcode
      +
      47  */
      +
      48  MarkovPasswords(const char* filename);
      +
      49 
      +
      50  /** @brief Open dataset file and return the ifstream pointer
      +
      51  * @param filename - Filename to open
      +
      52  * @return ifstream* to the the dataset file
      +
      53  */
      +
      54  std::ifstream* OpenDatasetFile(const char* filename);
      +
      55 
      +
      56 
      +
      57  /** @brief Train the model with the dataset file.
      +
      58  * @param datasetFileName - Ifstream* to the dataset. If null, use class member
      +
      59  * @param delimiter - a character, same as the delimiter in dataset content
      +
      60  * @param threads - number of OS threads to spawn
      +
      61  *
      +
      62  * @code{.cpp}
      +
      63  * Markov::API::MarkovPasswords mp;
      +
      64  * mp.Import("models/2gram.mdl");
      +
      65  * mp.Train("password.corpus");
      +
      66  * @endcode
      +
      67  */
      +
      68  void Train(const char* datasetFileName, char delimiter, int threads);
      +
      69 
      +
      70 
      +
      71 
      +
      72  /** @brief Export model to file.
      +
      73  * @param filename - Export filename.
      +
      74  * @return std::ofstream* of the exported file.
      +
      75  */
      +
      76  std::ofstream* Save(const char* filename);
      +
      77 
      +
      78  /** @brief Call Markov::Model::RandomWalk n times, and collect output.
      +
      79  *
      +
      80  * Generate from model and write results to a file.
      +
      81  * a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
      +
      82  *
      +
      83  * @deprecated See Markov::API::MatrixModel::FastRandomWalk for more information.
      +
      84  * @param n - Number of passwords to generate.
      +
      85  * @param wordlistFileName - Filename to write to
      +
      86  * @param minLen - Minimum password length to generate
      +
      87  * @param maxLen - Maximum password length to generate
      +
      88  * @param threads - number of OS threads to spawn
      +
      89  */
      +
      90  void Generate(unsigned long int n, const char* wordlistFileName, int minLen=6, int maxLen=12, int threads=20);
      +
      91 
      +
      92  /** @brief Buff expression of some characters in the model
      +
      93  * @param str A string containing all the characters to be buffed
      +
      94  * @param multiplier A constant value to buff the nodes with.
      +
      95  * @param bDontAdjustSelfEdges Do not adjust weights if target node is same as source node
      +
      96  * @param bDontAdjustExtendedLoops Do not adjust if both source and target nodes are in first parameter
      +
      97  */
      +
      98  void Buff(const char* str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false);
      +
      99 
      +
      100 
      +
      101  private:
      +
      102 
      +
      103  /** @brief A single thread invoked by the Train function.
      +
      104  * @param listhandler - Listhandler class to read corpus from
      +
      105  * @param delimiter - a character, same as the delimiter in dataset content
      +
      106  *
      +
      107  */
      +
      108  void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter);
      +
      109 
      +
      110  /** @brief A single thread invoked by the Generate function.
      +
      111  *
      +
      112  * @b DEPRECATED: See Markov::API::MatrixModel::FastRandomWalkThread for more information. This has been replaced with
      +
      113  * a much more performance-optimized method. FastRandomWalk will reduce the runtime by %96.5 on average.
      +
      114  *
      +
      115  * @param outputLock - shared mutex lock to lock during output operation. Prevents race condition on write.
      +
      116  * @param n number of lines to be generated by this thread
      +
      117  * @param wordlist wordlistfile
      +
      118  * @param minLen - Minimum password length to generate
      +
      119  * @param maxLen - Maximum password length to generate
      +
      120  *
      +
      121  */
      +
      122  void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen);
      +
      123  std::ifstream* datasetFile; /** @brief Dataset file input of our system */
      +
      124  std::ofstream* modelSavefile; /** @brief File to save model of our system */
      +
      125  std::ofstream* outputFile; /** @brief Generated output file of our system */
      +
      126  };
      +
      127 
      +
      128 
      +
      129 
      +
      130 };
      -
      std::ifstream * OpenDatasetFile(const char *filename)
      Open dataset file and return the ifstream pointer.
      -
      Markov::Model with char represented nodes.
      -
      std::ofstream * Save(const char *filename)
      Export model to file.
      -
      void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
      A single thread invoked by the Train function.
      -
      void Generate(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
      Call Markov::Model::RandomWalk n times, and collect output.
      -
      Namespace for Concurrency related classes.
      -
      Simple class for managing shared access to file.
      - -
      MarkovPasswords()
      Initialize the markov model from MarkovModel::Markov::Model.
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      -
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      -
      std::ofstream * outputFile
      File to save model of our system
      -
      class for the final Markov Model, constructed from nodes and edges.
      Definition: model.h:41
      -
      std::ofstream * modelSavefile
      Dataset file input of our system
      -
      MarkovPasswords(const char *filename)
      Initialize the markov model from MarkovModel::Markov::Model, with an import file.
      +
      std::ifstream * OpenDatasetFile(const char *filename)
      Open dataset file and return the ifstream pointer.
      +
      Markov::Model with char represented nodes.
      +
      std::ofstream * Save(const char *filename)
      Export model to file.
      +
      void TrainThread(Markov::API::Concurrency::ThreadSharedListHandler *listhandler, char delimiter)
      A single thread invoked by the Train function.
      +
      void Generate(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20)
      Call Markov::Model::RandomWalk n times, and collect output.
      +
      Namespace for Concurrency related classes.
      +
      Namespace for the MarkovPasswords API.
      +
      Simple class for managing shared access to file.
      + +
      MarkovPasswords()
      Initialize the markov model from MarkovModel::Markov::Model.
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      void GenerateThread(std::mutex *outputLock, unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen)
      A single thread invoked by the Generate function.
      +
      std::ofstream * outputFile
      File to save model of our system
      +
      std::ofstream * modelSavefile
      Dataset file input of our system
      +
      MarkovPasswords(const char *filename)
      Initialize the markov model from MarkovModel::Markov::Model, with an import file.
      +
      void Buff(const char *str, double multiplier, bool bDontAdjustSelfLoops=true, bool bDontAdjustExtendedLoops=false)
      Buff expression of some characters in the model.
      + +

      menu page +More...

      #include "menu.h"
      #include <fstream>
      #include "MarkovPasswordsGUI.h"
      @@ -96,10 +99,10 @@
      - - + + - + @@ -108,13 +111,18 @@

      Go to the source code of this file.

      -
      +

      Detailed Description

      +

      menu page

      +
      Authors
      Yunus Emre Yılmaz
      + +

      Definition in file menu.cpp.

      +
      -Go to the documentation of this file.
      1 #include "menu.h"
      -
      2 #include <fstream>
      - -
      4 #include <QtWidgets/QApplication>
      -
      5 
      -
      6 using namespace Markov::GUI;
      -
      7 
      -
      8 menu::menu(QWidget* parent)
      -
      9  : QMainWindow(parent)
      -
      10 {
      -
      11  ui.setupUi(this);
      -
      12 
      +Go to the documentation of this file.
      1 /** @file menu.cpp
      +
      2  * @brief menu page
      +
      3  * @authors Yunus Emre Yılmaz
      +
      4  *
      +
      5  */
      +
      6 
      +
      7 #include "menu.h"
      +
      8 #include <fstream>
      + +
      10 #include <QtWidgets/QApplication>
      +
      11 
      +
      12 using namespace Markov::GUI;
      13 
      -
      14  //QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {about(); });
      -
      15  QObject::connect(ui.visu, &QPushButton::clicked, this, [this] {visualization(); });
      -
      16 }
      -
      17 void menu::about() {
      +
      14 menu::menu(QWidget* parent)
      +
      15  : QMainWindow(parent)
      +
      16 {
      +
      17  ui.setupUi(this);
      18 
      19 
      -
      20 }
      -
      21 void menu::visualization() {
      -
      22  MarkovPasswordsGUI* w = new MarkovPasswordsGUI;
      -
      23  w->show();
      -
      24  this->close();
      -
      25 }
      +
      20  //QObject::connect(ui.pushButton, &QPushButton::clicked, this, [this] {about(); });
      +
      21  QObject::connect(ui.visu, &QPushButton::clicked, this, [this] {visualization(); });
      +
      22 }
      +
      23 void menu::about() {
      +
      24 
      +
      25 
      +
      26 }
      + + +
      29  w->show();
      +
      30  this->close();
      +
      31 }
      -
      namespace for MarkovPasswords API GUI wrapper
      Definition: menu.h:6
      +
      Ui::main ui
      Definition: menu.h:21
      +
      namespace for MarkovPasswords API GUI wrapper
      Definition: about.h:14
      +
      void about()
      Definition: menu.cpp:23
      +
      QT Menu class.
      Definition: menu.h:15
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      + +
      menu(QWidget *parent=Q_NULLPTR)
      Definition: menu.cpp:14
      +
      void visualization()
      Definition: menu.cpp:27
      + +

      menu page +More...

      #include <QtWidgets/QMainWindow>
      #include "ui_menu.h"
      @@ -97,7 +100,7 @@
      - + @@ -107,9 +110,9 @@
      - - - + + +
      @@ -130,13 +133,18 @@  namespace for MarkovPasswords API GUI wrapper
        -
      +

      Detailed Description

      +

      menu page

      +
      Authors
      Yunus Emre Yılmaz
      + +

      Definition in file menu.h.

      +
      -Go to the documentation of this file.
      1 #pragma once
      -
      2 #include <QtWidgets/QMainWindow>
      -
      3 #include "ui_menu.h"
      -
      4 
      -
      5 
      -
      6 namespace Markov::GUI{
      -
      7  /** @brief QT Menu class
      -
      8  */
      -
      9  class menu:public QMainWindow {
      -
      10  Q_OBJECT
      -
      11  public:
      - -
      13 
      -
      14  private:
      - -
      16 
      -
      17  public slots:
      -
      18  void about();
      -
      19  void visualization();
      -
      20  };
      -
      21 };
      +Go to the documentation of this file.
      1 /** @file menu.h
      +
      2  * @brief menu page
      +
      3  * @authors Yunus Emre Yılmaz
      +
      4  *
      +
      5  */
      +
      6 
      +
      7 #pragma once
      +
      8 #include <QtWidgets/QMainWindow>
      +
      9 #include "ui_menu.h"
      +
      10 
      +
      11 
      +
      12 namespace Markov::GUI{
      +
      13  /** @brief QT Menu class
      +
      14  */
      +
      15  class menu:public QMainWindow {
      +
      16  Q_OBJECT
      +
      17  public:
      +
      18  menu(QWidget* parent = Q_NULLPTR);
      +
      19 
      +
      20  private:
      +
      21  Ui::main ui;
      +
      22 
      +
      23  public slots:
      +
      24  void about();
      +
      25  void visualization();
      +
      26  };
      +
      27 };
      -
      Ui::main ui
      Definition: menu.h:15
      -
      namespace for MarkovPasswords API GUI wrapper
      Definition: menu.h:6
      -
      void about()
      Definition: menu.cpp:17
      -
      void visualization()
      Definition: menu.cpp:21
      +
      Ui::main ui
      Definition: menu.h:21
      +
      namespace for MarkovPasswords API GUI wrapper
      Definition: about.h:14
      +
      void about()
      Definition: menu.cpp:23
      +
      QT Menu class.
      Definition: menu.h:15
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      menu(QWidget *parent=Q_NULLPTR)
      Definition: menu.cpp:14
      +
      void visualization()
      Definition: menu.cpp:27
      + +

      Model class template. +More...

      #include <map>
      #include <vector>
      #include <fstream>
      @@ -103,18 +106,18 @@
      - + - - + + - + @@ -125,16 +128,20 @@
      - - - - - - - - - - + + + + + + + + + + + + + +
      @@ -158,13 +165,20 @@  Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
        -
      +

      Detailed Description

      +

      Model class template.

      +
      Authors
      Ata Hakçıl, Osman Ömer Yıldıztugay
      +

      class for the final Markov Model, constructed from nodes and edges. Each atomic piece of the generation result is stored in a node, while edges contain the relation weights. Extending: To extend the class, implement the template and inherit from it, as "class MyModel : public Markov::Model<char>". For a complete demonstration of how to extend the class, see MarkovPasswords.

      +

      Whole model can be defined as a list of the edges, as dangling nodes are pointless. This approach is used for the import/export operations. For more information on importing/exporting model, check out the github readme and wiki page.

      + +

      Definition in file model.h.

      +
      -Go to the documentation of this file.
      1 /** @dir Model.h
      -
      2  *
      -
      3  */
      -
      4 
      -
      5 
      -
      6 #pragma once
      -
      7 #include <map>
      -
      8 #include <vector>
      -
      9 #include <fstream>
      -
      10 #include <assert.h>
      -
      11 #include <string>
      -
      12 #include <algorithm>
      -
      13 #include "node.h"
      -
      14 #include "edge.h"
      -
      15 
      -
      16 /**
      -
      17  @brief Namespace for the markov-model related classes.
      -
      18  Contains Model, Node and Edge classes
      -
      19 */
      -
      20 namespace Markov {
      -
      21 
      -
      22  template <typename NodeStorageType>
      -
      23  class Node;
      -
      24 
      -
      25  template <typename NodeStorageType>
      -
      26  class Edge;
      -
      27 
      -
      28  template <typename NodeStorageType>
      -
      29 
      -
      30  /** @brief class for the final Markov Model, constructed from nodes and edges.
      -
      31  *
      -
      32  * Each atomic piece of the generation result is stored in a node, while edges contain the relation weights.
      -
      33  * *Extending:*
      -
      34  * To extend the class, implement the template and inherit from it, as "class MyModel : public Markov::Model<char>".
      -
      35  * For a complete demonstration of how to extend the class, see MarkovPasswords.
      -
      36  *
      -
      37  * Whole model can be defined as a list of the edges, as dangling nodes are pointless. This approach is used for the import/export operations.
      -
      38  * For more information on importing/exporting model, check out the github readme and wiki page.
      -
      39  *
      -
      40  */
      -
      41  class Model {
      -
      42  public:
      -
      43 
      -
      44  /** @brief Initialize a model with only start and end nodes.
      -
      45  *
      -
      46  * Initialize an empty model with only a starterNode
      -
      47  * Starter node is a special kind of node that has constant 0x00 value, and will be used to initiate the generation execution from.
      -
      48  */
      -
      49  Model<NodeStorageType>();
      -
      50 
      -
      51  /** @brief Do a random walk on this model.
      -
      52  *
      -
      53  * Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached.
      -
      54  * If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext
      -
      55  *
      -
      56  * If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node.
      -
      57  * This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from
      -
      58  *
      -
      59  * This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases
      -
      60  * don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.
      -
      61  *
      -
      62  * This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.
      -
      63  *
      -
      64  * @b Example @b Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia
      -
      65  * @code{.cpp}
      -
      66  * Markov::Model<char> model;
      -
      67  * Model.import("model.mdl");
      -
      68  * char* res = new char[11];
      -
      69  * Markov::Random::Marsaglia MarsagliaRandomEngine;
      -
      70  * for (int i = 0; i < 10; i++) {
      -
      71  * this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
      -
      72  * std::cout << res << "\n";
      -
      73  * }
      -
      74  * @endcode
      -
      75  *
      -
      76  * @param randomEngine Random Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia
      -
      77  * @param minSetting Minimum number of characters to generate
      -
      78  * @param maxSetting Maximum number of character to generate
      -
      79  * @param buffer buffer to write the result to
      -
      80  * @return Null terminated string that was generated.
      -
      81  */
      -
      82  NodeStorageType* RandomWalk(Markov::Random::RandomEngine* randomEngine, int minSetting, int maxSetting, NodeStorageType* buffer);
      -
      83 
      -
      84  /** @brief Adjust the model with a single string.
      -
      85  *
      -
      86  * Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.
      -
      87  *
      -
      88  * Then, update the edge EdgeWeight from current node, to the terminator node.
      +Go to the documentation of this file.
      1 /** @file model.h
      +
      2  * @brief Model class template
      +
      3  * @authors Ata Hakçıl, Osman Ömer Yıldıztugay
      +
      4  *
      +
      5  * @copydoc Markov::Model
      +
      6  */
      +
      7 
      +
      8 
      +
      9 
      +
      10 #pragma once
      +
      11 #include <map>
      +
      12 #include <vector>
      +
      13 #include <fstream>
      +
      14 #include <assert.h>
      +
      15 #include <string>
      +
      16 #include <algorithm>
      +
      17 #include "node.h"
      +
      18 #include "edge.h"
      +
      19 
      +
      20 /**
      +
      21  @brief Namespace for the markov-model related classes.
      +
      22  Contains Model, Node and Edge classes
      +
      23 */
      +
      24 namespace Markov {
      +
      25 
      +
      26  template <typename NodeStorageType>
      +
      27  class Node;
      +
      28 
      +
      29  template <typename NodeStorageType>
      +
      30  class Edge;
      +
      31 
      +
      32  template <typename NodeStorageType>
      +
      33 
      +
      34  /** @brief class for the final Markov Model, constructed from nodes and edges.
      +
      35  *
      +
      36  * Each atomic piece of the generation result is stored in a node, while edges contain the relation weights.
      +
      37  * *Extending:*
      +
      38  * To extend the class, implement the template and inherit from it, as "class MyModel : public Markov::Model<char>".
      +
      39  * For a complete demonstration of how to extend the class, see MarkovPasswords.
      +
      40  *
      +
      41  * Whole model can be defined as a list of the edges, as dangling nodes are pointless. This approach is used for the import/export operations.
      +
      42  * For more information on importing/exporting model, check out the github readme and wiki page.
      +
      43  *
      +
      44  */
      +
      45  class Model {
      +
      46  public:
      +
      47 
      +
      48  /** @brief Initialize a model with only start and end nodes.
      +
      49  *
      +
      50  * Initialize an empty model with only a starterNode
      +
      51  * Starter node is a special kind of node that has constant 0x00 value, and will be used to initiate the generation execution from.
      +
      52  */
      +
      53  Model<NodeStorageType>();
      +
      54 
      +
      55  /** @brief Do a random walk on this model.
      +
      56  *
      +
      57  * Start from the starter node, on each node, invoke RandomNext using the random engine on current node, until terminator node is reached.
      +
      58  * If terminator node is reached before minimum length criateria is reached, ignore the last selection and re-invoke randomNext
      +
      59  *
      +
      60  * If maximum length criteria is reached but final node is not, cut off the generation and proceed to the final node.
      +
      61  * This function takes Markov::Random::RandomEngine as a parameter to generate pseudo random numbers from
      +
      62  *
      +
      63  * This library is shipped with two random engines, Marsaglia and Mersenne. While mersenne output is higher in entropy, most use cases
      +
      64  * don't really need super high entropy output, so Markov::Random::Marsaglia is preferable for better performance.
      +
      65  *
      +
      66  * This function WILL NOT reallocate buffer. Make sure no out of bound writes are happening via maximum length criteria.
      +
      67  *
      +
      68  * @b Example @b Use: Generate 10 lines, with 5 to 10 characters, and print the output. Use Marsaglia
      +
      69  * @code{.cpp}
      +
      70  * Markov::Model<char> model;
      +
      71  * Model.import("model.mdl");
      +
      72  * char* res = new char[11];
      +
      73  * Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      74  * for (int i = 0; i < 10; i++) {
      +
      75  * this->RandomWalk(&MarsagliaRandomEngine, 5, 10, res);
      +
      76  * std::cout << res << "\n";
      +
      77  * }
      +
      78  * @endcode
      +
      79  *
      +
      80  * @param randomEngine Random Engine to use for the random walks. For examples, see Markov::Random::Mersenne and Markov::Random::Marsaglia
      +
      81  * @param minSetting Minimum number of characters to generate
      +
      82  * @param maxSetting Maximum number of character to generate
      +
      83  * @param buffer buffer to write the result to
      +
      84  * @return Null terminated string that was generated.
      +
      85  */
      +
      86  NodeStorageType* RandomWalk(Markov::Random::RandomEngine* randomEngine, int minSetting, int maxSetting, NodeStorageType* buffer);
      +
      87 
      +
      88  /** @brief Adjust the model with a single string.
      89  *
      -
      90  * This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.
      +
      90  * Start from the starter node, and for each character, AdjustEdge the edge EdgeWeight from current node to the next, until NULL character is reached.
      91  *
      -
      92  * @b Example @b Use: Create an empty model and train it with string: "testdata"
      -
      93  * @code{.cpp}
      -
      94  * Markov::Model<char> model;
      -
      95  * char test[] = "testdata";
      -
      96  * model.AdjustEdge(test, 15);
      -
      97  * @endcode
      -
      98  *
      -
      99  *
      -
      100  * @param string - String that is passed from the training, and will be used to AdjustEdge the model with
      -
      101  * @param occurrence - Occurrence of this string.
      +
      92  * Then, update the edge EdgeWeight from current node, to the terminator node.
      +
      93  *
      +
      94  * This function is used for training purposes, as it can be used for adjusting the model with each line of the corpus file.
      +
      95  *
      +
      96  * @b Example @b Use: Create an empty model and train it with string: "testdata"
      +
      97  * @code{.cpp}
      +
      98  * Markov::Model<char> model;
      +
      99  * char test[] = "testdata";
      +
      100  * model.AdjustEdge(test, 15);
      +
      101  * @endcode
      102  *
      103  *
      -
      104  */
      -
      105  void AdjustEdge(const NodeStorageType* payload, long int occurrence);
      -
      106 
      -
      107  /** @brief Import a file to construct the model.
      -
      108  *
      -
      109  * File contains a list of edges. For more info on the file format, check out the wiki and github readme pages.
      -
      110  * Format is: Left_repr;EdgeWeight;right_repr
      -
      111  *
      -
      112  * Iterate over this list, and construct nodes and edges accordingly.
      -
      113  * @return True if successful, False for incomplete models or corrupt file formats
      -
      114  *
      -
      115  * @b Example @b Use: Import a file from ifstream
      -
      116  * @code{.cpp}
      -
      117  * Markov::Model<char> model;
      -
      118  * std::ifstream file("test.mdl");
      -
      119  * model.Import(&file);
      -
      120  * @endcode
      -
      121  */
      -
      122  bool Import(std::ifstream*);
      -
      123 
      -
      124  /** @brief Open a file to import with filename, and call bool Model::Import with std::ifstream
      -
      125  * @return True if successful, False for incomplete models or corrupt file formats
      -
      126  *
      -
      127  * @b Example @b Use: Import a file with filename
      -
      128  * @code{.cpp}
      -
      129  * Markov::Model<char> model;
      -
      130  * model.Import("test.mdl");
      -
      131  * @endcode
      -
      132  */
      -
      133  bool Import(const char* filename);
      -
      134 
      -
      135  /** @brief Export a file of the model.
      -
      136  *
      -
      137  * File contains a list of edges.
      -
      138  * Format is: Left_repr;EdgeWeight;right_repr.
      -
      139  * For more information on the format, check out the project wiki or github readme.
      -
      140  *
      -
      141  * Iterate over this vertices, and their edges, and write them to file.
      -
      142  * @return True if successful, False for incomplete models.
      -
      143  *
      -
      144  * @b Example @b Use: Export file to ofstream
      -
      145  * @code{.cpp}
      -
      146  * Markov::Model<char> model;
      -
      147  * std::ofstream file("test.mdl");
      -
      148  * model.Export(&file);
      -
      149  * @endcode
      -
      150  */
      -
      151  bool Export(std::ofstream*);
      -
      152 
      -
      153  /** @brief Open a file to export with filename, and call bool Model::Export with std::ofstream
      -
      154  * @return True if successful, False for incomplete models or corrupt file formats
      -
      155  *
      -
      156  * @b Example @b Use: Export file to filename
      -
      157  * @code{.cpp}
      -
      158  * Markov::Model<char> model;
      -
      159  * model.Export("test.mdl");
      -
      160  * @endcode
      -
      161  */
      -
      162  bool Export(const char* filename);
      -
      163 
      -
      164  /** @brief Return starter Node
      -
      165  * @return starter node with 00 NodeValue
      -
      166  */
      -
      167  Node<NodeStorageType>* StarterNode(){ return starterNode;}
      -
      168 
      -
      169  /** @brief Return a vector of all the edges in the model
      -
      170  * @return vector of edges
      -
      171  */
      -
      172  std::vector<Edge<NodeStorageType>*>* Edges(){ return &edges;}
      -
      173 
      -
      174  /** @brief Return starter Node
      -
      175  * @return starter node with 00 NodeValue
      -
      176  */
      -
      177  std::map<NodeStorageType, Node<NodeStorageType>*>* Nodes(){ return &nodes;}
      -
      178 
      -
      179  private:
      -
      180  /**
      -
      181  @brief Map LeftNode is the Nodes NodeValue
      -
      182  * Map RightNode is the node pointer
      -
      183  */
      -
      184  std::map<NodeStorageType, Node<NodeStorageType>*> nodes;
      -
      185 
      -
      186  /**
      -
      187  @brief Starter Node of this model.
      -
      188  */
      -
      189  Node<NodeStorageType>* starterNode;
      -
      190 
      -
      191 
      -
      192  /**
      -
      193  @brief A list of all edges in this model.
      -
      194  */
      -
      195  std::vector<Edge<NodeStorageType>*> edges;
      -
      196  };
      -
      197 
      -
      198 };
      +
      104  * @param string - String that is passed from the training, and will be used to AdjustEdge the model with
      +
      105  * @param occurrence - Occurrence of this string.
      +
      106  *
      +
      107  *
      +
      108  */
      +
      109  void AdjustEdge(const NodeStorageType* payload, long int occurrence);
      +
      110 
      +
      111  /** @brief Import a file to construct the model.
      +
      112  *
      +
      113  * File contains a list of edges. For more info on the file format, check out the wiki and github readme pages.
      +
      114  * Format is: Left_repr;EdgeWeight;right_repr
      +
      115  *
      +
      116  * Iterate over this list, and construct nodes and edges accordingly.
      +
      117  * @return True if successful, False for incomplete models or corrupt file formats
      +
      118  *
      +
      119  * @b Example @b Use: Import a file from ifstream
      +
      120  * @code{.cpp}
      +
      121  * Markov::Model<char> model;
      +
      122  * std::ifstream file("test.mdl");
      +
      123  * model.Import(&file);
      +
      124  * @endcode
      +
      125  */
      +
      126  bool Import(std::ifstream*);
      +
      127 
      +
      128  /** @brief Open a file to import with filename, and call bool Model::Import with std::ifstream
      +
      129  * @return True if successful, False for incomplete models or corrupt file formats
      +
      130  *
      +
      131  * @b Example @b Use: Import a file with filename
      +
      132  * @code{.cpp}
      +
      133  * Markov::Model<char> model;
      +
      134  * model.Import("test.mdl");
      +
      135  * @endcode
      +
      136  */
      +
      137  bool Import(const char* filename);
      +
      138 
      +
      139  /** @brief Export a file of the model.
      +
      140  *
      +
      141  * File contains a list of edges.
      +
      142  * Format is: Left_repr;EdgeWeight;right_repr.
      +
      143  * For more information on the format, check out the project wiki or github readme.
      +
      144  *
      +
      145  * Iterate over this vertices, and their edges, and write them to file.
      +
      146  * @return True if successful, False for incomplete models.
      +
      147  *
      +
      148  * @b Example @b Use: Export file to ofstream
      +
      149  * @code{.cpp}
      +
      150  * Markov::Model<char> model;
      +
      151  * std::ofstream file("test.mdl");
      +
      152  * model.Export(&file);
      +
      153  * @endcode
      +
      154  */
      +
      155  bool Export(std::ofstream*);
      +
      156 
      +
      157  /** @brief Open a file to export with filename, and call bool Model::Export with std::ofstream
      +
      158  * @return True if successful, False for incomplete models or corrupt file formats
      +
      159  *
      +
      160  * @b Example @b Use: Export file to filename
      +
      161  * @code{.cpp}
      +
      162  * Markov::Model<char> model;
      +
      163  * model.Export("test.mdl");
      +
      164  * @endcode
      +
      165  */
      +
      166  bool Export(const char* filename);
      +
      167 
      +
      168  /** @brief Return starter Node
      +
      169  * @return starter node with 00 NodeValue
      +
      170  */
      +
      171  Node<NodeStorageType>* StarterNode(){ return starterNode;}
      +
      172 
      +
      173  /** @brief Return a vector of all the edges in the model
      +
      174  * @return vector of edges
      +
      175  */
      +
      176  std::vector<Edge<NodeStorageType>*>* Edges(){ return &edges;}
      +
      177 
      +
      178  /** @brief Return starter Node
      +
      179  * @return starter node with 00 NodeValue
      +
      180  */
      +
      181  std::map<NodeStorageType, Node<NodeStorageType>*>* Nodes(){ return &nodes;}
      +
      182 
      +
      183  /** @brief Sort edges of all nodes in the model ordered by edge weights
      +
      184  *
      +
      185  */
      +
      186  void OptimizeEdgeOrder();
      +
      187 
      +
      188  private:
      +
      189  /**
      +
      190  @brief Map LeftNode is the Nodes NodeValue
      +
      191  * Map RightNode is the node pointer
      +
      192  */
      +
      193  std::map<NodeStorageType, Node<NodeStorageType>*> nodes;
      +
      194 
      +
      195  /**
      +
      196  @brief Starter Node of this model.
      +
      197  */
      +
      198  Node<NodeStorageType>* starterNode;
      199 
      -
      200 template <typename NodeStorageType>
      -
      201 Markov::Model<NodeStorageType>::Model() {
      -
      202  this->starterNode = new Markov::Node<NodeStorageType>(0);
      -
      203  this->nodes.insert({ 0, this->starterNode });
      -
      204 }
      -
      205 
      -
      206 template <typename NodeStorageType>
      -
      207 bool Markov::Model<NodeStorageType>::Import(std::ifstream* f) {
      -
      208  std::string cell;
      -
      209 
      -
      210  char src;
      -
      211  char target;
      -
      212  long int oc;
      -
      213 
      -
      214  while (std::getline(*f, cell)) {
      -
      215  //std::cout << "cell: " << cell << std::endl;
      -
      216  src = cell[0];
      -
      217  target = cell[cell.length() - 1];
      -
      218  char* j;
      -
      219  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
      -
      220  //std::cout << oc << "\n";
      -
      221  Markov::Node<NodeStorageType>* srcN;
      -
      222  Markov::Node<NodeStorageType>* targetN;
      -
      223  Markov::Edge<NodeStorageType>* e;
      -
      224  if (this->nodes.find(src) == this->nodes.end()) {
      -
      225  srcN = new Markov::Node<NodeStorageType>(src);
      -
      226  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
      -
      227  //std::cout << "Creating new node at start.\n";
      -
      228  }
      -
      229  else {
      -
      230  srcN = this->nodes.find(src)->second;
      -
      231  }
      -
      232 
      -
      233  if (this->nodes.find(target) == this->nodes.end()) {
      -
      234  targetN = new Markov::Node<NodeStorageType>(target);
      -
      235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
      -
      236  //std::cout << "Creating new node at end.\n";
      +
      200 
      +
      201  /**
      +
      202  @brief A list of all edges in this model.
      +
      203  */
      +
      204  std::vector<Edge<NodeStorageType>*> edges;
      +
      205  };
      +
      206 
      +
      207 };
      +
      208 
      +
      209 template <typename NodeStorageType>
      +
      210 Markov::Model<NodeStorageType>::Model() {
      +
      211  this->starterNode = new Markov::Node<NodeStorageType>(0);
      +
      212  this->nodes.insert({ 0, this->starterNode });
      +
      213 }
      +
      214 
      +
      215 template <typename NodeStorageType>
      +
      216 bool Markov::Model<NodeStorageType>::Import(std::ifstream* f) {
      +
      217  std::string cell;
      +
      218 
      +
      219  char src;
      +
      220  char target;
      +
      221  long int oc;
      +
      222 
      +
      223  while (std::getline(*f, cell)) {
      +
      224  //std::cout << "cell: " << cell << std::endl;
      +
      225  src = cell[0];
      +
      226  target = cell[cell.length() - 1];
      +
      227  char* j;
      +
      228  oc = std::strtol(cell.substr(2, cell.length() - 2).c_str(),&j,10);
      +
      229  //std::cout << oc << "\n";
      +
      230  Markov::Node<NodeStorageType>* srcN;
      +
      231  Markov::Node<NodeStorageType>* targetN;
      +
      232  Markov::Edge<NodeStorageType>* e;
      +
      233  if (this->nodes.find(src) == this->nodes.end()) {
      +
      234  srcN = new Markov::Node<NodeStorageType>(src);
      +
      235  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(src, srcN));
      +
      236  //std::cout << "Creating new node at start.\n";
      237  }
      238  else {
      -
      239  targetN = this->nodes.find(target)->second;
      +
      239  srcN = this->nodes.find(src)->second;
      240  }
      -
      241  e = srcN->Link(targetN);
      -
      242  e->AdjustEdge(oc);
      -
      243  this->edges.push_back(e);
      -
      244 
      -
      245  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
      -
      246 
      -
      247 
      -
      248  }
      -
      249 
      -
      250  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      -
      251  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      -
      252  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      -
      253  return lhs->EdgeWeight() > rhs->EdgeWeight();
      -
      254  });
      -
      255  //for(int i=0;i<x.second->edgesV.size();i++)
      -
      256  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      -
      257  //std::cout << "\n";
      -
      258  }
      -
      259  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      -
      260  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      -
      261 
      -
      262  return true;
      -
      263 }
      -
      264 
      -
      265 template <typename NodeStorageType>
      -
      266 bool Markov::Model<NodeStorageType>::Import(const char* filename) {
      -
      267  std::ifstream importfile;
      -
      268  importfile.open(filename);
      -
      269  return this->Import(&importfile);
      -
      270 
      -
      271 }
      -
      272 
      -
      273 template <typename NodeStorageType>
      -
      274 bool Markov::Model<NodeStorageType>::Export(std::ofstream* f) {
      -
      275  Markov::Edge<NodeStorageType>* e;
      -
      276  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
      -
      277  e = this->edges[i];
      -
      278  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      -
      279  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      -
      280  }
      -
      281 
      -
      282  return true;
      -
      283 }
      +
      241 
      +
      242  if (this->nodes.find(target) == this->nodes.end()) {
      +
      243  targetN = new Markov::Node<NodeStorageType>(target);
      +
      244  this->nodes.insert(std::pair<char, Markov::Node<NodeStorageType>*>(target, targetN));
      +
      245  //std::cout << "Creating new node at end.\n";
      +
      246  }
      +
      247  else {
      +
      248  targetN = this->nodes.find(target)->second;
      +
      249  }
      +
      250  e = srcN->Link(targetN);
      +
      251  e->AdjustEdge(oc);
      +
      252  this->edges.push_back(e);
      +
      253 
      +
      254  //std::cout << int(srcN->NodeValue()) << " --" << e->EdgeWeight() << "--> " << int(targetN->NodeValue()) << "\n";
      +
      255 
      +
      256 
      +
      257  }
      +
      258 
      +
      259  this->OptimizeEdgeOrder();
      +
      260 
      +
      261  return true;
      +
      262 }
      +
      263 
      +
      264 template <typename NodeStorageType>
      +
      265 void Markov::Model<NodeStorageType>::OptimizeEdgeOrder(){
      +
      266  for (std::pair<unsigned char, Markov::Node<NodeStorageType>*> const& x : this->nodes) {
      +
      267  //std::cout << "Total edges in EdgesV: " << x.second->edgesV.size() << "\n";
      +
      268  std::sort (x.second->edgesV.begin(), x.second->edgesV.end(), [](Edge<NodeStorageType> *lhs, Edge<NodeStorageType> *rhs)->bool{
      +
      269  return lhs->EdgeWeight() > rhs->EdgeWeight();
      +
      270  });
      +
      271  //for(int i=0;i<x.second->edgesV.size();i++)
      +
      272  // std::cout << x.second->edgesV[i]->EdgeWeight() << ", ";
      +
      273  //std::cout << "\n";
      +
      274  }
      +
      275  //std::cout << "Total number of nodes: " << this->nodes.size() << std::endl;
      +
      276  //std::cout << "Total number of edges: " << this->edges.size() << std::endl;
      +
      277 }
      +
      278 
      +
      279 template <typename NodeStorageType>
      +
      280 bool Markov::Model<NodeStorageType>::Import(const char* filename) {
      +
      281  std::ifstream importfile;
      +
      282  importfile.open(filename);
      +
      283  return this->Import(&importfile);
      284 
      -
      285 template <typename NodeStorageType>
      -
      286 bool Markov::Model<NodeStorageType>::Export(const char* filename) {
      -
      287  std::ofstream exportfile;
      -
      288  exportfile.open(filename);
      -
      289  return this->Export(&exportfile);
      -
      290 }
      -
      291 
      -
      292 template <typename NodeStorageType>
      -
      293 NodeStorageType* Markov::Model<NodeStorageType>::RandomWalk(Markov::Random::RandomEngine* randomEngine, int minSetting, int maxSetting, NodeStorageType* buffer) {
      -
      294  Markov::Node<NodeStorageType>* n = this->starterNode;
      -
      295  int len = 0;
      -
      296  Markov::Node<NodeStorageType>* temp_node;
      -
      297  while (true) {
      -
      298  temp_node = n->RandomNext(randomEngine);
      -
      299  if (len >= maxSetting) {
      -
      300  break;
      -
      301  }
      -
      302  else if ((temp_node == NULL) && (len < minSetting)) {
      -
      303  continue;
      -
      304  }
      +
      285 }
      +
      286 
      +
      287 template <typename NodeStorageType>
      +
      288 bool Markov::Model<NodeStorageType>::Export(std::ofstream* f) {
      +
      289  Markov::Edge<NodeStorageType>* e;
      +
      290  for (std::vector<int>::size_type i = 0; i != this->edges.size(); i++) {
      +
      291  e = this->edges[i];
      +
      292  //std::cout << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      +
      293  *f << e->LeftNode()->NodeValue() << "," << e->EdgeWeight() << "," << e->RightNode()->NodeValue() << "\n";
      +
      294  }
      +
      295 
      +
      296  return true;
      +
      297 }
      +
      298 
      +
      299 template <typename NodeStorageType>
      +
      300 bool Markov::Model<NodeStorageType>::Export(const char* filename) {
      +
      301  std::ofstream exportfile;
      +
      302  exportfile.open(filename);
      +
      303  return this->Export(&exportfile);
      +
      304 }
      305 
      -
      306  else if (temp_node == NULL){
      -
      307  break;
      -
      308  }
      -
      309 
      -
      310  n = temp_node;
      -
      311 
      -
      312  buffer[len++] = n->NodeValue();
      -
      313  }
      -
      314 
      -
      315  //null terminate the string
      -
      316  buffer[len] = 0x00;
      -
      317 
      -
      318  //do something with the generated string
      -
      319  return buffer; //for now
      -
      320 }
      -
      321 
      -
      322 template <typename NodeStorageType>
      -
      323 void Markov::Model<NodeStorageType>::AdjustEdge(const NodeStorageType* payload, long int occurrence) {
      -
      324  NodeStorageType p = payload[0];
      -
      325  Markov::Node<NodeStorageType>* curnode = this->starterNode;
      -
      326  Markov::Edge<NodeStorageType>* e;
      -
      327  int i = 0;
      +
      306 template <typename NodeStorageType>
      +
      307 NodeStorageType* Markov::Model<NodeStorageType>::RandomWalk(Markov::Random::RandomEngine* randomEngine, int minSetting, int maxSetting, NodeStorageType* buffer) {
      +
      308  Markov::Node<NodeStorageType>* n = this->starterNode;
      +
      309  int len = 0;
      +
      310  Markov::Node<NodeStorageType>* temp_node;
      +
      311  while (true) {
      +
      312  temp_node = n->RandomNext(randomEngine);
      +
      313  if (len >= maxSetting) {
      +
      314  break;
      +
      315  }
      +
      316  else if ((temp_node == NULL) && (len < minSetting)) {
      +
      317  continue;
      +
      318  }
      +
      319 
      +
      320  else if (temp_node == NULL){
      +
      321  break;
      +
      322  }
      +
      323 
      +
      324  n = temp_node;
      +
      325 
      +
      326  buffer[len++] = n->NodeValue();
      +
      327  }
      328 
      -
      329  if (p == 0) return;
      -
      330  while (p != 0) {
      -
      331  e = curnode->FindEdge(p);
      -
      332  if (e == NULL) return;
      -
      333  e->AdjustEdge(occurrence);
      -
      334  curnode = e->RightNode();
      -
      335  p = payload[++i];
      -
      336  }
      -
      337 
      -
      338  e = curnode->FindEdge('\xff');
      -
      339  e->AdjustEdge(occurrence);
      -
      340  return;
      -
      341 }
      +
      329  //null terminate the string
      +
      330  buffer[len] = 0x00;
      +
      331 
      +
      332  //do something with the generated string
      +
      333  return buffer; //for now
      +
      334 }
      +
      335 
      +
      336 template <typename NodeStorageType>
      +
      337 void Markov::Model<NodeStorageType>::AdjustEdge(const NodeStorageType* payload, long int occurrence) {
      +
      338  NodeStorageType p = payload[0];
      +
      339  Markov::Node<NodeStorageType>* curnode = this->starterNode;
      +
      340  Markov::Edge<NodeStorageType>* e;
      +
      341  int i = 0;
      +
      342 
      +
      343  if (p == 0) return;
      +
      344  while (p != 0) {
      +
      345  e = curnode->FindEdge(p);
      +
      346  if (e == NULL) return;
      +
      347  e->AdjustEdge(occurrence);
      +
      348  curnode = e->RightNode();
      +
      349  p = payload[++i];
      +
      350  }
      +
      351 
      +
      352  e = curnode->FindEdge('\xff');
      +
      353  e->AdjustEdge(occurrence);
      +
      354  return;
      +
      355 }
      -
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:323
      -
      std::map< NodeStorageType, Node< NodeStorageType > * > * Nodes()
      Return starter Node.
      Definition: model.h:177
      -
      Objects related to RNG.
      Definition: random.h:9
      -
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:207
      -
      An abstract class for Random Engine.
      Definition: random.h:21
      -
      bool Export(const char *filename)
      Open a file to export with filename, and call bool Model::Export with std::ofstream.
      Definition: model.h:286
      -
      NodeStorageType * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer)
      Do a random walk on this model.
      Definition: model.h:293
      -
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:274
      -
      Node< NodeStorageType > * StarterNode()
      Return starter Node.
      Definition: model.h:167
      -
      std::vector< Edge< NodeStorageType > * > edges
      A list of all edges in this model.
      Definition: model.h:195
      -
      bool Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: model.h:266
      -
      std::vector< Edge< NodeStorageType > * > * Edges()
      Return a vector of all the edges in the model.
      Definition: model.h:172
      -
      class for the final Markov Model, constructed from nodes and edges.
      Definition: model.h:41
      -
      std::map< NodeStorageType, Node< NodeStorageType > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:184
      -
      Node< NodeStorageType > * starterNode
      Starter Node of this model.
      Definition: model.h:189
      +
      void AdjustEdge(const NodeStorageType *payload, long int occurrence)
      Adjust the model with a single string.
      Definition: model.h:337
      +
      std::map< NodeStorageType, Node< NodeStorageType > * > * Nodes()
      Return starter Node.
      Definition: model.h:181
      +
      Objects related to RNG.
      Definition: random.h:18
      +
      bool Import(std::ifstream *)
      Import a file to construct the model.
      Definition: model.h:216
      +
      An abstract class for Random Engine.
      Definition: random.h:30
      +
      bool Export(const char *filename)
      Open a file to export with filename, and call bool Model::Export with std::ofstream.
      Definition: model.h:300
      +
      void OptimizeEdgeOrder()
      Sort edges of all nodes in the model ordered by edge weights.
      Definition: model.h:265
      +
      NodeStorageType * RandomWalk(Markov::Random::RandomEngine *randomEngine, int minSetting, int maxSetting, NodeStorageType *buffer)
      Do a random walk on this model.
      Definition: model.h:307
      +
      bool Export(std::ofstream *)
      Export a file of the model.
      Definition: model.h:288
      +
      Node< NodeStorageType > * StarterNode()
      Return starter Node.
      Definition: model.h:171
      +
      std::vector< Edge< NodeStorageType > * > edges
      A list of all edges in this model.
      Definition: model.h:204
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      bool Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: model.h:280
      +
      std::vector< Edge< NodeStorageType > * > * Edges()
      Return a vector of all the edges in the model.
      Definition: model.h:176
      +
      class for the final Markov Model, constructed from nodes and edges.
      Definition: model.h:45
      +
      std::map< NodeStorageType, Node< NodeStorageType > * > nodes
      Map LeftNode is the Nodes NodeValue Map RightNode is the node pointer.
      Definition: model.h:193
      +
      Node< NodeStorageType > * starterNode
      Starter Node of this model.
      Definition: model.h:198
      -Go to the documentation of this file.
      1 #include "modelMatrix.h"
      -
      2 #include <map>
      -
      3 #include <cstring>
      -
      4 #include <thread>
      -
      5 
      -
      6 Markov::API::ModelMatrix::ModelMatrix(){
      -
      7  this->ready = false;
      -
      8 }
      +Go to the documentation of this file.
      1 /** @file modelMatrix.cpp
      +
      2  * @brief An extension of Markov::API::MarkovPasswords
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * This class shows superior performance compared to the traditional model at Markov::API::MarkovPasswords
      +
      6  *
      +
      7  * @copydoc Markov::API::ModelMatrix
      +
      8  */
      9 
      -
      10 void Markov::API::ModelMatrix::Import(const char *filename){
      - -
      12  this->Markov::API::MarkovPasswords::Import(filename);
      - -
      14 }
      -
      15 
      -
      16 void Markov::API::ModelMatrix::Train(const char *datasetFileName, char delimiter, int threads){
      - -
      18  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
      - -
      20 }
      -
      21 
      -
      22 bool Markov::API::ModelMatrix::ConstructMatrix(){
      -
      23  if(this->ready) return false;
      -
      24  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
      -
      25 
      -
      26  this->matrixIndex = new char[this->matrixSize];
      -
      27  this->totalEdgeWeights = new long int[this->matrixSize];
      -
      28 
      -
      29  this->edgeMatrix = new char*[this->matrixSize];
      -
      30  for(int i=0;i<this->matrixSize;i++){
      -
      31  this->edgeMatrix[i] = new char[this->matrixSize];
      -
      32  }
      -
      33  this->valueMatrix = new long int*[this->matrixSize];
      -
      34  for(int i=0;i<this->matrixSize;i++){
      -
      35  this->valueMatrix[i] = new long int[this->matrixSize];
      -
      36  }
      -
      37  std::map< char, Node< char > * > *nodes;
      -
      38  nodes = this->Nodes();
      -
      39  int i=0;
      -
      40  for (auto const& [repr, node] : *nodes){
      -
      41  if(repr!=0) this->matrixIndex[i] = repr;
      -
      42  else this->matrixIndex[i] = 199;
      - -
      44  for(int j=0;j<this->matrixSize;j++){
      -
      45  char val = node->NodeValue();
      -
      46  if(val < 0){
      -
      47  for(int k=0;k<this->matrixSize;k++){
      -
      48  this->valueMatrix[i][k] = 0;
      -
      49  this->edgeMatrix[i][k] = 255;
      -
      50  }
      -
      51  break;
      -
      52  }
      -
      53  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
      -
      54  this->valueMatrix[i][j] = 0;
      -
      55  this->edgeMatrix[i][j] = 255;
      -
      56  }else if(j==(this->matrixSize-1)) {
      -
      57  this->valueMatrix[i][j] = 0;
      -
      58  this->edgeMatrix[i][j] = 255;
      -
      59  }else{
      -
      60  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
      -
      61  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
      -
      62  }
      -
      63 
      -
      64  }
      -
      65  i++;
      -
      66  }
      -
      67  this->ready = true;
      -
      68  return true;
      -
      69  //this->DumpJSON();
      -
      70 }
      -
      71 
      -
      72 bool Markov::API::ModelMatrix::DeallocateMatrix(){
      -
      73  if(!this->ready) return false;
      -
      74  delete[] this->matrixIndex;
      -
      75  delete[] this->totalEdgeWeights;
      -
      76 
      -
      77  for(int i=0;i<this->matrixSize;i++){
      -
      78  delete[] this->edgeMatrix[i];
      -
      79  }
      -
      80  delete[] this->edgeMatrix;
      -
      81 
      -
      82  for(int i=0;i<this->matrixSize;i++){
      -
      83  delete[] this->valueMatrix[i];
      -
      84  }
      -
      85  delete[] this->valueMatrix;
      -
      86 
      -
      87  this->matrixSize = -1;
      -
      88  this->ready = false;
      -
      89  return true;
      -
      90 }
      -
      91 
      -
      92 void Markov::API::ModelMatrix::DumpJSON(){
      -
      93 
      -
      94  std::cout << "{\n \"index\": \"";
      -
      95  for(int i=0;i<this->matrixSize;i++){
      -
      96  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
      -
      97  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
      -
      98  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
      -
      99  else if(i==0) std::cout << "\\\\xff";
      -
      100  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
      -
      101  else std::cout << this->matrixIndex[i];
      -
      102  }
      -
      103  std::cout <<
      -
      104  "\",\n"
      -
      105  " \"edgemap\": {\n";
      -
      106 
      -
      107  for(int i=0;i<this->matrixSize;i++){
      -
      108  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      -
      109  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      -
      110  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      -
      111  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      -
      112  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      -
      113  for(int j=0;j<this->matrixSize;j++){
      -
      114  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
      -
      115  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
      -
      116  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
      -
      117  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
      -
      118  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
      -
      119  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
      -
      120  if(j!=this->matrixSize-1) std::cout << ", ";
      -
      121  }
      -
      122  std::cout << "],\n";
      -
      123  }
      -
      124  std::cout << "},\n";
      -
      125 
      -
      126  std::cout << "\" weightmap\": {\n";
      -
      127  for(int i=0;i<this->matrixSize;i++){
      -
      128  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      -
      129  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      -
      130  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      -
      131  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      -
      132  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      -
      133 
      -
      134  for(int j=0;j<this->matrixSize;j++){
      -
      135  std::cout << this->valueMatrix[i][j];
      -
      136  if(j!=this->matrixSize-1) std::cout << ", ";
      -
      137  }
      -
      138  std::cout << "],\n";
      -
      139  }
      -
      140  std::cout << " }\n}\n";
      -
      141 }
      +
      10 #include "modelMatrix.h"
      +
      11 #include <map>
      +
      12 #include <cstring>
      +
      13 #include <thread>
      +
      14 
      + +
      16  this->ready = false;
      +
      17 }
      +
      18 
      +
      19 void Markov::API::ModelMatrix::Import(const char *filename){
      + + + +
      23 }
      +
      24 
      +
      25 void Markov::API::ModelMatrix::Train(const char *datasetFileName, char delimiter, int threads){
      + +
      27  this->Markov::API::MarkovPasswords::Train(datasetFileName,delimiter,threads);
      + +
      29 }
      +
      30 
      + +
      32  if(this->ready) return false;
      +
      33  this->matrixSize = this->StarterNode()->edgesV.size() + 2;
      +
      34 
      +
      35  this->matrixIndex = new char[this->matrixSize];
      +
      36  this->totalEdgeWeights = new long int[this->matrixSize];
      +
      37 
      +
      38  this->edgeMatrix = new char*[this->matrixSize];
      +
      39  for(int i=0;i<this->matrixSize;i++){
      +
      40  this->edgeMatrix[i] = new char[this->matrixSize];
      +
      41  }
      +
      42  this->valueMatrix = new long int*[this->matrixSize];
      +
      43  for(int i=0;i<this->matrixSize;i++){
      +
      44  this->valueMatrix[i] = new long int[this->matrixSize];
      +
      45  }
      +
      46  std::map< char, Node< char > * > *nodes;
      +
      47  nodes = this->Nodes();
      +
      48  int i=0;
      +
      49  for (auto const& [repr, node] : *nodes){
      +
      50  if(repr!=0) this->matrixIndex[i] = repr;
      +
      51  else this->matrixIndex[i] = 199;
      + +
      53  for(int j=0;j<this->matrixSize;j++){
      +
      54  char val = node->NodeValue();
      +
      55  if(val < 0){
      +
      56  for(int k=0;k<this->matrixSize;k++){
      +
      57  this->valueMatrix[i][k] = 0;
      +
      58  this->edgeMatrix[i][k] = 255;
      +
      59  }
      +
      60  break;
      +
      61  }
      +
      62  else if(node->NodeValue() == 0 && j>(this->matrixSize-3)){
      +
      63  this->valueMatrix[i][j] = 0;
      +
      64  this->edgeMatrix[i][j] = 255;
      +
      65  }else if(j==(this->matrixSize-1)) {
      +
      66  this->valueMatrix[i][j] = 0;
      +
      67  this->edgeMatrix[i][j] = 255;
      +
      68  }else{
      +
      69  this->valueMatrix[i][j] = node->edgesV[j]->EdgeWeight();
      +
      70  this->edgeMatrix[i][j] = node->edgesV[j]->RightNode()->NodeValue();
      +
      71  }
      +
      72 
      +
      73  }
      +
      74  i++;
      +
      75  }
      +
      76  this->ready = true;
      +
      77  return true;
      +
      78  //this->DumpJSON();
      +
      79 }
      +
      80 
      + +
      82  if(!this->ready) return false;
      +
      83  delete[] this->matrixIndex;
      +
      84  delete[] this->totalEdgeWeights;
      +
      85 
      +
      86  for(int i=0;i<this->matrixSize;i++){
      +
      87  delete[] this->edgeMatrix[i];
      +
      88  }
      +
      89  delete[] this->edgeMatrix;
      +
      90 
      +
      91  for(int i=0;i<this->matrixSize;i++){
      +
      92  delete[] this->valueMatrix[i];
      +
      93  }
      +
      94  delete[] this->valueMatrix;
      +
      95 
      +
      96  this->matrixSize = -1;
      +
      97  this->ready = false;
      +
      98  return true;
      +
      99 }
      +
      100 
      + +
      102 
      +
      103  std::cout << "{\n \"index\": \"";
      +
      104  for(int i=0;i<this->matrixSize;i++){
      +
      105  if(this->matrixIndex[i]=='"') std::cout << "\\\"";
      +
      106  else if(this->matrixIndex[i]=='\\') std::cout << "\\\\";
      +
      107  else if(this->matrixIndex[i]==0) std::cout << "\\\\x00";
      +
      108  else if(i==0) std::cout << "\\\\xff";
      +
      109  else if(this->matrixIndex[i]=='\n') std::cout << "\\n";
      +
      110  else std::cout << this->matrixIndex[i];
      +
      111  }
      +
      112  std::cout <<
      +
      113  "\",\n"
      +
      114  " \"edgemap\": {\n";
      +
      115 
      +
      116  for(int i=0;i<this->matrixSize;i++){
      +
      117  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      +
      118  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      +
      119  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      +
      120  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      +
      121  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      +
      122  for(int j=0;j<this->matrixSize;j++){
      +
      123  if(this->edgeMatrix[i][j]=='"') std::cout << "\"\\\"\"";
      +
      124  else if(this->edgeMatrix[i][j]=='\\') std::cout << "\"\\\\\"";
      +
      125  else if(this->edgeMatrix[i][j]==0) std::cout << "\"\\\\x00\"";
      +
      126  else if(this->edgeMatrix[i][j]<0) std::cout << "\"\\\\xff\"";
      +
      127  else if(this->matrixIndex[i]=='\n') std::cout << "\"\\n\"";
      +
      128  else std::cout << "\"" << this->edgeMatrix[i][j] << "\"";
      +
      129  if(j!=this->matrixSize-1) std::cout << ", ";
      +
      130  }
      +
      131  std::cout << "],\n";
      +
      132  }
      +
      133  std::cout << "},\n";
      +
      134 
      +
      135  std::cout << "\" weightmap\": {\n";
      +
      136  for(int i=0;i<this->matrixSize;i++){
      +
      137  if(this->matrixIndex[i]=='"') std::cout << " \"\\\"\": [";
      +
      138  else if(this->matrixIndex[i]=='\\') std::cout << " \"\\\\\": [";
      +
      139  else if(this->matrixIndex[i]==0) std::cout << " \"\\\\x00\": [";
      +
      140  else if(this->matrixIndex[i]<0) std::cout << " \"\\\\xff\": [";
      +
      141  else std::cout << " \"" << this->matrixIndex[i] << "\": [";
      142 
      -
      143 
      -
      144 void Markov::API::ModelMatrix::FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO){
      -
      145  if(n==0) return;
      -
      146 
      -
      147  Markov::Random::Marsaglia MarsagliaRandomEngine;
      -
      148  char* e;
      -
      149  char *res = new char[maxLen*n];
      -
      150  int index = 0;
      -
      151  char next;
      -
      152  int len=0;
      -
      153  long int selection;
      -
      154  char cur;
      -
      155  long int bufferctr = 0;
      -
      156  for (int i = 0; i < n; i++) {
      -
      157  cur=199;
      -
      158  len=0;
      -
      159  while (true) {
      -
      160  e = strchr(this->matrixIndex, cur);
      -
      161  index = e - this->matrixIndex;
      -
      162  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
      -
      163  for(int j=0;j<this->matrixSize;j++){
      -
      164  selection -= this->valueMatrix[index][j];
      -
      165  if (selection < 0){
      -
      166  next = this->edgeMatrix[index][j];
      -
      167  break;
      -
      168  }
      -
      169  }
      -
      170 
      -
      171  if (len >= maxLen) break;
      -
      172  else if ((next < 0) && (len < minLen)) continue;
      -
      173  else if (next < 0) break;
      -
      174  cur = next;
      -
      175  res[bufferctr + len++] = cur;
      -
      176  }
      -
      177  res[bufferctr + len++] = '\n';
      -
      178  bufferctr+=len;
      +
      143  for(int j=0;j<this->matrixSize;j++){
      +
      144  std::cout << this->valueMatrix[i][j];
      +
      145  if(j!=this->matrixSize-1) std::cout << ", ";
      +
      146  }
      +
      147  std::cout << "],\n";
      +
      148  }
      +
      149  std::cout << " }\n}\n";
      +
      150 }
      +
      151 
      +
      152 
      +
      153 void Markov::API::ModelMatrix::FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO){
      +
      154  if(n==0) return;
      +
      155 
      +
      156  Markov::Random::Marsaglia MarsagliaRandomEngine;
      +
      157  char* e;
      +
      158  char *res = new char[(maxLen+2)*n];
      +
      159  int index = 0;
      +
      160  char next;
      +
      161  int len=0;
      +
      162  long int selection;
      +
      163  char cur;
      +
      164  long int bufferctr = 0;
      +
      165  for (int i = 0; i < n; i++) {
      +
      166  cur=199;
      +
      167  len=0;
      +
      168  while (true) {
      +
      169  e = strchr(this->matrixIndex, cur);
      +
      170  index = e - this->matrixIndex;
      +
      171  selection = MarsagliaRandomEngine.random() % this->totalEdgeWeights[index];
      +
      172  for(int j=0;j<this->matrixSize;j++){
      +
      173  selection -= this->valueMatrix[index][j];
      +
      174  if (selection < 0){
      +
      175  next = this->edgeMatrix[index][j];
      +
      176  break;
      +
      177  }
      +
      178  }
      179 
      -
      180  }
      -
      181  if(bFileIO){
      -
      182  mlock->lock();
      -
      183  *wordlist << res;
      -
      184  mlock->unlock();
      -
      185  }else{
      -
      186  mlock->lock();
      -
      187  std::cout << res;
      -
      188  mlock->unlock();
      +
      180  if (len >= maxLen) break;
      +
      181  else if ((next < 0) && (len < minLen)) continue;
      +
      182  else if (next < 0) break;
      +
      183  cur = next;
      +
      184  res[bufferctr + len++] = cur;
      +
      185  }
      +
      186  res[bufferctr + len++] = '\n';
      +
      187  bufferctr+=len;
      +
      188 
      189  }
      -
      190  delete res;
      -
      191 
      -
      192 }
      -
      193 
      -
      194 
      -
      195 void Markov::API::ModelMatrix::FastRandomWalk(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen, int threads, bool bFileIO){
      -
      196 
      -
      197 
      -
      198  std::ofstream wordlist;
      -
      199  if(bFileIO)
      -
      200  wordlist.open(wordlistFileName);
      -
      201 
      -
      202  std::mutex mlock;
      -
      203  if(n<=50000000ull) return this->FastRandomWalkPartition(&mlock, &wordlist, n, minLen, maxLen, bFileIO, threads);
      -
      204  else{
      -
      205  int numberOfPartitions = n/50000000ull;
      -
      206  for(int i=0;i<numberOfPartitions;i++)
      -
      207  this->FastRandomWalkPartition(&mlock, &wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
      -
      208  }
      -
      209 
      -
      210 
      -
      211 }
      -
      212 
      -
      213 
      -
      214 void Markov::API::ModelMatrix::FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads){
      -
      215 
      -
      216  int iterationsPerThread = n/threads;
      -
      217  int iterationsPerThreadCarryOver = n%threads;
      -
      218 
      -
      219  std::vector<std::thread*> threadsV;
      -
      220 
      -
      221  int id = 0;
      -
      222  for(int i=0;i<threads;i++){
      -
      223  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
      -
      224  id++;
      -
      225  }
      +
      190  if(bFileIO){
      +
      191  mlock->lock();
      +
      192  *wordlist << res;
      +
      193  mlock->unlock();
      +
      194  }else{
      +
      195  mlock->lock();
      +
      196  std::cout << res;
      +
      197  mlock->unlock();
      +
      198  }
      +
      199  delete res;
      +
      200 
      +
      201 }
      +
      202 
      +
      203 
      +
      204 int Markov::API::ModelMatrix::FastRandomWalk(unsigned long int n, std::ofstream *wordlist, int minLen, int maxLen, int threads, bool bFileIO){
      +
      205 
      +
      206 
      +
      207  std::mutex mlock;
      +
      208  if(n<=50000000ull) this->FastRandomWalkPartition(&mlock, wordlist, n, minLen, maxLen, bFileIO, threads);
      +
      209  else{
      +
      210  int numberOfPartitions = n/50000000ull;
      +
      211  for(int i=0;i<numberOfPartitions;i++)
      +
      212  this->FastRandomWalkPartition(&mlock, wordlist, 50000000ull, minLen, maxLen, bFileIO, threads);
      +
      213  }
      +
      214  return 0;
      +
      215 }
      +
      216 
      +
      217 int Markov::API::ModelMatrix::FastRandomWalk(unsigned long int n, const char* wordlistFileName, int minLen, int maxLen, int threads, bool bFileIO){
      +
      218  std::ofstream wordlist;
      +
      219  if(bFileIO)
      +
      220  wordlist.open(wordlistFileName);
      +
      221  this->FastRandomWalk(n, &wordlist, minLen, maxLen, threads, bFileIO);
      +
      222  return 0;
      +
      223 }
      +
      224 
      +
      225 void Markov::API::ModelMatrix::FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads){
      226 
      -
      227  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
      -
      228 
      -
      229  for(int i=0;i<threads;i++){
      -
      230  threadsV[i]->join();
      -
      231  }
      -
      232 }
      +
      227  int iterationsPerThread = n/threads;
      +
      228  int iterationsPerThreadCarryOver = n%threads;
      +
      229 
      +
      230  std::vector<std::thread*> threadsV;
      +
      231 
      +
      232  int id = 0;
      +
      233  for(int i=0;i<threads;i++){
      +
      234  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThread, minLen, maxLen, id, bFileIO));
      +
      235  id++;
      +
      236  }
      +
      237 
      +
      238  threadsV.push_back(new std::thread(&Markov::API::ModelMatrix::FastRandomWalkThread, this, mlock, wordlist, iterationsPerThreadCarryOver, minLen, maxLen, id, bFileIO));
      +
      239 
      +
      240  for(int i=0;i<threads;i++){
      +
      241  threadsV[i]->join();
      +
      242  }
      +
      243 }
      - -
      std::map< NodeStorageType, Node< NodeStorageType > * > * Nodes()
      Return starter Node.
      Definition: model.h:177
      -
      Objects related to RNG.
      Definition: random.h:9
      -
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:10
      -
      long int TotalEdgeWeights()
      return total edge weights
      Definition: node.h:269
      -
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:156
      -
      void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      -
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:13
      -
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:163
      -
      Markov::Model with char represented nodes.
      -
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:141
      -
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:153
      -
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:161
      -
      Node< NodeStorageType > * StarterNode()
      Return starter Node.
      Definition: model.h:167
      -
      unsigned long random()
      Generate Random Number.
      Definition: random.h:131
      -
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:146
      -
      void DumpJSON()
      Debug function to dump the model to a JSON file.
      Definition: modelMatrix.cpp:92
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      -
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:207
      -
      Implementation of Marsaglia Random Engine.
      Definition: random.h:116
      -
      bool Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: model.h:266
      -
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      -
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:72
      -
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:22
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      Definition: modelMatrix.cpp:16
      -
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      -
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:151
      -
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:136
      + +
      std::map< NodeStorageType, Node< NodeStorageType > * > * Nodes()
      Return starter Node.
      Definition: model.h:181
      +
      Objects related to RNG.
      Definition: random.h:18
      +
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:19
      +
      long int TotalEdgeWeights()
      return total edge weights
      Definition: node.h:277
      +
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:195
      +
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:23
      +
      int FastRandomWalk(unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      +
      Node< NodeStorageType > * RightNode()
      return edge's RightNode
      Definition: edge.h:170
      +
      Markov::Model with char represented nodes.
      +
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:180
      +
      uint64_t EdgeWeight()
      return edge's EdgeWeight.
      Definition: edge.h:160
      +
      Namespace for the MarkovPasswords API.
      +
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:200
      +
      Node< NodeStorageType > * StarterNode()
      Return starter Node.
      Definition: model.h:171
      +
      unsigned long random()
      Generate Random Number.
      Definition: random.h:140
      +
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:185
      +
      void DumpJSON()
      Debug function to dump the model to a JSON file.
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      +
      unsigned char NodeValue()
      Return character representation of this node.
      Definition: node.h:215
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      int FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      +
      Implementation of Marsaglia Random Engine.
      Definition: random.h:125
      +
      bool Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: model.h:280
      +
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      +
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:81
      +
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:31
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      Definition: modelMatrix.cpp:25
      +
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      +
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:190
      +
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:175
      + +

      An extension of Markov::API::MarkovPasswords. +More...

      #include "markovPasswords.h"
      #include <mutex>
      @@ -97,22 +100,22 @@
      - - + + - - + + - - + + - + @@ -123,11 +126,13 @@
      - - - - - + + + + + + +
      @@ -148,13 +153,21 @@  Namespace for the MarkovPasswords API.
        -
      +

      Detailed Description

      +

      An extension of Markov::API::MarkovPasswords.

      +
      Authors
      Ata Hakçıl
      +

      This class shows superior performance compared to the traditional model at Markov::API::MarkovPasswords

      +

      Class to flatten and reduce Markov::Model to a Matrix. Matrix level operations can be used for Generation events, with a significant performance optimization at the cost of O(N) memory complexity (O(1) memory space for slow mode)

      +

      To limit the maximum memory usage, each generation operation is partitioned into 50M chunks for allocation. Threads are sychronized and files are flushed every 50M operations.

      + +

      Definition in file modelMatrix.h.

      +
      -Go to the documentation of this file.
      1 #include "markovPasswords.h"
      -
      2 #include <mutex>
      -
      3 
      -
      4 namespace Markov::API{
      -
      5 
      -
      6  /** @brief Class to flatten and reduce Markov::Model to a Matrix
      -
      7  *
      -
      8  * Matrix level operations can be used for Generation events, with a significant performance optimization at the cost of O(N) memory complexity (O(1) memory space for slow mode)
      -
      9  *
      -
      10  * To limit the maximum memory usage, each generation operation is partitioned into 50M chunks for allocation. Threads are sychronized and files are flushed every 50M operations.
      -
      11  *
      -
      12  */
      -
      13  class ModelMatrix : public Markov::API::MarkovPasswords{
      -
      14  public:
      -
      15  ModelMatrix();
      -
      16 
      -
      17  /** @brief Construct the related Matrix data for the model.
      -
      18  *
      -
      19  * This operation can be used after importing/training to allocate and populate the matrix content.
      -
      20  *
      -
      21  * this will initialize:
      -
      22  * char** edgeMatrix -> a 2D array of mapping left and right connections of each edge.
      -
      23  * long int **valueMatrix -> a 2D array representing the edge weights.
      -
      24  * int matrixSize -> Size of the matrix, aka total number of nodes.
      -
      25  * char* matrixIndex -> order of nodes in the model
      -
      26  * long int *totalEdgeWeights -> total edge weights of each Node.
      -
      27  *
      -
      28  * @returns True if constructed. False if already construced.
      -
      29  */
      -
      30  bool ConstructMatrix();
      -
      31 
      -
      32 
      -
      33  /** @brief Debug function to dump the model to a JSON file.
      -
      34  *
      -
      35  * Might not work 100%. Not meant for production use.
      -
      36  */
      -
      37  void DumpJSON();
      -
      38 
      -
      39 
      -
      40  /** @brief Random walk on the Matrix-reduced Markov::Model
      -
      41  *
      -
      42  * This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.
      -
      43  *
      -
      44  * If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations.
      -
      45  * This comes at a minor performance penalty.
      -
      46  *
      -
      47  * While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5
      -
      48  *
      -
      49  * This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.
      -
      50  *
      -
      51  * @param n - Number of passwords to generate.
      -
      52  * @param wordlistFileName - Filename to write to
      -
      53  * @param minLen - Minimum password length to generate
      -
      54  * @param maxLen - Maximum password length to generate
      -
      55  * @param threads - number of OS threads to spawn
      -
      56  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      -
      57  *
      +Go to the documentation of this file.
      1 /** @file modelMatrix.h
      +
      2  * @brief An extension of Markov::API::MarkovPasswords
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * This class shows superior performance compared to the traditional model at Markov::API::MarkovPasswords
      +
      6  *
      +
      7  * @copydoc Markov::API::ModelMatrix
      +
      8  *
      +
      9  */
      +
      10 
      +
      11 #include "markovPasswords.h"
      +
      12 #include <mutex>
      +
      13 
      +
      14 namespace Markov::API{
      +
      15 
      +
      16  /** @brief Class to flatten and reduce Markov::Model to a Matrix
      +
      17  *
      +
      18  * Matrix level operations can be used for Generation events, with a significant performance optimization at the cost of O(N) memory complexity (O(1) memory space for slow mode)
      +
      19  *
      +
      20  * To limit the maximum memory usage, each generation operation is partitioned into 50M chunks for allocation. Threads are sychronized and files are flushed every 50M operations.
      +
      21  *
      +
      22  */
      + +
      24  public:
      +
      25  ModelMatrix();
      +
      26 
      +
      27  /** @brief Construct the related Matrix data for the model.
      +
      28  *
      +
      29  * This operation can be used after importing/training to allocate and populate the matrix content.
      +
      30  *
      +
      31  * this will initialize:
      +
      32  * char** edgeMatrix -> a 2D array of mapping left and right connections of each edge.
      +
      33  * long int **valueMatrix -> a 2D array representing the edge weights.
      +
      34  * int matrixSize -> Size of the matrix, aka total number of nodes.
      +
      35  * char* matrixIndex -> order of nodes in the model
      +
      36  * long int *totalEdgeWeights -> total edge weights of each Node.
      +
      37  *
      +
      38  * @returns True if constructed. False if already construced.
      +
      39  */
      +
      40  bool ConstructMatrix();
      +
      41 
      +
      42 
      +
      43  /** @brief Debug function to dump the model to a JSON file.
      +
      44  *
      +
      45  * Might not work 100%. Not meant for production use.
      +
      46  */
      +
      47  void DumpJSON();
      +
      48 
      +
      49 
      +
      50  /** @brief Random walk on the Matrix-reduced Markov::Model
      +
      51  *
      +
      52  * This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.
      +
      53  *
      +
      54  * If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations.
      +
      55  * This comes at a minor performance penalty.
      +
      56  *
      +
      57  * While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5
      58  *
      -
      59  * @code{.cpp}
      -
      60  * Markov::API::ModelMatrix mp;
      -
      61  * mp.Import("models/finished.mdl");
      -
      62  * mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      -
      63  * @endcode
      -
      64  *
      -
      65  */
      -
      66  void FastRandomWalk(unsigned long int n, const char* wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true);
      -
      67 
      -
      68  /** @copydoc Markov::Model::Import(const char *filename)
      -
      69  * Construct the matrix when done.
      -
      70  *
      -
      71  */
      -
      72  void Import(const char *filename);
      -
      73 
      -
      74  /** @copydoc Markov::API::MarkovPasswords::Train(const char *datasetFileName, char delimiter, int threads)
      -
      75  * Construct the matrix when done.
      -
      76  *
      -
      77  */
      -
      78  void Train(const char *datasetFileName, char delimiter, int threads);
      -
      79 
      -
      80  protected:
      -
      81 
      -
      82  /** @brief A single partition of FastRandomWalk event
      -
      83  *
      -
      84  * Since FastRandomWalk has to allocate its output buffer before operation starts and writes data in chunks,
      -
      85  * large n parameters would lead to huge memory allocations.
      -
      86  * @b Without @b Partitioning:
      -
      87  * - 50M results 12 characters max -> 550 Mb Memory allocation
      -
      88  *
      -
      89  * - 5B results 12 characters max -> 55 Gb Memory allocation
      -
      90  *
      -
      91  * - 50B results 12 characters max -> 550GB Memory allocation
      -
      92  *
      -
      93  * Instead, FastRandomWalk is partitioned per 50M generations to limit the top memory need.
      -
      94  *
      -
      95  * @param mlock - mutex lock to distribute to child threads
      -
      96  * @param wordlist - Reference to the wordlist file to write to
      -
      97  * @param n - Number of passwords to generate.
      -
      98  * @param wordlistFileName - Filename to write to
      -
      99  * @param minLen - Minimum password length to generate
      -
      100  * @param maxLen - Maximum password length to generate
      -
      101  * @param threads - number of OS threads to spawn
      -
      102  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      -
      103  *
      -
      104  *
      -
      105  */
      -
      106  void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads);
      -
      107 
      -
      108  /** @brief A single thread of a single partition of FastRandomWalk
      +
      59  * This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.
      +
      60  *
      +
      61  * @param n - Number of passwords to generate.
      +
      62  * @param wordlistFileName - Filename to write to
      +
      63  * @param minLen - Minimum password length to generate
      +
      64  * @param maxLen - Maximum password length to generate
      +
      65  * @param threads - number of OS threads to spawn
      +
      66  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      +
      67  *
      +
      68  *
      +
      69  * @code{.cpp}
      +
      70  * Markov::API::ModelMatrix mp;
      +
      71  * mp.Import("models/finished.mdl");
      +
      72  * mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      +
      73  * @endcode
      +
      74  *
      +
      75  */
      +
      76  int FastRandomWalk(unsigned long int n, const char* wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true);
      +
      77 
      +
      78  /** @copydoc Markov::Model::Import(const char *filename)
      +
      79  * Construct the matrix when done.
      +
      80  *
      +
      81  */
      +
      82  void Import(const char *filename);
      +
      83 
      +
      84  /** @copydoc Markov::API::MarkovPasswords::Train(const char *datasetFileName, char delimiter, int threads)
      +
      85  * Construct the matrix when done.
      +
      86  *
      +
      87  */
      +
      88  void Train(const char *datasetFileName, char delimiter, int threads);
      +
      89 
      +
      90  protected:
      +
      91 
      +
      92  /** @brief Random walk on the Matrix-reduced Markov::Model
      +
      93  *
      +
      94  * This has an O(N) Memory complexity. To limit the maximum usage, requests with n>50M are partitioned using Markov::API::ModelMatrix::FastRandomWalkPartition.
      +
      95  *
      +
      96  * If n>50M, threads are going to be synced, files are going to be flushed, and buffers will be reallocated every 50M generations.
      +
      97  * This comes at a minor performance penalty.
      +
      98  *
      +
      99  * While it has the same functionality, this operation reduces Markov::API::MarkovPasswords::Generate runtime by %96.5
      +
      100  *
      +
      101  * This function has deprecated Markov::API::MarkovPasswords::Generate, and will eventually replace it.
      +
      102  *
      +
      103  * @param n - Number of passwords to generate.
      +
      104  * @param wordlistFileName - Filename to write to
      +
      105  * @param minLen - Minimum password length to generate
      +
      106  * @param maxLen - Maximum password length to generate
      +
      107  * @param threads - number of OS threads to spawn
      +
      108  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      109  *
      -
      110  * A FastRandomWalkPartition will initiate as many of this function as requested.
      -
      111  *
      -
      112  * This function contains the bulk of the generation algorithm.
      -
      113  *
      -
      114  * @param mlock - mutex lock to distribute to child threads
      -
      115  * @param wordlist - Reference to the wordlist file to write to
      -
      116  * @param n - Number of passwords to generate.
      -
      117  * @param wordlistFileName - Filename to write to
      -
      118  * @param minLen - Minimum password length to generate
      -
      119  * @param maxLen - Maximum password length to generate
      -
      120  * @param id - @b DEPRECATED Thread id - No longer used
      -
      121  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      +
      110  *
      +
      111  * @code{.cpp}
      +
      112  * Markov::API::ModelMatrix mp;
      +
      113  * mp.Import("models/finished.mdl");
      +
      114  * mp.FastRandomWalk(50000000,"./wordlist.txt",6,12,25, true);
      +
      115  * @endcode
      +
      116  *
      +
      117  */
      +
      118  int FastRandomWalk(unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true);
      +
      119 
      +
      120 
      +
      121  /** @brief A single partition of FastRandomWalk event
      122  *
      -
      123  *
      -
      124  */
      -
      125  void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO);
      -
      126 
      -
      127  /** @brief Deallocate matrix and make it ready for re-construction
      -
      128  *
      -
      129  * @returns True if deallocated. False if matrix was not initialized
      -
      130  */
      -
      131  bool DeallocateMatrix();
      -
      132 
      -
      133  /**
      -
      134  @brief 2-D Character array for the edge Matrix (The characters of Nodes)
      -
      135  */
      -
      136  char** edgeMatrix;
      -
      137 
      -
      138  /**
      -
      139  @brief 2-d Integer array for the value Matrix (For the weights of Edges)
      -
      140  */
      -
      141  long int **valueMatrix;
      -
      142 
      -
      143  /**
      -
      144  @brief to hold Matrix size
      -
      145  */
      - -
      147 
      -
      148  /**
      -
      149  @brief to hold the Matrix index (To hold the orders of 2-D arrays')
      -
      150  */
      -
      151  char* matrixIndex;
      -
      152 
      -
      153  /**
      -
      154  @brief Array of the Total Edge Weights
      -
      155  */
      -
      156  long int *totalEdgeWeights;
      -
      157 
      -
      158  /**
      -
      159  @brief True when matrix is constructed. False if not.
      -
      160  */
      -
      161  bool ready;
      -
      162  };
      -
      163 
      -
      164 
      +
      123  * Since FastRandomWalk has to allocate its output buffer before operation starts and writes data in chunks,
      +
      124  * large n parameters would lead to huge memory allocations.
      +
      125  * @b Without @b Partitioning:
      +
      126  * - 50M results 12 characters max -> 550 Mb Memory allocation
      +
      127  *
      +
      128  * - 5B results 12 characters max -> 55 Gb Memory allocation
      +
      129  *
      +
      130  * - 50B results 12 characters max -> 550GB Memory allocation
      +
      131  *
      +
      132  * Instead, FastRandomWalk is partitioned per 50M generations to limit the top memory need.
      +
      133  *
      +
      134  * @param mlock - mutex lock to distribute to child threads
      +
      135  * @param wordlist - Reference to the wordlist file to write to
      +
      136  * @param n - Number of passwords to generate.
      +
      137  * @param wordlistFileName - Filename to write to
      +
      138  * @param minLen - Minimum password length to generate
      +
      139  * @param maxLen - Maximum password length to generate
      +
      140  * @param threads - number of OS threads to spawn
      +
      141  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      +
      142  *
      +
      143  *
      +
      144  */
      +
      145  void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads);
      +
      146 
      +
      147  /** @brief A single thread of a single partition of FastRandomWalk
      +
      148  *
      +
      149  * A FastRandomWalkPartition will initiate as many of this function as requested.
      +
      150  *
      +
      151  * This function contains the bulk of the generation algorithm.
      +
      152  *
      +
      153  * @param mlock - mutex lock to distribute to child threads
      +
      154  * @param wordlist - Reference to the wordlist file to write to
      +
      155  * @param n - Number of passwords to generate.
      +
      156  * @param wordlistFileName - Filename to write to
      +
      157  * @param minLen - Minimum password length to generate
      +
      158  * @param maxLen - Maximum password length to generate
      +
      159  * @param id - @b DEPRECATED Thread id - No longer used
      +
      160  * @param bFileIO - If false, filename will be ignored and will output to stdout.
      +
      161  *
      +
      162  *
      +
      163  */
      +
      164  void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO);
      165 
      -
      166 };
      +
      166  /** @brief Deallocate matrix and make it ready for re-construction
      +
      167  *
      +
      168  * @returns True if deallocated. False if matrix was not initialized
      +
      169  */
      +
      170  bool DeallocateMatrix();
      +
      171 
      +
      172  /**
      +
      173  @brief 2-D Character array for the edge Matrix (The characters of Nodes)
      +
      174  */
      +
      175  char** edgeMatrix;
      +
      176 
      +
      177  /**
      +
      178  @brief 2-d Integer array for the value Matrix (For the weights of Edges)
      +
      179  */
      +
      180  long int **valueMatrix;
      +
      181 
      +
      182  /**
      +
      183  @brief to hold Matrix size
      +
      184  */
      + +
      186 
      +
      187  /**
      +
      188  @brief to hold the Matrix index (To hold the orders of 2-D arrays')
      +
      189  */
      +
      190  char* matrixIndex;
      +
      191 
      +
      192  /**
      +
      193  @brief Array of the Total Edge Weights
      +
      194  */
      +
      195  long int *totalEdgeWeights;
      +
      196 
      +
      197  /**
      +
      198  @brief True when matrix is constructed. False if not.
      +
      199  */
      +
      200  bool ready;
      +
      201  };
      +
      202 
      +
      203 
      +
      204 
      +
      205 };
      - -
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:10
      -
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:156
      -
      void FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      -
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:13
      -
      Markov::Model with char represented nodes.
      -
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:141
      -
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:161
      -
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:146
      -
      void DumpJSON()
      Debug function to dump the model to a JSON file.
      Definition: modelMatrix.cpp:92
      -
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      -
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:72
      -
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:22
      -
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      Definition: modelMatrix.cpp:16
      -
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      -
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:151
      -
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:136
      + +
      void Import(const char *filename)
      Open a file to import with filename, and call bool Model::Import with std::ifstream.
      Definition: modelMatrix.cpp:19
      +
      long int * totalEdgeWeights
      Array of the Total Edge Weights.
      Definition: modelMatrix.h:195
      +
      Class to flatten and reduce Markov::Model to a Matrix.
      Definition: modelMatrix.h:23
      +
      int FastRandomWalk(unsigned long int n, std::ofstream *wordlist, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      +
      Markov::Model with char represented nodes.
      +
      long int ** valueMatrix
      2-d Integer array for the value Matrix (For the weights of Edges)
      Definition: modelMatrix.h:180
      +
      Namespace for the MarkovPasswords API.
      +
      bool ready
      True when matrix is constructed. False if not.
      Definition: modelMatrix.h:200
      +
      int matrixSize
      to hold Matrix size
      Definition: modelMatrix.h:185
      +
      void DumpJSON()
      Debug function to dump the model to a JSON file.
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      int FastRandomWalk(unsigned long int n, const char *wordlistFileName, int minLen=6, int maxLen=12, int threads=20, bool bFileIO=true)
      Random walk on the Matrix-reduced Markov::Model.
      +
      void FastRandomWalkThread(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, int id, bool bFileIO)
      A single thread of a single partition of FastRandomWalk.
      +
      bool DeallocateMatrix()
      Deallocate matrix and make it ready for re-construction.
      Definition: modelMatrix.cpp:81
      +
      bool ConstructMatrix()
      Construct the related Matrix data for the model.
      Definition: modelMatrix.cpp:31
      +
      void Train(const char *datasetFileName, char delimiter, int threads)
      Train the model with the dataset file.
      Definition: modelMatrix.cpp:25
      +
      void FastRandomWalkPartition(std::mutex *mlock, std::ofstream *wordlist, unsigned long int n, int minLen, int maxLen, bool bFileIO, int threads)
      A single partition of FastRandomWalk event.
      +
      char * matrixIndex
      to hold the Matrix index (To hold the orders of 2-D arrays')
      Definition: modelMatrix.h:190
      +
      char ** edgeMatrix
      2-D Character array for the edge Matrix (The characters of Nodes)
      Definition: modelMatrix.h:175
      -
      Here is a list of all namespace members with links to the namespace documentation for each member:
      - -

      - a -

      + +

      Terminal handler for pretty stuff like colors. +More...

      #include "term.h"
      #include <string>
      @@ -96,8 +99,8 @@
      - - + + @@ -111,7 +114,13 @@ std::ostream & operator<< (std::ostream &os, const Terminal::color &c)   -

      Function Documentation

      +

      Detailed Description

      +

      Terminal handler for pretty stuff like colors.

      +
      Authors
      Ata Hakçıl
      +

      pretty colors for Terminal. Windows Only.

      + +

      Definition in file term.cpp.

      +

      Function Documentation

      ◆ operator<<()

      @@ -139,15 +148,15 @@

      overload for std::cout.

      -

      Definition at line 60 of file term.cpp.

      -
      60  {
      -
      61  char buf[6];
      -
      62  sprintf(buf,"%d",Terminal::colormap.find(c)->second);
      -
      63  os << "\e[1;" << buf << "m";
      -
      64  return os;
      -
      65 }
      +

      Definition at line 66 of file term.cpp.

      +
      66  {
      +
      67  char buf[6];
      +
      68  sprintf(buf,"%d",Terminal::colormap.find(c)->second);
      +
      69  os << "\e[1;" << buf << "m";
      +
      70  return os;
      +
      71 }
      -

      References Markov::API::CLI::Terminal::colormap.

      +

      References Markov::API::CLI::Terminal::colormap.

      @@ -156,8 +165,8 @@

      diff --git a/docs/dark/term_8cpp__incl.map b/docs/dark/term_8cpp__incl.map index fb58b5ac..2bcfe669 100644 --- a/docs/dark/term_8cpp__incl.map +++ b/docs/dark/term_8cpp__incl.map @@ -1,6 +1,6 @@ - - + + diff --git a/docs/dark/term_8cpp__incl.md5 b/docs/dark/term_8cpp__incl.md5 index 382ffd5e..a04abc8d 100644 --- a/docs/dark/term_8cpp__incl.md5 +++ b/docs/dark/term_8cpp__incl.md5 @@ -1 +1 @@ -06000e559f5019d71698106db36fbc1f \ No newline at end of file +716768b1d0150b3991a4e3a7387261af \ No newline at end of file diff --git a/docs/dark/term_8cpp_source.html b/docs/dark/term_8cpp_source.html index 81cd40f2..6769900e 100644 --- a/docs/dark/term_8cpp_source.html +++ b/docs/dark/term_8cpp_source.html @@ -87,100 +87,108 @@
      term.cpp

      -Go to the documentation of this file.
      1 #pragma once
      -
      2 #include "term.h"
      -
      3 #include <string>
      -
      4 
      -
      5 using namespace Markov::API::CLI;
      -
      6 
      -
      7 //Windows text processing is different from unix systems, so use windows header and text attributes
      -
      8 #ifdef _WIN32
      -
      9 
      -
      10 HANDLE Terminal::_stdout;
      -
      11 HANDLE Terminal::_stderr;
      +Go to the documentation of this file.
      1 /** @file term.cpp
      +
      2  * @brief Terminal handler for pretty stuff like colors
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::API::CLI::Terminal
      +
      6  */
      +
      7 
      +
      8 #include "term.h"
      +
      9 #include <string>
      +
      10 
      +
      11 using namespace Markov::API::CLI;
      12 
      -
      13 std::map<Terminal::color, DWORD> Terminal::colormap = {
      -
      14  {Terminal::color::BLACK, 0},
      -
      15  {Terminal::color::BLUE, 1},
      -
      16  {Terminal::color::GREEN, 2},
      -
      17  {Terminal::color::CYAN, 3},
      -
      18  {Terminal::color::RED, 4},
      -
      19  {Terminal::color::MAGENTA, 5},
      -
      20  {Terminal::color::BROWN, 6},
      -
      21  {Terminal::color::LIGHTGRAY, 7},
      -
      22  {Terminal::color::DARKGRAY, 8},
      -
      23  {Terminal::color::YELLOW, 14},
      -
      24  {Terminal::color::WHITE, 15},
      -
      25  {Terminal::color::RESET, 15},
      -
      26 };
      -
      27 
      -
      28 
      -
      29 Terminal::Terminal() {
      -
      30  Terminal::_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      -
      31  Terminal::_stderr = GetStdHandle(STD_ERROR_HANDLE);
      -
      32 }
      +
      13 //Windows text processing is different from unix systems, so use windows header and text attributes
      +
      14 #ifdef _WIN32
      +
      15 
      +
      16 HANDLE Terminal::_stdout;
      +
      17 HANDLE Terminal::_stderr;
      +
      18 
      +
      19 std::map<Terminal::color, DWORD> Terminal::colormap = {
      +
      20  {Terminal::color::BLACK, 0},
      +
      21  {Terminal::color::BLUE, 1},
      +
      22  {Terminal::color::GREEN, 2},
      +
      23  {Terminal::color::CYAN, 3},
      +
      24  {Terminal::color::RED, 4},
      +
      25  {Terminal::color::MAGENTA, 5},
      +
      26  {Terminal::color::BROWN, 6},
      +
      27  {Terminal::color::LIGHTGRAY, 7},
      +
      28  {Terminal::color::DARKGRAY, 8},
      +
      29  {Terminal::color::YELLOW, 14},
      +
      30  {Terminal::color::WHITE, 15},
      +
      31  {Terminal::color::RESET, 15},
      +
      32 };
      33 
      -
      34 std::ostream& operator<<(std::ostream& os, const Terminal::color& c) {
      -
      35  SetConsoleTextAttribute(Terminal::_stdout, Terminal::colormap.find(c)->second);
      -
      36  return os;
      -
      37 }
      -
      38 
      -
      39 #else
      -
      40 
      -
      41 std::map<Terminal::color, int> Terminal::colormap = {
      - - - - - - - - - - - - -
      54 };
      -
      55 
      - -
      57  /*this->;*/
      -
      58 }
      -
      59 
      -
      60 std::ostream& operator<<(std::ostream& os, const Terminal::color& c) {
      -
      61  char buf[6];
      -
      62  sprintf(buf,"%d",Terminal::colormap.find(c)->second);
      -
      63  os << "\e[1;" << buf << "m";
      -
      64  return os;
      -
      65 }
      -
      66 
      -
      67 
      -
      68 
      -
      69 
      -
      70 #endif
      +
      34 
      +
      35 Terminal::Terminal() {
      +
      36  Terminal::_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
      +
      37  Terminal::_stderr = GetStdHandle(STD_ERROR_HANDLE);
      +
      38 }
      +
      39 
      +
      40 std::ostream& operator<<(std::ostream& os, const Terminal::color& c) {
      +
      41  SetConsoleTextAttribute(Terminal::_stdout, Terminal::colormap.find(c)->second);
      +
      42  return os;
      +
      43 }
      +
      44 
      +
      45 #else
      +
      46 
      +
      47 std::map<Terminal::color, int> Terminal::colormap = {
      + + + + + + + + + + + + +
      60 };
      +
      61 
      + +
      63  /*this->;*/
      +
      64 }
      +
      65 
      +
      66 std::ostream& operator<<(std::ostream& os, const Terminal::color& c) {
      +
      67  char buf[6];
      +
      68  sprintf(buf,"%d",Terminal::colormap.find(c)->second);
      +
      69  os << "\e[1;" << buf << "m";
      +
      70  return os;
      +
      71 }
      +
      72 
      +
      73 
      +
      74 
      +
      75 
      +
      76 #endif
      - - - - -
      static std::map< Markov::API::CLI::Terminal::color, int > colormap
      Definition: term.h:32
      - -
      pretty colors for Terminal. Windows Only.
      Definition: term.h:18
      - - - - - - - - - -
      Structure to hold parsed cli arguements.
      Definition: argparse.h:15
      + + + + +
      Namespace for the MarkovPasswords API.
      +
      static std::map< Markov::API::CLI::Terminal::color, int > colormap
      Definition: term.h:39
      + +
      pretty colors for Terminal. Windows Only.
      Definition: term.h:25
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      + + + + + + + + + +
      Structure to hold parsed cli arguements.
      Definition: argparse.h:23
      + +

      Terminal handler for pretty stuff like colors. +More...

      #include <iostream>
      #include <map>
      @@ -99,7 +102,7 @@
      - + @@ -109,10 +112,10 @@
      - - - - + + + +
      @@ -152,7 +155,13 @@ std::ostream & Markov::API::CLI::operator<< (std::ostream &os, const Markov::API::CLI::Terminal::color &c)   -

      Macro Definition Documentation

      +

      Detailed Description

      +

      Terminal handler for pretty stuff like colors.

      +
      Authors
      Ata Hakçıl
      +

      pretty colors for Terminal. Windows Only.

      + +

      Definition in file term.h.

      +

      Macro Definition Documentation

      ◆ TERM_FAIL

      @@ -165,7 +174,7 @@

      -

      Definition at line 10 of file term.h.

      +

      Definition at line 17 of file term.h.

      @@ -181,7 +190,7 @@

      -

      Definition at line 11 of file term.h.

      +

      Definition at line 18 of file term.h.

      @@ -197,7 +206,7 @@

      -

      Definition at line 13 of file term.h.

      +

      Definition at line 20 of file term.h.

      @@ -213,7 +222,7 @@

      -

      Definition at line 12 of file term.h.

      +

      Definition at line 19 of file term.h.

      @@ -222,8 +231,8 @@

      diff --git a/docs/dark/term_8h__dep__incl.map b/docs/dark/term_8h__dep__incl.map index f4bb82fc..5f3bc372 100644 --- a/docs/dark/term_8h__dep__incl.map +++ b/docs/dark/term_8h__dep__incl.map @@ -1,6 +1,6 @@ - - - - + + + + diff --git a/docs/dark/term_8h__dep__incl.md5 b/docs/dark/term_8h__dep__incl.md5 index 44ab933d..c60d003c 100644 --- a/docs/dark/term_8h__dep__incl.md5 +++ b/docs/dark/term_8h__dep__incl.md5 @@ -1 +1 @@ -d5bf3a4edc64bc1905ac12e857e7c65f \ No newline at end of file +453b4e30a74b3a5f9128b2410c949502 \ No newline at end of file diff --git a/docs/dark/term_8h__incl.map b/docs/dark/term_8h__incl.map index 4e1f5be2..e31f5395 100644 --- a/docs/dark/term_8h__incl.map +++ b/docs/dark/term_8h__incl.map @@ -1,5 +1,5 @@ - + diff --git a/docs/dark/term_8h__incl.md5 b/docs/dark/term_8h__incl.md5 index a9a67622..6c7115e6 100644 --- a/docs/dark/term_8h__incl.md5 +++ b/docs/dark/term_8h__incl.md5 @@ -1 +1 @@ -9c4df588578ef3f779ca94640d314995 \ No newline at end of file +7d8e258a2f3f6c839374aecd0a7a3805 \ No newline at end of file diff --git a/docs/dark/term_8h_source.html b/docs/dark/term_8h_source.html index c03d58cf..7a266431 100644 --- a/docs/dark/term_8h_source.html +++ b/docs/dark/term_8h_source.html @@ -87,77 +87,86 @@
      term.h
      -Go to the documentation of this file.
      1 #pragma once
      -
      2 
      -
      3 #ifdef _WIN32
      -
      4 #include <Windows.h>
      -
      5 #endif
      -
      6 
      -
      7 #include <iostream>
      -
      8 #include <map>
      +Go to the documentation of this file.
      1 /** @file term.h
      +
      2  * @brief Terminal handler for pretty stuff like colors
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::API::CLI::Terminal
      +
      6  */
      +
      7 
      +
      8 #pragma once
      9 
      -
      10 #define TERM_FAIL "[" << Markov::API::CLI::Terminal::color::RED << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      -
      11 #define TERM_INFO "[" << Markov::API::CLI::Terminal::color::BLUE << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      -
      12 #define TERM_WARN "[" << Markov::API::CLI::Terminal::color::YELLOW << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      -
      13 #define TERM_SUCC "[" << Markov::API::CLI::Terminal::color::GREEN << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      -
      14 
      -
      15 namespace Markov::API::CLI{
      -
      16  /** @brief pretty colors for Terminal. Windows Only.
      -
      17  */
      -
      18  class Terminal {
      -
      19  public:
      -
      20 
      -
      21  /** Default constructor.
      -
      22  * Get references to stdout and stderr handles.
      -
      23  */
      -
      24  Terminal();
      -
      25 
      - -
      27  #ifdef _WIN32
      -
      28  static HANDLE _stdout;
      -
      29  static HANDLE _stderr;
      - -
      31  #else
      -
      32  static std::map<Markov::API::CLI::Terminal::color, int> colormap;
      -
      33  #endif
      -
      34 
      -
      35 
      -
      36 
      -
      37  static std::ostream endl;
      -
      38 
      -
      39 
      -
      40  };
      +
      10 #ifdef _WIN32
      +
      11 #include <Windows.h>
      +
      12 #endif
      +
      13 
      +
      14 #include <iostream>
      +
      15 #include <map>
      +
      16 
      +
      17 #define TERM_FAIL "[" << Markov::API::CLI::Terminal::color::RED << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      +
      18 #define TERM_INFO "[" << Markov::API::CLI::Terminal::color::BLUE << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      +
      19 #define TERM_WARN "[" << Markov::API::CLI::Terminal::color::YELLOW << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      +
      20 #define TERM_SUCC "[" << Markov::API::CLI::Terminal::color::GREEN << "+" << Markov::API::CLI::Terminal::color::RESET << "] "
      +
      21 
      +
      22 namespace Markov::API::CLI{
      +
      23  /** @brief pretty colors for Terminal. Windows Only.
      +
      24  */
      +
      25  class Terminal {
      +
      26  public:
      +
      27 
      +
      28  /** Default constructor.
      +
      29  * Get references to stdout and stderr handles.
      +
      30  */
      +
      31  Terminal();
      +
      32 
      + +
      34  #ifdef _WIN32
      +
      35  static HANDLE _stdout;
      +
      36  static HANDLE _stderr;
      + +
      38  #else
      +
      39  static std::map<Markov::API::CLI::Terminal::color, int> colormap;
      +
      40  #endif
      41 
      -
      42  /** overload for std::cout.
      -
      43  */
      -
      44  std::ostream& operator<<(std::ostream& os, const Markov::API::CLI::Terminal::color& c);
      +
      42 
      +
      43 
      +
      44  static std::ostream endl;
      45 
      -
      46 }
      +
      46 
      +
      47  };
      +
      48 
      +
      49  /** overload for std::cout.
      +
      50  */
      +
      51  std::ostream& operator<<(std::ostream& os, const Markov::API::CLI::Terminal::color& c);
      +
      52 
      +
      53 }
      - - - - -
      static std::map< Markov::API::CLI::Terminal::color, int > colormap
      Definition: term.h:32
      - -
      pretty colors for Terminal. Windows Only.
      Definition: term.h:18
      - - - - - - - - -
      static std::ostream endl
      Definition: term.h:37
      - -
      Structure to hold parsed cli arguements.
      Definition: argparse.h:15
      + + + + +
      Namespace for the MarkovPasswords API.
      +
      static std::map< Markov::API::CLI::Terminal::color, int > colormap
      Definition: term.h:39
      + +
      pretty colors for Terminal. Windows Only.
      Definition: term.h:25
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      + + + + + + + + +
      static std::ostream endl
      Definition: term.h:44
      + +
      Structure to hold parsed cli arguements.
      Definition: argparse.h:23
      + +

      Thread-safe wrapper for std::ifstream. +More...

      Include dependency graph for threadSharedListHandler.cpp:
      - - + + @@ -102,13 +105,20 @@

      Go to the source code of this file.

      -
      +

      Detailed Description

      +

      Thread-safe wrapper for std::ifstream.

      +
      Authors
      Ata Hakçıl
      +

      Simple class for managing shared access to file. This class maintains the handover of each line from a file to multiple threads.

      +

      When two different threads try to read from the same file while reading a line isn't completed, it can have unexpected results. Line might be split, or might be read twice. This class locks the read action on the list until a line is completed, and then proceeds with the handover.

      + +

      Definition in file threadSharedListHandler.cpp.

      +
      -Go to the documentation of this file.
      -
      2 
      -
      3 
      -
      4 Markov::API::Concurrency::ThreadSharedListHandler::ThreadSharedListHandler(const char* filename){
      -
      5  this->listfile;
      -
      6  this->listfile.open(filename, std::ios_base::binary);
      -
      7 }
      +Go to the documentation of this file.
      1 /** @file threadSharedListHandler.cpp
      +
      2  * @brief Thread-safe wrapper for std::ifstream
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::API::Concurrency::ThreadSharedListHandler
      +
      6  *
      +
      7  */
      8 
      -
      9 
      -
      10 bool Markov::API::Concurrency::ThreadSharedListHandler::next(std::string* line){
      -
      11  bool res = false;
      -
      12  this->mlock.lock();
      -
      13  res = (std::getline(this->listfile,*line,'\n'))? true : false;
      -
      14  this->mlock.unlock();
      -
      15 
      -
      16  return res;
      -
      17 }
      + +
      10 
      +
      11 
      + +
      13  this->listfile;
      +
      14  this->listfile.open(filename, std::ios_base::binary);
      +
      15 }
      +
      16 
      +
      17 
      +
      18 bool Markov::API::Concurrency::ThreadSharedListHandler::next(std::string* line){
      +
      19  bool res = false;
      +
      20  this->mlock.lock();
      +
      21  res = (std::getline(this->listfile,*line,'\n'))? true : false;
      +
      22  this->mlock.unlock();
      +
      23 
      +
      24  return res;
      +
      25 }
      - -
      Namespace for Concurrency related classes.
      -
      Simple class for managing shared access to file.
      -
      bool next(std::string *line)
      Read the next line from the file.
      - -
      ThreadSharedListHandler(const char *filename)
      Construct the Thread Handler with a filename.
      + +
      Namespace for Concurrency related classes.
      +
      Namespace for the MarkovPasswords API.
      +
      Simple class for managing shared access to file.
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      bool next(std::string *line)
      Read the next line from the file.
      + +
      ThreadSharedListHandler(const char *filename)
      Construct the Thread Handler with a filename.
      + +

      Thread-safe wrapper for std::ifstream. +More...

      #include <string>
      #include <fstream>
      #include <mutex>
      @@ -98,7 +101,7 @@
      - + @@ -109,15 +112,19 @@
      - - - - - - - - - + + + + + + + + + + + + +
      @@ -141,13 +148,20 @@  Namespace for Concurrency related classes.
        -
      +

      Detailed Description

      +

      Thread-safe wrapper for std::ifstream.

      +
      Authors
      Ata Hakçıl
      +

      Simple class for managing shared access to file. This class maintains the handover of each line from a file to multiple threads.

      +

      When two different threads try to read from the same file while reading a line isn't completed, it can have unexpected results. Line might be split, or might be read twice. This class locks the read action on the list until a line is completed, and then proceeds with the handover.

      + +

      Definition in file threadSharedListHandler.h.

      +
      -Go to the documentation of this file.
      1 #include <string>
      -
      2 #include <fstream>
      -
      3 #include <mutex>
      -
      4 
      -
      5 /** @brief Namespace for Concurrency related classes
      -
      6 */
      -
      7 namespace Markov::API::Concurrency{
      -
      8 
      -
      9 /** @brief Simple class for managing shared access to file
      -
      10  *
      -
      11  * This class maintains the handover of each line from a file to multiple threads.
      -
      12  *
      -
      13  * When two different threads try to read from the same file while reading a line isn't completed, it can have unexpected results.
      -
      14  * Line might be split, or might be read twice.
      -
      15  * This class locks the read action on the list until a line is completed, and then proceeds with the handover.
      -
      16  *
      -
      17 */
      - -
      19 public:
      -
      20  /** @brief Construct the Thread Handler with a filename
      -
      21  *
      -
      22  * Simply open the file, and initialize the locks.
      -
      23  *
      -
      24  * @b Example @b Use: Simple file read
      -
      25  * @code{.cpp}
      -
      26  * ThreadSharedListHandler listhandler("test.txt");
      -
      27  * std::string line;
      -
      28  * std::cout << listhandler->next(&line) << "\n";
      -
      29  * @endcode
      +Go to the documentation of this file.
      1 /** @file threadSharedListHandler.h
      +
      2  * @brief Thread-safe wrapper for std::ifstream
      +
      3  * @authors Ata Hakçıl
      +
      4  *
      +
      5  * @copydoc Markov::API::Concurrency::ThreadSharedListHandler
      +
      6  */
      +
      7 
      +
      8 #include <string>
      +
      9 #include <fstream>
      +
      10 #include <mutex>
      +
      11 
      +
      12 /** @brief Namespace for Concurrency related classes
      +
      13 */
      +
      14 namespace Markov::API::Concurrency{
      +
      15 
      +
      16 /** @brief Simple class for managing shared access to file
      +
      17  *
      +
      18  * This class maintains the handover of each line from a file to multiple threads.
      +
      19  *
      +
      20  * When two different threads try to read from the same file while reading a line isn't completed, it can have unexpected results.
      +
      21  * Line might be split, or might be read twice.
      +
      22  * This class locks the read action on the list until a line is completed, and then proceeds with the handover.
      +
      23  *
      +
      24 */
      + +
      26 public:
      +
      27  /** @brief Construct the Thread Handler with a filename
      +
      28  *
      +
      29  * Simply open the file, and initialize the locks.
      30  *
      -
      31  * @b Example @b Use: Example use case from MarkovPasswords showing multithreaded access
      +
      31  * @b Example @b Use: Simple file read
      32  * @code{.cpp}
      -
      33  * void MarkovPasswords::Train(const char* datasetFileName, char delimiter, int threads) {
      -
      34  * ThreadSharedListHandler listhandler(datasetFileName);
      -
      35  * auto start = std::chrono::high_resolution_clock::now();
      -
      36  *
      -
      37  * std::vector<std::thread*> threadsV;
      -
      38  * for(int i=0;i<threads;i++){
      -
      39  * threadsV.push_back(new std::thread(&MarkovPasswords::TrainThread, this, &listhandler, datasetFileName, delimiter));
      -
      40  * }
      -
      41  *
      -
      42  * for(int i=0;i<threads;i++){
      -
      43  * threadsV[i]->join();
      -
      44  * delete threadsV[i];
      -
      45  * }
      -
      46  * auto finish = std::chrono::high_resolution_clock::now();
      -
      47  * std::chrono::duration<double> elapsed = finish - start;
      -
      48  * std::cout << "Elapsed time: " << elapsed.count() << " s\n";
      -
      49  *
      -
      50  * }
      -
      51  *
      -
      52  * void MarkovPasswords::TrainThread(ThreadSharedListHandler *listhandler, const char* datasetFileName, char delimiter){
      -
      53  * char format_str[] ="%ld,%s";
      -
      54  * format_str[2]=delimiter;
      -
      55  * std::string line;
      -
      56  * while (listhandler->next(&line)) {
      -
      57  * long int oc;
      -
      58  * if (line.size() > 100) {
      -
      59  * line = line.substr(0, 100);
      -
      60  * }
      -
      61  * char* linebuf = new char[line.length()+5];
      -
      62  * sscanf_s(line.c_str(), format_str, &oc, linebuf, line.length()+5);
      -
      63  * this->AdjustEdge((const char*)linebuf, oc);
      -
      64  * delete linebuf;
      -
      65  * }
      -
      66  * }
      -
      67  * @endcode
      -
      68  *
      -
      69  * @param filename Filename for the file to manage.
      -
      70  */
      -
      71  ThreadSharedListHandler(const char* filename);
      -
      72 
      -
      73  /** @brief Read the next line from the file.
      -
      74  *
      -
      75  * This action will be blocked until another thread (if any) completes the read operation on the file.
      -
      76  *
      -
      77  * @b Example @b Use: Simple file read
      -
      78  * @code{.cpp}
      -
      79  * ThreadSharedListHandler listhandler("test.txt");
      -
      80  * std::string line;
      -
      81  * std::cout << listhandler->next(&line) << "\n";
      -
      82  * @endcode
      +
      33  * ThreadSharedListHandler listhandler("test.txt");
      +
      34  * std::string line;
      +
      35  * std::cout << listhandler->next(&line) << "\n";
      +
      36  * @endcode
      +
      37  *
      +
      38  * @b Example @b Use: Example use case from MarkovPasswords showing multithreaded access
      +
      39  * @code{.cpp}
      +
      40  * void MarkovPasswords::Train(const char* datasetFileName, char delimiter, int threads) {
      +
      41  * ThreadSharedListHandler listhandler(datasetFileName);
      +
      42  * auto start = std::chrono::high_resolution_clock::now();
      +
      43  *
      +
      44  * std::vector<std::thread*> threadsV;
      +
      45  * for(int i=0;i<threads;i++){
      +
      46  * threadsV.push_back(new std::thread(&MarkovPasswords::TrainThread, this, &listhandler, datasetFileName, delimiter));
      +
      47  * }
      +
      48  *
      +
      49  * for(int i=0;i<threads;i++){
      +
      50  * threadsV[i]->join();
      +
      51  * delete threadsV[i];
      +
      52  * }
      +
      53  * auto finish = std::chrono::high_resolution_clock::now();
      +
      54  * std::chrono::duration<double> elapsed = finish - start;
      +
      55  * std::cout << "Elapsed time: " << elapsed.count() << " s\n";
      +
      56  *
      +
      57  * }
      +
      58  *
      +
      59  * void MarkovPasswords::TrainThread(ThreadSharedListHandler *listhandler, const char* datasetFileName, char delimiter){
      +
      60  * char format_str[] ="%ld,%s";
      +
      61  * format_str[2]=delimiter;
      +
      62  * std::string line;
      +
      63  * while (listhandler->next(&line)) {
      +
      64  * long int oc;
      +
      65  * if (line.size() > 100) {
      +
      66  * line = line.substr(0, 100);
      +
      67  * }
      +
      68  * char* linebuf = new char[line.length()+5];
      +
      69  * sscanf_s(line.c_str(), format_str, &oc, linebuf, line.length()+5);
      +
      70  * this->AdjustEdge((const char*)linebuf, oc);
      +
      71  * delete linebuf;
      +
      72  * }
      +
      73  * }
      +
      74  * @endcode
      +
      75  *
      +
      76  * @param filename Filename for the file to manage.
      +
      77  */
      +
      78  ThreadSharedListHandler(const char* filename);
      +
      79 
      +
      80  /** @brief Read the next line from the file.
      +
      81  *
      +
      82  * This action will be blocked until another thread (if any) completes the read operation on the file.
      83  *
      -
      84  */
      -
      85  bool next(std::string* line);
      -
      86 
      -
      87 private:
      -
      88  std::ifstream listfile;
      -
      89  std::mutex mlock;
      -
      90 };
      -
      91 
      -
      92 };
      +
      84  * @b Example @b Use: Simple file read
      +
      85  * @code{.cpp}
      +
      86  * ThreadSharedListHandler listhandler("test.txt");
      +
      87  * std::string line;
      +
      88  * std::cout << listhandler->next(&line) << "\n";
      +
      89  * @endcode
      +
      90  *
      +
      91  */
      +
      92  bool next(std::string* line);
      +
      93 
      +
      94 private:
      +
      95  std::ifstream listfile;
      +
      96  std::mutex mlock;
      +
      97 };
      +
      98 
      +
      99 };
      - -
      Namespace for Concurrency related classes.
      -
      Simple class for managing shared access to file.
      -
      bool next(std::string *line)
      Read the next line from the file.
      - -
      ThreadSharedListHandler(const char *filename)
      Construct the Thread Handler with a filename.
      + +
      Namespace for Concurrency related classes.
      +
      Namespace for the MarkovPasswords API.
      +
      Simple class for managing shared access to file.
      +
      Namespace for the markov-model related classes. Contains Model, Node and Edge classes.
      Definition: model.h:24
      +
      bool next(std::string *line)
      Read the next line from the file.
      + +
      ThreadSharedListHandler(const char *filename)
      Construct the Thread Handler with a filename.