Skip to content

Commit

Permalink
Better passphrases
Browse files Browse the repository at this point in the history
  • Loading branch information
NonlinearFruit committed Dec 31, 2023
1 parent b114323 commit 3feef56
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions scripts/passphrase
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
#!/usr/bin/env nu

def main [number_of_words?] {
let passphrase = ipsum --as-json ($number_of_words | default 1)
| from json
| str join '#'

print $passphrase
echo $passphrase | clip copy
print "Copied!"
def main [
--with-entropy # Print the entropy of the passphrase
--number-of-numbers: int # Number of single digit numbers in passphrase
number_of_words? # Number of words in passphrase
] {
if $with_entropy {
let ipsum_structure = ipsum --with-entropy --as-json ($number_of_words | default 1)
| from json
let numbers = 1..($number_of_numbers | default 0) | each { random-number } | str join ''
let number_entropy = (10 | math log 2 | $in * ($number_of_numbers | default 0))
let passphrase = $ipsum_structure.words
| append $numbers
| str join '#'

print ({
passphrase: $passphrase
entropy: ($ipsum_structure.entropy + ($number_of_numbers | default 0))
})
echo $passphrase | clip copy
print "Copied!"
} else {
let numbers = 1..($number_of_numbers | default 0) | each { random-number } | str join ''
let passphrase = ipsum --as-json ($number_of_words | default 1)
| from json
| append $numbers
| str join '#'

print $passphrase
echo $passphrase | clip copy
print "Copied!"
}
}

def random-number [] {
let max_int = 16777216
od -N3 -An -i /dev/urandom
| into int
| $in * 10 / $max_int
| math round
}

0 comments on commit 3feef56

Please sign in to comment.