added argument to change integer base

This commit is contained in:
ika4422 2026-04-08 21:41:26 +01:00
parent f9a479f4b5
commit 96bacd47bf
No known key found for this signature in database
GPG key ID: F7FBF981D2A33785
2 changed files with 24 additions and 4 deletions

View file

@ -7,6 +7,11 @@ const LETTERS_MIXED: &[u8] = b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW
const ALNUM_LOWER: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyz";
const ALNUM_UPPER: &[u8] = b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ALNUM_MIXED: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const DIGITS_BINARY: &[u8] = b"01";
const DIGITS_OCTAL: &[u8] = b"01234567";
const DIGITS_HEX_LOWER: &[u8] = b"0123456789abcdef";
const DIGITS_HEX_UPPER: &[u8] = b"0123456789ABCDEF";
const DIGITS_HEX_MIXED: &[u8] = b"0123456789abcdefABCDEF";
pub const TOKEN_HELP: &str = "\
Pattern Tokens:
@ -17,6 +22,11 @@ Pattern Tokens:
a alnum lower (0-9, a-z)
A alnum upper (0-9, A-Z)
x alnum mixed (0-9, a-z, A-Z)
b binary digit (0-1)
o octal digit (0-7)
h hex lower (0-f)
H hex upper (0-F)
X hex mixed (0-9, a-f, A-F)
* any other character is used literally";
fn pick(rng: &mut impl rand::Rng, pool: &[u8]) -> char {
@ -36,6 +46,11 @@ pub fn generate_from_pattern(pattern: &str) -> String {
'a' => Some(ALNUM_LOWER),
'A' => Some(ALNUM_UPPER),
'x' => Some(ALNUM_MIXED),
'b' => Some(DIGITS_BINARY),
'o' => Some(DIGITS_OCTAL),
'h' => Some(DIGITS_HEX_LOWER),
'H' => Some(DIGITS_HEX_UPPER),
'X' => Some(DIGITS_HEX_MIXED),
_ => None,
};