Created
September 7, 2018 23:42
-
-
Save franccesco/fc4198602c9fd33e68c9236c40bd52a4 to your computer and use it in GitHub Desktop.
rdice.rb
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
#!/usr/bin/env ruby | |
require 'colorize' | |
# if ARGV is zero (or no argument given) then default to 6. Else, keep ARGV. | |
length = ARGV[0].to_i.zero? ? 6 : ARGV[0].to_i | |
colors = String.colors | |
colors.delete(:black) | |
def scramble_pass(length) | |
pass_dict = 'assets/diceware_dict.txt' | |
# load new password as array and strip new lines | |
pass_array = File.readlines(pass_dict) | |
pass_array.map(&:strip!) | |
# shuffle and strip to desired length. | |
shuffle_pass = pass_array.shuffle[1..length] | |
shuffle_pass | |
end | |
new_password = scramble_pass(length) | |
print 'Passphrase ~> ' | |
new_password.each do |pass| | |
rand_color = colors.shuffle[1] | |
print pass.colorize(rand_color) + ' ' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment