Lua to BlitzMax conversion.
BlitzMax Forums/BlitzMax Programming/Lua to BlitzMax conversion.
| ||
Hi! I'm trying to convert some Lua code to BlitzMax but I can't get it to work :/ This is what I've got so far: Lua BlitzMax I've tried almost everything to get it working :P Anyone have a clue? Thank you! :) |
| ||
Could you explain what's wrong and possibly include any global variables you're using in the BMax code as well? Edit: Far as I can tell - and I can't tell much, since I just had a cavity filled and my jaw is aching and the pounding won't stop - but you're forgetting to add 1 to the remainder j. E.g., Scanner = { masked = true; scantime = 0; offset = 0; list = { player="what" }; } function Scanner.mask(text) if not Scanner.masked then return text end local mask = ((string.reverse(Scanner.scantime) + Scanner.offset) % 59) .. Scanner.list["player"] local masked = "" local masklen = #mask Scanner.offset = Scanner.offset + 3 for i=1,#text do local j = (i % masklen) + 1 local k = bit.bxor(string.byte(text, i), string.byte(mask, j)) masked = masked..string.char(k) end return masked end |
| ||
Thanks Nilium, But I'm trying to convert the Lua code to BlitzMax, not the other way around ^^ I just wanted to see if anyone could see a problem with my code just by looking at it. My code works for the first characters in a string, but then it just gets strange. One strange thing I can't get my head around is that in the Lua function, the Masked variable, which will get returned is longer than the Text variable which is what you input. So I guess that my StringToByte function doesn't work exactly as the Lua function String.Byte does :P |
| ||
type TCrypt Global ScanTime:Int = 48 Global Offset:Int = 0 Global Enabled:Int = 1 Function Crypt:String( Text:String ) If Enabled = 0 Return Text EndIf Local Mask:String = ((Int( ReverseString( ScanTime ) ) + Offset) Mod 59) + TChar.Name Local Masked:String = "" Local TextLen:Int = Len( Text ) Local MaskLen:Int = Len( Mask ) Offset = Offset + 3 For Local I:Int = 1 To TextLen Local J:Int = I Mod MaskLen Local K:Int = StringToByte( Text, I, I ) ~ StringToByte( Mask, J, J ) Print K + " " + Mid( Text, I, 1 ) + " " + I + " " + Chr(K) Masked = Masked + Chr(K) Next Return Masked End Function Function ReverseString:String( Str:String ) Local N:Int Local RS:String For N = 0 To Str.length - 1 RS:+ Chr( Str[ Str.Length -1 -N ] ) Next Return RS EndFunction Function StringToByte:Int( Text:String, Pos:Int, Pos2:Int ) Local ByteStr:String Local Size:Int = Max( Pos - Pos2, 1 ) For Local X:Int = 1 To Size ByteStr = ByteStr + Asc( Mid( Text, Pos + X - 1, 1 ) ) Next Return Int( ByteStr ) End Function End Type TCrypt.Crypt( "VanderjacktVanderjacktVanderjackt" ) Is supposed to turn out as: "dT8 \n=a\\Q37dWG<\000\r" But it turns out as: "dT8 =ž\Q37›WG< " |