class PasswordCrack::Dict
Public Class Methods
new(dict_name,dict_type=nil)
click to toggle source
# File lib/password_crack.rb, line 117 def initialize dict_name,dict_type=nil dict_name = dict_name+ '.txt' dict_name = dict_name + '.' + dict_type if dict_type @dict_name = dict_name @dict_path= Dir.tmpdir @dict_filename = dict_name +'.7z' @dict_filename_timestamp = @dict_filename +'.timestamp' @client = Mechanize.new end
Public Instance Methods
clean()
click to toggle source
# File lib/password_crack.rb, line 139 def clean delete dict_7z_pathname delete dict_timestamp_pathname delete dict_pathname end
create()
click to toggle source
# File lib/password_crack.rb, line 168 def create pathname = dict_pathname load pathname end
load()
click to toggle source
# File lib/password_crack.rb, line 148 def load return if(Time.now.to_i - local_timestamp < 10 *60) if local_timestamp < server_timestamp download_and_unpack else write dict_timestamp_pathname,Time.now.to_i.to_s if(Time.now.to_i - local_timestamp > 10 *60) end end
update()
click to toggle source
# File lib/password_crack.rb, line 134 def update load end
Private Instance Methods
delete(pathname)
click to toggle source
# File lib/password_crack.rb, line 263 def delete pathname if File.exists? pathname File.delete pathname p 'delete file:'+pathname end end
dict_7z_pathname()
click to toggle source
# File lib/password_crack.rb, line 189 def dict_7z_pathname @dict_path+'/'+@dict_filename end
dict_download_url()
click to toggle source
# File lib/password_crack.rb, line 204 def dict_download_url DICT_DOWNLOAD_FOLDER+'/'+@dict_filename end
dict_pathname()
click to toggle source
# File lib/password_crack.rb, line 182 def dict_pathname @dict_path+'/'+@dict_filename.gsub(/\.7z/,'') end
dict_timestamp_download_url()
click to toggle source
# File lib/password_crack.rb, line 210 def dict_timestamp_download_url DICT_DOWNLOAD_FOLDER+'/'+@dict_filename_timestamp end
dict_timestamp_pathname()
click to toggle source
# File lib/password_crack.rb, line 196 def dict_timestamp_pathname @dict_path+'/'+@dict_filename_timestamp end
download(url)
click to toggle source
# File lib/password_crack.rb, line 241 def download url r = @client.get(url) r.body end
download_and_unpack()
click to toggle source
# File lib/password_crack.rb, line 234 def download_and_unpack write dict_7z_pathname,download(dict_download_url) unpack write dict_timestamp_pathname, server_timestamp end
local_timestamp()
click to toggle source
# File lib/password_crack.rb, line 216 def local_timestamp return @l_t.to_i if @l_t @l_t = read dict_timestamp_pathname return 0 if ( !@l_t) @l_t.to_i end
read(pathname)
click to toggle source
# File lib/password_crack.rb, line 256 def read pathname return nil unless File.exists? pathname File.read pathname end
server_timestamp()
click to toggle source
# File lib/password_crack.rb, line 228 def server_timestamp return @t if @t @t =download dict_timestamp_download_url @t.to_i end
unpack()
click to toggle source
# File lib/password_crack.rb, line 248 def unpack File.open(dict_7z_pathname, "rb") do |file| SevenZipRuby::Reader.extract_all(file, @dict_path) delete file.path p 'create new file:' +dict_pathname end end
write(pathname,content)
click to toggle source
# File lib/password_crack.rb, line 275 def write pathname,content File.open(pathname, "wb") do |file| file.write content end p 'create new file: '+pathname end