vxencrypt.rb 672 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env ruby
  2. #
  3. # This script can be used to calculate hash values for VxWorks passwords.
  4. #
  5. def hashit(inp)
  6. if inp.length < 8 or inp.length > 120
  7. raise RuntimeError, "The password must be between 8 and 120 characters"
  8. end
  9. sum = 0
  10. bytes = inp.unpack("C*")
  11. bytes.each_index {|i| sum += (bytes[i] * (i + 1)) ^ (i + 1) }
  12. hackit(sum)
  13. end
  14. def hackit(sum)
  15. magic = 31695317
  16. res = ((sum * magic) & 0xffffffff).to_s
  17. res.unpack("C*").map{ |c|
  18. c += 0x21 if c < 0x33
  19. c += 0x2f if c < 0x37
  20. c += 0x42 if c < 0x39
  21. c
  22. }.pack("C*")
  23. end
  24. input = ARGV.shift || "flintstone"
  25. $stderr.puts "[*] Hash for password '#{input}' is #{hashit(input)}"