Re: Mimic AES_ENCRYPT and AES_DECRYPT functions in Ruby



Just as a FYI, it works!!!

I forgot about the remains... Take a look at the final incarnation:

def mysql_key(key)
# The algorithm just creates a 16 byte buffer set to all zero,
final_key = "\0" * 16

# Number of string "blocks"
blocks, remain = key.length.divmod(16)

blocks.times do |i|
# For each block
key_block = key[i*16, 16]

# Runs bitwise XOR for each char on string
# and the same char on the block
16.times do |j|
final_key[j] ^= key_block[j]
end
end

if remain
remain.times do |i|
final_key[i] ^= key[(blocks * 16) + i]
end
end

final_key
end

And:

mkey = mysql_key(key)
=> "dp&!{\021?pK?G!8[r."
decrypt(mkey, User.find(1).password)
User Load (2.9ms) SELECT * FROM `users` WHERE (`users`.`id` = 1)
=> "password"

Just BEATIFUL!

Thanks a lot everyone!
--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Re: [newbie] Best way to search for binary data
    ... [string searching ... ... > searching random bytes. ... algorithms are usually preferred to the Knuth-Morris-Pratt algorithm. ... void init_search(const char *string) ...
    (microsoft.public.vc.language)
  • Re: Searching for byte string in a binary file.
    ... > string and data in a binary file. ... > location and length of the longest match from the left side of bstring. ... would be better to make the first argument "const char buf[255]". ... kind of algorithm to use. ...
    (comp.lang.c)
  • Re: optimization pointers?
    ... >def lz: ... > for char in string: ... >LZ78 for multi-GB files, but it seems infeasible. ...
    (comp.lang.python)
  • optimization pointers?
    ... Would anyone care to offer pointers on how the following code ... def lz: ... for char in string: ... about 1.3 hrs to process a 1 MB string. ...
    (comp.lang.python)
  • Re: my cryptogram program
    ... letters in the alphabet). ... def convert_quote: ... if char in original_set: ... BTW, the name make_set is a bit misleading, since the function returns a string... ...
    (comp.lang.python)