pkcrack 0.1.0

A Rust implementation of pkcrack - Known-plaintext attack against PkZip encryption
Documentation
#![allow(warnings)]
//! # PKCRACK - Rust Implementation
//!
//! A Rust implementation of the known-plaintext attack against PkZip encryption.
//! This library provides the same functionality as the original C implementation
//! but with modern Rust safety and ergonomics.
//!
//! ## Architecture
//!
//! The attack is divided into three main stages:
//! - **Stage 1**: Generate and reduce possible key2 values
//! - **Stage 2**: Reconstruct complete key sequences
//! - **Stage 3**: Find password or decrypt ZIP file
//!
//! ## Usage
//!
//! ```rust
//! use pkcrack::{PkCracker, Config};
//!
//! let config = Config::new("encrypted.zip", "plaintext.txt")
//!     .with_offset(12);
//!
//! let mut cracker = PkCracker::new(config)?;
//! let result = cracker.attack()?;
//! ```

pub mod types;
pub mod config;
pub mod zip;
pub mod crc;
pub mod crypto;
pub mod stage1;
pub mod stage2;
pub mod stage3;
pub mod error;
pub mod cracker;

// Re-export main public API
pub use types::*;
pub use config::{Config, Cli};
pub use error::{Result, PkCrackError};
pub use cracker::{PkCracker, AttackReport};

pub const KEY2_SPACE: usize = 1 << 23; // 8,388,608 possible key2 values
pub const CONST: u32 = 0x08088405; // 134,775,813
pub const INVCONST: u32 = 0xd94fa8cd; // CONST^(-1) mod 2^32
pub const MAX_DELTA: u32 = 0x00FFFFFF + 0xFF;
pub const MSB_MASK: u32 = 0xFF000000;
pub const GOOD_NUM: usize = 1000;
pub const VERY_GOOD: usize = 100;

/// Most significant byte extraction
#[inline]
pub fn msb(x: u32) -> u8 {
    ((x >> 24) & 0xFF) as u8
}

/// Key3 calculation: key3 = plaintext[i] XOR ciphertext[i]
#[inline]
pub fn key3_at(plaintext: &[u8], ciphertext: &[u8], i: usize) -> u8 {
    plaintext[i] ^ ciphertext[i]
}