# codebreaker-rs
[](https://crates.io/crates/codebreaker)
[](https://docs.rs/codebreaker)
[](https://github.com/mlafeldt/codebreaker-rs/actions)
A Rust library to decrypt & encrypt any cheat code for CodeBreaker PS2.
Originally reverse-engineered from MIPS R5900 assembly and [converted to C](https://github.com/mlafeldt/cb2util/blob/v1.9/cb2_crypto.c) in 2006.
Now ported to Rust for [fun and profit](https://github.com/mlafeldt/cb2util/pull/13).
For more information, check out my article on [7 Things I Learned From Porting a C Crypto Library to Rust](https://web.archive.org/web/20241119103347/https://sharpend.io/7-things-i-learned-from-porting-a-c-crypto-library-to-rust/).
## Quickstart
Add the crate as a dependency to your `Cargo.toml`:
```toml
[dependencies]
codebreaker = "0.4"
```
Now you can start decrypting some codes:
```rust
use codebreaker::Codebreaker;
let input: Vec<(u32, u32)> = vec![
(0x2043AFCC, 0x2411FFFF),
(0x2A973DBD, 0x00000000),
(0xB4336FA9, 0x4DFEFB79),
(0x973E0B2A, 0xA7D4AF10),
];
let output: Vec<(u32, u32)> = vec![
(0x2043AFCC, 0x2411FFFF),
(0x201F6024, 0x00000000),
(0xBEEFC0DE, 0x00000000),
(0x2096F5B8, 0x000000BE),
];
let mut cb = Codebreaker::new();
for (i, code) in input.iter().enumerate() {
assert_eq!(cb.auto_decrypt_code(code.0, code.1), output[i]);
}
```
Read the [full documentation](https://docs.rs/codebreaker) for more examples.
## Platform support
The `codebreaker` crate is `no_std` and currently supports little-endian targets only.
The CB v7 implementation intentionally preserves byte-level behavior from the original C code.
## License
Copyright (c) Mathias Lafeldt
Licensed under the [Apache License, Version 2.0](LICENSE-APACHE) or the [MIT license](LICENSE-MIT), at your option.