-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd58445
commit 372eec8
Showing
2 changed files
with
29 additions
and
32 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,36 @@ | ||
#!/usr/bin/env nu | ||
|
||
# Generates a cryptographically secure passphrase | ||
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 | ||
--with-entropy # Print the entropy of the passphrase | ||
--number-of-numbers: int = 0 # Number of single digit numbers in passphrase | ||
number_of_words?: int = 1 # Number of words in passphrase | ||
] { | ||
let ipsum_structure = ipsum --with-entropy=$with_entropy --as-json $number_of_words | ||
| from json | ||
let numbers = 1..$number_of_numbers | each { random-number } | str join '' | ||
let passphrase = $ipsum_structure | ||
| get words | ||
| append $numbers | ||
| str join '#' | ||
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 '#' | ||
|
||
let number_entropy = (10 | math log 2 | $in * $number_of_numbers) | ||
print ({ | ||
passphrase: $passphrase | ||
entropy: ($ipsum_structure.entropy + ($number_of_numbers | default 0)) | ||
entropy: ($ipsum_structure.entropy + $number_of_numbers) | ||
}) | ||
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!" | ||
} | ||
echo $passphrase | clip copy | ||
print "Copied!" | ||
} | ||
|
||
def random-number [] { | ||
def random-number [max: int = 10] { | ||
let max_int = 16777216 | ||
od -N3 -An -i /dev/urandom | ||
| into int | ||
| $in * 10 / $max_int | ||
| $in * $max / $max_int | ||
| math round | ||
} | ||
|