Module: Crc32Cracker

Defined in:
lib/crc32_cracker.rb,
lib/crc32_cracker/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.crc32_check(str, js_32_bit = true) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/crc32_cracker.rb', line 14

def self.crc32_check(str, js_32_bit = true)
  table = Zlib::crc_table.map {|el| el.to_s(16).upcase} # hex crc32 table

  crc = 0
  crc = crc ^ (-1)

  max_32_int = (2**32)

  str.length.times do |k|
    a = (crc >> 8)
    b = ("0x" + table[((crc ^ str[k].ord ) & 0x000000FF)]).to_i(16)
    crc = (a ^ b)

    if js_32_bit # See http://stackoverflow.com/questions/17056263/getting-the-same-result-from-ruby-as-javascript-for-bitwise-xor?noredirect=1#comment24669730_17056263
      if crc > (max_32_int/2)
        crc = crc - max_32_int
      elsif crc < -(max_32_int/2)
        crc = crc + max_32_int
      end
    end

  end

  crc =  crc ^ (-1)
  crc = crc.abs
  return crc

end

.crc32_crack(start_letter, end_letter, length, salt, hash) ⇒ Object

Gets the crc32 code of the given length using the range from a start_letter…end_letter that matches the salt/hash



4
5
6
7
8
9
10
11
12
# File 'lib/crc32_cracker.rb', line 4

def self.crc32_crack(start_letter, end_letter, length, salt, hash) # Gets the crc32 code of the given length using the range from a start_letter...end_letter that matches the salt/hash

  (start_letter..end_letter).to_a.repeated_permutation(length.to_i).each do |guess|
    guess = guess.join

    return guess if (crc32_check(guess + salt).to_i == hash.to_i)
  end

end