Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created September 4, 2014 08:54
Show Gist options
  • Save jonelf/4a5d9415776e823b50ac to your computer and use it in GitHub Desktop.
Save jonelf/4a5d9415776e823b50ac to your computer and use it in GitHub Desktop.
Histogram of characters used in Google Application Passwords
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) )
@jonelf
Copy link
Author

jonelf commented Sep 4, 2014

Outputs:

v |++++++++++++++++++++++++++26
e |++++++++++++++++++++++++24
r |++++++++++++++++++++++++24
t |++++++++++++++++++++++++24
p |+++++++++++++++++++++++23
w |++++++++++++++++++++++22
i |++++++++++++++++++++++22
d |++++++++++++++++++++++22
a |++++++++++++++++++++++22
s |+++++++++++++++++++++21
f |+++++++++++++++++++19
n |+++++++++++++++++++19
o |+++++++++++++++++++19
j |+++++++++++++++++++19
c |+++++++++++++++++++19
x |++++++++++++++++++18
z |++++++++++++++++++18
b |+++++++++++++++++17
k |++++++++++++++++16
y |+++++++++++++++15
g |++++++++++++++14
q |++++++++++++++14
l |+++++++++++++13
m |++++++++++++12
h |+++++++++++11
u |+++++++7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment