1
0

chore: update dependency

This commit is contained in:
sangge 2025-08-27 11:32:48 +08:00
parent 944a68c18c
commit 74e9959c6d
3 changed files with 130 additions and 0 deletions

49
CLAUDE.md Normal file
View File

@ -0,0 +1,49 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
This is a Rust implementation of the Cryptopal challenges - a collection of cryptography exercises. The codebase follows a workspace structure with individual problem solutions and shared utilities.
## Workspace Structure
- **Root workspace**: Defined in `Cargo.toml` with `edition = "2024"`
- **Individual problems**: Located in `problems/p1/`, `problems/p2/`, etc. Each has its own `Cargo.toml` and `src/main.rs`
- **Common utilities**: Located in `common/` crate with shared cryptographic functions like `is_valid_english()` and `xor_with_key()`
- **Documentation**: `cryptopal_book/` contains mdBook documentation for each challenge
## Key Commands
### Building and Running
- `cargo build` - Build the entire workspace
- `cargo run -p p1` - Run a specific problem (e.g., problem 1)
- `cargo build -p p1` - Build a specific problem
- `cargo test` - Run tests across the workspace
- `cargo check` - Quick syntax check without full compilation
### Documentation
- `mdbook build cryptopal_book/` - Build the challenge documentation
- `mdbook serve cryptopal_book/` - Serve documentation locally
## Architecture Notes
- Each problem is isolated in its own binary crate under `problems/`
- Common cryptographic utilities are shared via the `common` crate
- Problems use dependencies like `hex`, `base64`, and `anyhow` for encoding/error handling
- Code includes Chinese comments for educational purposes
- The `common` crate provides utilities for English text validation and XOR operations
## Dependencies Pattern
Individual problems typically use:
- `hex` for hexadecimal encoding/decoding
- `base64` for Base64 operations
- `anyhow` for error handling (via common crate)
- Local `common` crate for shared utilities
## Development Notes
- Each challenge solution should be self-contained in its respective `problems/pN/` directory
- Use the `common` crate for shared cryptographic functions
- Follow the existing pattern of having a simple `main.rs` that demonstrates the solution

37
Cargo.lock generated
View File

@ -215,6 +215,12 @@ dependencies = [
[[package]]
name = "p19"
version = "0.1.0"
dependencies = [
"anyhow",
"base64",
"common",
"rayon",
]
[[package]]
name = "p2"
@ -223,6 +229,37 @@ dependencies = [
"hex",
]
[[package]]
name = "p20"
version = "0.1.0"
[[package]]
name = "p21"
version = "0.1.0"
[[package]]
name = "p22"
version = "0.1.0"
dependencies = [
"common",
"rand 0.9.2",
]
[[package]]
name = "p23"
version = "0.1.0"
dependencies = [
"rand 0.9.2",
]
[[package]]
name = "p24"
version = "0.1.0"
[[package]]
name = "p28"
version = "0.1.0"
[[package]]
name = "p3"
version = "0.1.0"

View File

@ -502,3 +502,47 @@ pub fn aes_ctr_enc(input: &[u8], key: &[u8; 16], nonce: u64) -> Result<Vec<u8>>
pub fn aes_ctr_dec(input: &[u8], key: &[u8; 16], nonce: u64) -> Result<Vec<u8>> {
aes_ctr_enc(input, key, nonce)
}
pub struct MT19937 {
mt: [u32; 624],
index: usize,
}
impl MT19937 {
pub fn new(seed: u32) -> Self {
let mut mt = [0; 624];
mt[0] = seed;
for i in 1..624 {
mt[i] = 0x6c078965u32
.wrapping_mul(mt[i - 1] ^ (mt[i - 1] >> 30))
.wrapping_add(i as u32)
}
let index = 0;
MT19937 { mt, index }
}
pub fn extract_number(&mut self) -> u32 {
if self.index == 0 {
self.generate_numbers();
}
let mut result = self.mt[self.index];
result ^= result >> 11;
result ^= (result << 7) & 0x9d2c5680;
result ^= (result << 15) & 0xefc60000;
result ^= result >> 18;
self.index = (self.index + 1) % 624;
result
}
fn generate_numbers(&mut self) {
for i in 0..624 {
let y: u32 = (self.mt[i] & 0x80000000) + (self.mt[(i + 1) % 624] & 0x7fffffff);
self.mt[i] = self.mt[(i + 397) % 624] ^ (y >> 1);
if y % 2 != 0 {
self.mt[i] ^= 0x9908b0df;
}
}
}
}