I don't know if somebody did the same but I think this way to handle pointers is very usefull
- similar to C syntax
- clean code (less variables needed)
- that's all
Code: Select all
Structure Bytes
b.b[0]
EndStructure
String.s = "PureBasic"
*p.Bytes = @String
i.l
While *p\b[i]
Debug Chr( *p\b[i] )
i + 1
Wend
Code: Select all
Procedure XorMemory(*Memory.Bytes, MemoryLength.l, *Key.Bytes, KeyLength.l)
Protected XorMemory.l, i.l, j.l
If *Memory And *Key And MemoryLength > 0 And KeyLength > 0
While i < MemoryLength
If j = KeyLength : j = 0 : EndIf
*Memory\b[i] ! *Key\b[j]
;the two lines above could also be wrote this way :
;*Memory\b[i] ! *Key\b[i % KeyLength]
;so the j variable becomes useless
i + 1
j + 1
Wend
XorMemory = #True
EndIf
ProcedureReturn XorMemory
EndProcedure
;-test of the procedure
string.s = "a try of the xor width the 'array pointer' trick"
key.s = "this is the xor key"
length = Len(string) ;it may change after xor
XorMemory(@string, length, @key, Len(key))
Debug string
XorMemory(@string, length, @key, Len(key))
Debug string
