Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fake-ish Legend of Zelda password generator
#!/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