Created
September 4, 2014 08:54
-
-
Save jonelf/4a5d9415776e823b50ac to your computer and use it in GitHub Desktop.
Histogram of characters used in Google Application Passwords
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
def histogram(message) | |
message.each_char.reduce(Hash.new(0)) { |h, k| h[k] += 1; h} | |
end | |
def graph_histogram(h) | |
h.to_a. | |
sort_by{|kv| kv[1]*-1}. | |
map{|a| "#{a[0]} |#{('+'*a[1])[0..120]}#{a[1].to_s}\n"}. | |
join | |
end | |
message = "bejkpcfcpofjctvlybwqvdpkwebavtbyxngwbrkobhrtribviwprprjpdootlzeykwypskoapaovadeenabiajviezaivmtyowwmmjkaqcretlgtlimiecizhempplsuhsjfwgsapyupyshyiduhcecnffzxvwidkufekanlarlroxqloemogsisdpsdvqpbvkefysmbnorzttjwhvxqchvjtvqzwcgilyclijgrttfcjhwjptnvnjoqrodvvibkiwmrddfxgolfnaijorrcvertiuyssxsuetdfbatrwwsazcstsjexttfigxvsdyzqjhpeynxbkaazpnekjemcngwtiazngnlaevvdehccbdzasqpmwncwspxktrbqdazecvpqyowjvaxlgpwzkkvnxthzdrdsdmdtzdeqffjznfxxbfjtewindravsxobrriyfxnorzfvovwkfxnrxrqcggdqpsgumzpi" | |
puts graph_histogram( histogram(message) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs: