Class: String

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

Overview

Monkeypatch String to feature #encrypt, #decrypt methods.

Instance Method Summary collapse

Instance Method Details

#decryptObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ios7crypt.rb', line 73

def decrypt
  seed = self[0, 2].to_i

  hash = self[2, length - 1]

  pairs = (0 .. (hash.length / 2 - 1)).map do |i|
    hash[i * 2, 2].to_i(16)
  end

  decrypted = (0 .. (pairs.length - 1)).map do |i|
    IOS7Crypt::XLAT[(seed + i) % IOS7Crypt::XLAT.length] ^ pairs[i]
  end

  decrypted.map { |e| e.chr }.join('')
end

#encryptObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ios7crypt.rb', line 60

def encrypt
  seed = rand(16)

  hash = (0 .. (length - 1)).map do |i|
    IOS7Crypt::XLAT[(seed + i) % IOS7Crypt::XLAT.length] ^ self[i].ord
  end

  format('%02d', seed) + hash.map do |e|
    format('%02x', e)
  end.join('')
end