lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2015-04-08 21:18 GMT+02:00 Hisham <h@hisham.hm>:
> On 8 April 2015 at 04:04, Dirk Laurie <dirk.laurie@gmail.com> wrote:

>> math.randomseed(os.clock())
>> function password()  return (("."):rep(32):gsub(".",
>>   function() return string.char(math.random(256)-1) end))
>> end
>>
>> Now make two tables: one containing the original keys
>> and a password for each, the other containing those
>> passwords as keys with the original values.
>>
>> Three times gsub:
>>   the ${var} forms with the first table,
>>   the $var forms with the first table,
>>   the passwords with the second table.
>>
>> If you are scared this might not work, better not use
>> ATMs any more either.
>
> Haha, nice. :) The passwords would have to have some sort of constant
> marker for us to be able to perform the third gsub, right?

Not really. One is searching for exact 32-byte strings. But there
is a bug. I forgot that gsub is never raw.

So the passwords must not contain magic characters or backslash, i.e.
byte values 36 37 40 41 42 43 45 46 63 91 92 93 94.  Exercise for the
reader to replace "math.random(256)-1" by something better.