# hashcat/princeprocessor architecture

> Architecture diagram of the GitHub repository hashcat/princeprocessor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hashcat/princeprocessor
- Repository: https://github.com/hashcat/princeprocessor

## Overview

##### Main Components

a) Input Processing Component:
- Input wordlist handling mechanism
- File reading and parsing logic

b) PRINCE Algorithm Core:
- Word chain generation engine
- Combination logic processor
- Length calculation component

c) Output Generation:
- Password candidate output stream
- Memory management for word combinations

- Input Wordlist → Processing → Chain Generation → Output Candidates

##### Detailed Component Breakdown

a) Input Layer:
- Connection to the input wordlist file
- Rules processing component (reference rules/*.rule files)
- Rule optimization process (prince_optimized.rule)

b) Processing Core (based on src/pp.c):
- Word tokenization
- Chain building logic
- MPZ integer handling (reference to mpz_int128.h)

c) Output Layer:
- Password candidate generation
- Output stream management

##### Key Technical Elements to Highlight

a) Algorithm Components:
- Word chain length calculator
- Combination generator
- Probability calculator
- Chain element processor

b) Performance Optimizations:
- Memory management flow
- Parallel processing if applicable
- Reference the optimization rules

##### Implementation Details to Consider

- Relationship between the main program (pp.c) and supporting components
- Where rule files are applied in the process
- MPZ integer handling for large number operations
- Build process integration (Makefile)

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Legend
        style Legend fill:#f5f5f5,stroke:#333
        L1[Process Module]:::process
        L2[(File Component)]:::file
        L3{Decision Point}:::decision
        L4([Performance Component]):::performance
    end

    subgraph Input_Layer
        InputFile[(Input Wordlist)]:::file
        RuleFiles[(Rule Files)]:::file
        RuleOpt[(Optimized Rules)]:::file
        RuleGen[(Generated Rules)]:::file
    end

    subgraph Processing_Core
        MainProgram[Main Program]:::process
        WordTokenizer[Word Tokenizer]:::process
        ChainBuilder[Chain Builder]:::process
        MPZHandler[Large Integer Handler]:::process
    end

    subgraph Algorithm_Components
        LengthCalc{Chain Length Calculator}:::decision
        CombGen{Combination Generator}:::decision
        ProbCalc{Probability Calculator}:::decision
    end

    subgraph Performance_Layer
        MemManager([Memory Manager]):::performance
        ParallelProc([Parallel Processing]):::performance
        OptRules([Rule Optimization]):::performance
    end

    subgraph Output_Layer
        PasswdGen[Password Generator]:::process
        OutputStream[(Output Stream)]:::file
    end

    %% Connections
    InputFile --> WordTokenizer
    RuleFiles --> OptRules
    RuleOpt --> OptRules
    RuleGen --> OptRules

    WordTokenizer --> ChainBuilder
    ChainBuilder --> MPZHandler
    MPZHandler --> LengthCalc

    LengthCalc --> CombGen
    CombGen --> ProbCalc
    ProbCalc --> PasswdGen

    MemManager --> ChainBuilder
    ParallelProc --> ChainBuilder
    OptRules --> ChainBuilder

    PasswdGen --> OutputStream

    MainProgram --> WordTokenizer
    MainProgram --> ChainBuilder
    MainProgram --> PasswdGen

    %% Styles
    classDef process fill:#90caf9,stroke:#1565c0
    classDef file fill:#a5d6a7,stroke:#2e7d32
    classDef decision fill:#ffe082,stroke:#ff8f00
    classDef performance fill:#ef9a9a,stroke:#c62828

    %% Click Events
    click MainProgram "https://github.com/hashcat/princeprocessor/blob/master/src/pp.c"
    click MPZHandler "https://github.com/hashcat/princeprocessor/blob/master/src/mpz_int128.h"
    click RuleOpt "https://github.com/hashcat/princeprocessor/blob/master/rules/prince_optimized.rule"
    click RuleGen "https://github.com/hashcat/princeprocessor/blob/master/rules/prince_generated.rule"
    click MainProgram "https://github.com/hashcat/princeprocessor/tree/master/src/Makefile"
```
