|
Post by cntkillme on Jun 16, 2017 9:10:41 GMT
--- CHALLENGE 3 --- -- Author: cntkillme -- Goal: call TestPin with a pin such that it returns true. -- Do not alter the TestPin local or your solution is invalidated. -- Your solution must work in Roblox Studio and in standard Lua 5.1. local TestPin do local _pin = nil local _entered = { } local _tostring, _match = tostring, string.match
local function GeneratePin() _pin = _match(_tostring(function() end), "%x+$") end
function TestPin(pin) table.insert(_entered, pin or 0) if #_entered <= 3 then -- 3 tries return pin == _pin elseif #_entered == 4 then print("No more tries left, the pin was: " .. _pin) GeneratePin() -- extra security return false end return false end
GeneratePin() end -- DO NOT EDIT ANYTHING ABOVE THIS LINE print(TestPin("12345678"))
|
|
|
Post by Bit on Jun 16, 2017 20:41:11 GMT
local TestPin do local _pin = nil local _entered = { } local _tostring, _match = tostring, string.match
local function GeneratePin() _pin = _match(_tostring(function() end), "%x+$") end
function TestPin(pin) table.insert(_entered, pin or 0) if #_entered <= 3 then -- 3 tries return pin == _pin elseif #_entered == 4 then print("No more tries left, the pin was: " .. _pin) GeneratePin() -- extra security return false end return false end
GeneratePin() end -- DO NOT EDIT ANYTHING ABOVE THIS LINE local capture local setTo=4 table=setmetatable({insert=function(x) for i,v in pairs(x) do x[i]=nil end -- wipe for i=1,setTo do x[i]=1 --fill to setTo number of indexes end end},{__index=table}) local oldprint=print print=function(...) local x={...} x=x[1] if x and type(x)=="string" and capture==nil then capture=x:gsub("No more tries left, the pin was: ","") error() --:] RIP Your extra security. end oldprint(...) end pcall(TestPin) setTo=1 print(TestPin(capture))
|
|
john
New Member
Posts: 11
|
Post by john on Jun 16, 2017 21:55:08 GMT
well bit got the "right" solution but the allocator behavior doesn't make it hard to come close with something more naive local TestPin do local _pin = nil local _entered = { } local _tostring, _match = tostring, string.match
local function GeneratePin() _pin = _match(_tostring(function() end), "%x+$") end
function TestPin(pin) table.insert(_entered, pin or 0) if #_entered <= 3 then -- 3 tries return pin == _pin elseif #_entered == 4 then print("No more tries left, the pin was: " .. _pin) GeneratePin() -- extra security return false end return false end
GeneratePin() end -- DO NOT EDIT ANYTHING ABOVE THIS LINE
local base, string_format, answer = tonumber (string.match (tostring (function() end), '%x+$'), 16), string.format, answer table.insert = function(...) end for i = base - 2^16, base, 4 do if TestPin (string_format ('%x', i)) then answer = string_format ('%x', i) break end end print (TestPin (answer), answer)[/div][div]
[/div] [/spoiler] [/code][/spoiler][/div]
edit: ok the bbcode editor hates me
|
|
|
Post by Bit on Jun 17, 2017 0:49:41 GMT
IKR, bbcode editor hates us. Plus that wouldn't work on studio without the metatable h4x or making a new table table (redundant, tableception), only in vanilla Lua if that. Even then, I also thought of making it start bruteforcing down from a memory location made the same way, but I didn't have the patience.
|
|
john
New Member
Posts: 11
|
Post by john on Jun 17, 2017 4:28:54 GMT
IKR, bbcode editor hates us. Plus that wouldn't work on studio without the metatable h4x or making a new table table (redundant, tableception), only in vanilla Lua if that. Even then, I also thought of making it start bruteforcing down from a memory location made the same way, but I didn't have the patience. can't run studio (i don't have windows or mac os ), but why wouldn't it work?
|
|
|
Post by cntkillme on Jun 17, 2017 8:05:21 GMT
It's unstable. There is no guarantee that a table created after another table will be anywhere near the previous table. Sure you could attempt to brute-force it but is it reliable and can you even guarantee it will work half the time? Well if you use a large enough displacement then perhaps you can be more certain but it becomes increasingly slow and, well, ugly.
I did a lot of testing before using this method and sometimes a table created literally right after another table (2 NEWTABLE instructions right after each other) were more than a KB away from each other.
|
|
john
New Member
Posts: 11
|
Post by john on Jun 17, 2017 17:40:26 GMT
It's unstable. There is no guarantee that a table created after another table will be anywhere near the previous table. Sure you could attempt to brute-force it but is it reliable and can you even guarantee it will work half the time? Well if you use a large enough displacement then perhaps you can be more certain but it becomes increasingly slow and, well, ugly. I did a lot of testing before using this method and sometimes a table created literally right after another table (2 NEWTABLE instructions right after each other) were more than a KB away from each other. 1kb is just 1024 bytes. that's basically nothing, especially when you aren't incrementing i in the loop by 1, but by 4 or 8.
|
|
|
Post by cntkillme on Jun 17, 2017 22:41:21 GMT
That's just from 1 example, and that's on Windows. It can easily vary from platform to platform and it just becomes an ugly solution when you have to guess a ton of times for no guaranteed win. I guess I could implement some sort of "attempts" variable like I did in the other challenges (so it stops at 10 calls and you'd have to restart) but eh I'll do that in later challenges. If you can successfully show your brute-force method works at least 49 out of 50 times then it's good enough for this challenge.
|
|
john
New Member
Posts: 11
|
Post by john on Jun 18, 2017 20:39:19 GMT
That's just from 1 example, and that's on Windows. It can easily vary from platform to platform and it just becomes an ugly solution when you have to guess a ton of times for no guaranteed win. I guess I could implement some sort of "attempts" variable like I did in the other challenges (so it stops at 10 calls and you'd have to restart) but eh I'll do that in later challenges. If you can successfully show your brute-force method works at least 49 out of 50 times then it's good enough for this challenge. ran on linux and worked, ran on my windows vm and worked.
-_----__-
but i'll concede that it was pretty nasty and not the kind of solution that should've been done
|
|
|
Post by cntkillme on Jun 19, 2017 1:36:15 GMT
Good enough for me. Although next challenge I'll probably make sure to only allow a certain amount of attempts.
|
|