Last active
February 24, 2021 03:13
-
-
Save brohee/c6e3f3dec32f009ba255 to your computer and use it in GitHub Desktop.
Solution to http://security.stackexchange.com/a/102794/1898
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://security.stackexchange.com/questions/102703/help-generating-wordlist-using-crunch | |
// I need to configure crunch so that it produces a wordlist with the following set of rules: | |
// | |
// Exactly 10 characters long | |
// Contains exactly 4 letters, which have to be a-f (all lowercase) | |
// Contains exactly 6 numbers, which have to be 2-9 | |
// The letters and numbers can be anywhere in the word | |
// | |
// Is there any way to add a function to that program that disallows character repetition above 2? | |
fn all_words(prefix: &str, letters: u32, numbers: u32) { | |
let prefix_length = prefix.len(); | |
if prefix_length >= 3 { | |
// abort early is last three chars are identical | |
let c1 = prefix.chars().last(); | |
let c2 = prefix.chars().nth(prefix_length-2); | |
let c3 = prefix.chars().nth(prefix_length-3); | |
if c1 == c2 && c1 == c3 { | |
return; | |
} | |
} | |
if letters == 0 && numbers == 0 { | |
println!("{}", prefix); | |
return; | |
} | |
if letters > 0 { | |
for c in b'a'..b'f'+1 { | |
let mut new_prefix = String::from(prefix); | |
new_prefix.push(c as char); | |
all_words(&new_prefix, letters-1, numbers); | |
} | |
} | |
if numbers > 0 { | |
for n in b'2'..b'9'+1 { | |
let mut new_prefix = String::from(prefix); | |
new_prefix.push(n as char); | |
all_words(&new_prefix, letters, numbers-1); | |
} | |
} | |
} | |
fn main() { | |
all_words("", 4, 6); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment