Class: Md5sum

Inherits:
Object
  • Object
show all
Includes:
AliasE
Defined in:
lib/md5sum/md5sum.rb

Constant Summary collapse

N =
"\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = ARGV, run_already = true) ⇒ Md5sum

#

initialize

#

27
28
29
30
31
32
33
34
35
36
37
# File 'lib/md5sum/md5sum.rb', line 27

def initialize(
    input       = ARGV,
    run_already = true
  )
  case run_already
  when false, :dont_run_yet, :do_not_run_yet
    run_already = false
  end
  set_input(input)
  run if run_already
end

Class Method Details

.[](i) ⇒ Object

#

Md5sum[]

#

88
89
90
# File 'lib/md5sum/md5sum.rb', line 88

def self.[](i)
  Md5sum.new(i)
end

.reverse_md5(i) ⇒ Object

#

Md5sum.reverse_md5

Usage examples:

require 'md5sum'; Md5sum.reverse_md5("/Depot/jjj/lalalala.flv")
#

74
75
76
# File 'lib/md5sum/md5sum.rb', line 74

def self.reverse_md5(i)
  Md5sum.new(nil,false).reverse_md5(i)
end

Instance Method Details

#file?Boolean

#

file?

#

Returns:

  • (Boolean)

95
96
97
# File 'lib/md5sum/md5sum.rb', line 95

def file?
  @input
end

#return_md5sum(input = @input) ⇒ Object Also known as: md5sum?

#

return_md5sum

Example results:

1897a33110ebfee800fb9562711cac02
#

105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/md5sum/md5sum.rb', line 105

def return_md5sum(input = @input)
  if input.is_a? Array
    input.each { |file|
      if File.file? file
        dataset = File.read(file)
      else
        dataset = file
      end
      digest = Digest::MD5.hexdigest(dataset)
      return digest
    }
  else
    if File.file? input
      dataset = File.read(input)
    else
      dataset = input
    end
    return Digest::MD5.hexdigest(dataset)
  end
end

#reverse_md5(md5hash = '5f4dcc3b5aa765d61d8327deb882cf99') ⇒ Object

#

reverse_md5

This reverses a md5 hash, by using making use of the Digest module.

reverse_md5 '5f4dcc3b5aa765d61d8327deb882cf99'
#

62
63
64
65
66
# File 'lib/md5sum/md5sum.rb', line 62

def reverse_md5(md5hash = '5f4dcc3b5aa765d61d8327deb882cf99')
  require 'digest/md5reverse'
  reverse_hexdigest = Digest::MD5Reverse.to_reverse_hexdigest(md5hash.to_s)
  e N+"\tmd5hash word [#{reverse_hexdigest}] "+N # md5hash word [password]
end

#run(shall_we_show_the_result = false) ⇒ Object

#

run (run tag)

Will return the md5sum.

#

131
132
133
134
135
136
137
138
# File 'lib/md5sum/md5sum.rb', line 131

def run(shall_we_show_the_result = false)
  case shall_we_show_the_result
  when :do_show_the_result
    shall_we_show_the_result = true
  end
  set_result
  show_result if shall_we_show_the_result
end

#set_input(i = '') ⇒ Object

#

set_input

#

42
43
44
45
46
47
# File 'lib/md5sum/md5sum.rb', line 42

def set_input(i = '')
  i = '' if i.nil?
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i # Assign to input.
end

#set_resultObject

#

set_result

#

81
82
83
# File 'lib/md5sum/md5sum.rb', line 81

def set_result
  @result = return_md5sum(@input)
end

#show_resultObject

#

show_result

#

52
53
54
# File 'lib/md5sum/md5sum.rb', line 52

def show_result
  e @result unless @input.nil? # must pass 1 arg
end