Class: Kyle

Inherits:
Object
  • Object
show all
Defined in:
lib/kyle.rb

Class Method Summary collapse

Class Method Details

.di_hash(val) ⇒ Object



96
97
98
# File 'lib/kyle.rb', line 96

def self.di_hash(val)
  iterative_hash(iterative_hash(val))
end

.enc_it(alg, val, key) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/kyle.rb', line 57

def self.enc_it(alg,val,key) 
  #puts "enc_it #{alg} #{to_hex(val)} #{to_hex(key)}"
  begin
    cipher = OpenSSL::Cipher::Cipher.new(alg)
    cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, "kyle", 10000, 32)
    cipher.iv = sha512ize(key)
    cipher.encrypt
    return cipher.update(val) + cipher.final
  rescue OpenSSL::Cipher::CipherError => e
    puts "Error: #{e.message}"
  end
end

.generate(hostname, account, port, key) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/kyle.rb', line 115

def self.generate(hostname,,port,key)
  
  ret  = Array.new
  
  harr = [ di_hash(hostname), di_hash(), di_hash(port), di_hash(key) ]

  v1 = iterative_enc(harr[0],harr[1])
  v2 = iterative_enc(harr[2],harr[3])

  v = iterative_enc(v1,v2)

  c = v
  $animalnames.each do |animal|
    c = OpenSSL::PKCS5.pbkdf2_hmac_sha1(c, v, 10000, 32)
  
    ret << hash2pass(c)
  
  end
  
  return ret
end

.hash2pass(val) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/kyle.rb', line 100

def self.hash2pass(val) 
  ret = ""
  
  # to be sure it is long enough
  h = sha512ize(val)
  
  h.each_byte do |c|
    ret += $passctable[c % ($passctable.size)]
  end
  
  return ret[0..15]
end

.hash_it(alg, val) ⇒ Object



79
80
81
82
# File 'lib/kyle.rb', line 79

def self.hash_it(alg,val)
  #puts "hash_it #{alg} - #{to_hex(val)}"
  OpenSSL::Digest.digest(alg,val)
end

.iterative_enc(val, key) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/kyle.rb', line 70

def self.iterative_enc(val, key)
  ret = val
  val.each_byte do |c|
    ret = enc_it($ENC_ALGS[c % ($ENC_ALGS.size)], ret, key)
  end
  
  return ret
end

.iterative_hash(val) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/kyle.rb', line 84

def self.iterative_hash(val)
  ret = val
  val.each_byte do |c|
    ret = hash_it($HSH_ALGS[c % ($HSH_ALGS.size)], ret)
  end
  return ret
end

.run(args) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/kyle.rb', line 172

def self.run(args)
  if (args.size > 0 && args[0] == "test")
    test_it()
  else
    hostname = ask("Hostname:")
      = ask("Account:")
    port  = ask("Port:")
    key  = ask("Key:") { |q| q.echo = false }
    key2  = ask("Key (again):") { |q| q.echo = false }
    
    if (key != key2)
      puts "Passes do not match!!"
      exit
    end
    
    puts "Calculating..."
    vals = generate(hostname,,port,key)
    
    $animalnames.each.with_index(0) do |animal,i|
    
      puts "#{animal}\t#{vals[i]}"
    
    end
  end
end

.sha512ize(val) ⇒ Object



92
93
94
# File 'lib/kyle.rb', line 92

def self.sha512ize(val)
  hash_it("sha512",val)
end

.test_itObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/kyle.rb', line 156

def self.test_it()
  puts "Testing..."
  
  failed = false
  (0..1).each do |idx|
    vals = generate($testarr[idx][0],$testarr[idx][1],$testarr[idx][2],$testarr[idx][3])
    vals.each.with_index(0) do |v,i|
      if ($testarr[idx][i+4] != v)
        puts "Test failed: #{$testarr[idx][i+4]} <> #{v}"
        failed = true
      end
    end
  end
  puts "Finished #{failed ? "and Failed" : "successfully"}"
end

.to_hex(s) ⇒ Object



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

def self.to_hex(s)
  s.each_byte.map { |b| b.to_s(16) }.join
end