Lock2Key Lua 5
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Lock2Key Lua 5

Started by Meka][Meka, 12 September, 2005, 15:43:08

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Meka][Meka

any chance of a lock2key lua, maybe even using some lib, i've tried to write, but have problems with xor....

language samples: http://66.249.93.104/search?q=cache:mz5rusF3zw8J:dcplusplus.sourceforge.net/wiki/index.php/LockToKey%3Fversion%3D25+dc+locktokey&hl=da

thanks in advance...
Do you know what \'nemesis\' means? A righteous infliction of retribution manifested by an appropriate agent. Personified in this case by an \'orrible cunt... me.



Corayzon

What are u sceeming upto now? ^^

Nuh sorry mate, i checked around and tried a few things, none of them worked.

Its prob not the algorithm, but lua's encoding ;) U want to be using utf7 or 8, cant remember which one

Mardeg

try this:
-- Coded by Mardeg
function bODD(x)
       return x ~= math.floor(x / 2) * 2
end

function bitwise(x, y, bw)
       local c, p = 0, 1
       while x > 0 or y > 0 do
           if bw == "xor" then
               if (bODD(x) and not bODD(y)) or (bODD(y) and not bODD(x)) then
                       c = c + p
               end
           elseif bw == "and" then
               if bODD(x) and bODD(y) then
                       c = c + p
               end
           elseif bw == "or" then
               if bODD(x) or bODD(y) then
                       c = c + p
               end
           end
           x = math.floor(x / 2)
           y = math.floor(y / 2)
           p = p * 2
       end
       return c
end

function nibbleswap(bits)
 	return bitwise(bitwise(bits*(2^4),240,"and"),bitwise(math.floor(bits/(2^4)),15,"and"),"or")
end

function lock2key(lock)
	local key = {}
	table.insert(key,bitwise(bitwise(bitwise(string.byte(lock,1),string.byte(lock,-1),"xor"),string.byte(lock,-2),"xor"),5,"xor"))
	for i=2,string.len(lock),1 do
		table.insert(key,bitwise(string.byte(lock,i),string.byte(lock,i - 1),"xor"))
	end
	local g = {["5"]=1,["0"]=1,["36"]=1,["96"]=1,["124"]=1,["126"]=1}
	for i=1,table.getn(key),1 do
		local b = nibbleswap(rawget(key,i)) 
		rawset(key,i,(g[tostring(b)] and string.format("/%%DCN%03d%%/",b) or string.char(b)))
	end
	return table.concat(key)
end

Meka][Meka

well finally found my way back to the forum, seems it didnt, work but very nice try, i'll see if i can get it working, i actually think its my fault, a socket prob.....

Thanks!  :]
Do you know what \'nemesis\' means? A righteous infliction of retribution manifested by an appropriate agent. Personified in this case by an \'orrible cunt... me.



Mardeg

No problem, although I just did it as an exercise to compare different languages doing the same thing, so never tested the Lua version.

Specific things that may be worth checking are whether:
? arithmetic is allowable inside string.byte(lock,i - 1)
? string.format("/%%DCN%03d%%/",b) is correct
? each table.insert really does add each value to the end of the table
? the code can be optimised down in size without help from plugins or losing readability (this is just so it looks less daunting on the code comparison page: http://wiki.dcpp.net/index.php/LockToKey#Lua_5.0.2B - especially when I see how compact I made the Javascript example, still waiting for someone to make a Firefox extension to test that one.)

bastya_elvtars

QuoteOriginally posted by Mardeg
? arithmetic is allowable inside string.byte(lock,i - 1)
It is.

QuoteOriginally posted by Mardeg
each table.insert really does add each value to the end of the table
It does, unless you explicitly specify the position.
Everything could have been anything else and it would have just as much meaning.

Mardeg

#6
I've noticed that ptokax simply drops the connection without feedback if $Supports is not sent before $Key if that's any help.

SMF spam blocked by CleanTalk