-
-
Save johnbintz/92b940a61682de59f82f9dedc3920b6e to your computer and use it in GitHub Desktop.
Fake-ish Legend of Zelda password generator
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 | |
# 675 bits of real data + an 8 bit shift instruction to help encrypt the passsword | |
length = 675 + 8 | |
# the same character set as kid icarus | |
chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?!" | |
result = "" | |
loop do | |
# i just need something that looks good for the video | |
bits = length.times.each_with_object([]) { |i, obj| obj << rand(2) } | |
# the checksum is literally just adding all the bits together as far as I can tell. it's very simple. | |
bits_with_checksum = bits + (bits.sum.to_s(2).reverse.split("").map(&:to_i)) | |
# run all this until i get a password with plenty of cool exclamation points (and slightly less cool question marks) | |
result = bits_with_checksum.each_slice(6).each_with_object("") { |bits, out| out << chars[bits.join.reverse.to_i(2)] } | |
break if result.split('!').length > 3 && result.split('?').length > 3 | |
end | |
puts result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment