Hello there. I am trying to recover a password of which I think I know the first letters, but where I can't remember the last ones, which were digits if I remember well. So I did something like that:
#!/usr/bin/ruby
require 'base64'
require 'digest/sha2'
require 'open3'
require 'openssl'
# Put your best guess at your passphrase here
passphrase = 'guili'
# The full path to your electrum.dat or default_wallet
wallet_file = '/home/lapa/.electrum/wallets/default_wallet'
# Where to find Electrum. Am using Ubuntu
$electrum = '/usr/bin/electrum'
def test(phrase)
$cipher.reset
$cipher.key = Digest::SHA256.digest(Digest::SHA256.digest(phrase))
$cipher.update $seed
$cipher.final
puts phrase
i,o,t = Open3.popen2e($electrum, "-o", "getseed")
i.puts(phrase)
i.close
if t.value.success?
puts "Found it! #{phrase}"
exit
end
rescue OpenSSL::Cipher::CipherError
end
def scramble(passphrase)
characters = " !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
list = []
#add numbers at the end
for i in 1..100000
testphrase = passphrase.dup
testphrase.concat(i.to_s)
list << testphrase
return list
end
wallet = File.read(wallet_file)
seed_base64 = wallet.match(/'seed': '([^']+)'/).captures.first
$seed = Base64.decode64(seed_base64)
$cipher = OpenSSL::Cipher.new('aes-256-cbc')
$cipher.iv = $seed.slice!(0,16)
Dir.chdir File.dirname $electrum
list1 = scramble(passphrase)
for i in list1
test i
end
puts "No luck."
exit 1
Problem is, the test does not test all possibilities as expected. Typically i get results like :
guili195
guili466
guili1051
guili1231
guili1370
guili2026
guili2476
As if, I don't why, some steps were jumped. I can write a bit python but this is the first time I am touching ruby. Please someone help ?