Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function testDiceware($numWords = 3)
- {
- $wordlistUrl = 'https://www.eff.org/files/2016/07/18/eff_large_wordlist.txt';
- if (!file_exists(CACHE_DIR . '/' . basename($wordlistUrl))) {
- $wordlist = file_get_contents($wordlistUrl);
- file_put_contents(CACHE_DIR . '/' . basename($wordlistUrl), $wordlist);
- } else {
- $wordlist = file_get_contents(CACHE_DIR . '/' . basename($wordlistUrl));
- }
- $dies = 5;
- $words = [];
- for ($n = 0; $n < $numWords; $n++) {
- $rolls = [];
- for ($i = $dies; $i > 0; $i--) {
- $rolls[] = rand(1, 6);
- }
- $key = implode('', $rolls);
- preg_match('#^' . $key . '\s+(.*?)$#sm', $wordlist, $matches);
- $words[] = $matches[1];
- }
- $phrase = str_replace(' ', '', lcfirst(ucwords(implode(' ', $words))));
- return $phrase;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement