This code only encrypts a peice of the string and not the whole thing.[/code]
At a guess, that is because the unencrypted characters match (key=value) and so the test avoids this otherwise there would be a null (0) terminator embedded into the middle of the string.
Procedure.s selfE(src.s,en.l)
k1=Len(src)
If k1>0
*p=@src
k2=PeekB(*p) & $FF
r=k1 ! k2
If r<>0 : PokeB(*p,r) : EndIf
For i=2 To Len(src)
*p+1
If en : k1=PeekB(*p-1) & $FF : Else : k1=k2 : EndIf
k2=PeekB(*p)
r=k1 ! k2
If r<>0 : PokeB(*p,r) : EndIf
Next
EndIf
ProcedureReturn src
EndProcedure
w.s="Wooo! Hooo! This is self encrypting"
x.s=selfE(w,#True)
y.s=selfE(x,#False)
Debug w
Debug x
Debug y
The self-encrypting code doesn't seem to work, my debug output is:
Wooo! Hooo! This is self encrypting
瑴ᬛ瑴ᬛ㨺ᨚ剒㴽剒㴽ᰜ㰼桨桨ā牲剒;s self encrypting
瑗᭯瑯᭯㨡ᨠ剈㵯副㵯ᰡ㰠桔桨ũ牳删is self encrypting
I'm using 6.04LTS Windows x86, if that is important.
Any ideas?
If I'm reading the code correctly, this seems to encrypt each character using the previous character, and stores the starting character required with the encrypted string?