Skip to content

Instantly share code, notes, and snippets.

@tenten0213
Last active August 29, 2015 13:56
Show Gist options
  • Save tenten0213/8910211 to your computer and use it in GitHub Desktop.
Save tenten0213/8910211 to your computer and use it in GitHub Desktop.
数字6桁パスワードのハッシュ値の総当たり
require 'digest/md5'
hash = "4b364677946ccf79f841114e73ccaf4f"
salt = "hoge$"
0.upto(999999) { |num|
pass = "%06d"%num
digest = Digest::MD5.new.update(salt + pass).to_s
if digest == hash
puts "Solved: #{pass}"
end
}
@tenten0213
Copy link
Author

time ruby jal.rbで実行すれば良いからbenchmark消した。

@tenten0213
Copy link
Author

  1. 0から999999の範囲指定に変更
  2. 書式を"%6d"から"%06d"に変更(元の書式だと0埋めにならずスペース埋めになる
  3. 先に$をsaltに付与するように変更

@tenten0213
Copy link
Author

formatとmd5の取り方を変えたら半分程度まで早くなった模様。
勉強になります。
https://gist.github.com/Sheile/8949613

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