The problem is that delta can be both positive and negative.Keya wrote:aw, i thought i was already accounting for delta=0, my bad! i try again
When delta = -1 and you add 1, you end up with 0.
The problem is that delta can be both positive and negative.Keya wrote:aw, i thought i was already accounting for delta=0, my bad! i try again
Code: Select all
Structure Str
StructureUnion
c.c
b.b[0]
EndStructureUnion
EndStructure
Procedure SNIB(*Str.Str)
Protected i
While *Str\c
If *Str\c <> $0A And *Str\c <> $A0 And *Str\c <> $0D And *Str\c <> $D0
For i = 0 To SizeOf(Character) - 1
*Str\b[i] = (*Str\b[i] >> 4 & $0F) | (*Str\b[i] << 4 & $F0)
Next
EndIf
*Str + SizeOf(Character)
Wend
EndProcedure
Text$ = "Ћирилица"
Debug Text$
SNIB(@Text$)
Debug Text$
SNIB(@Text$)
Debug Text$
Code: Select all
Procedure.c RolChar(c.c, n)
!movzx ecx, byte [p.v_n]
CompilerIf #PB_Compiler_Unicode
!movzx eax, word [p.v_c]
!rol ax, cl
CompilerElse
!movzx eax, byte [p.v_c]
!rol al, cl
CompilerEndIf
ProcedureReturn
EndProcedure
Procedure Encode(*String.Character, i = 0)
Protected.c c
While *String\c
i + 1 : c = -RolChar(*String\c, i + c)
Swap *String\c, c : *String + SizeOf(Character)
Wend
EndProcedure
Procedure Decode(*String.Character, i = 0)
Protected.c c
While *String\c
i + 1 : c = RolChar(-*String\c, -(i + c))
*String\c = c : *String + SizeOf(Character)
Wend
EndProcedure
S.s = "This is a test string 123"
Encode(@S, 3)
Debug S
Decode(@S, 3)
Debug S
Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Macro rbx : ebx : EndMacro
Macro rdx : edx : EndMacro
Macro rsi : esi : EndMacro
CompilerEndIf
Procedure EncodeU(*String, i = 0)
EnableASM
mov rdx, *String
mov eax, [p.v_i]
push rbx
push rsi
sub esi, esi
!encode_u:
add eax, 1
lea ecx, [esi + eax]
movzx ebx, word [rdx]
add rdx, 2
mov esi, ebx
rol bx, cl
neg bx
mov [rdx - 2], bx
!jnz encode_u
pop rsi
pop rbx
DisableASM
EndProcedure
Procedure DecodeU(*String, i = 0)
EnableASM
mov rdx, *String
mov eax, [p.v_i]
push rbx
sub ebx, ebx
!decode_u:
add eax, 1
lea ecx, [ebx + eax]
movzx ebx, word [rdx]
add rdx, 2
neg bx
ror bx, cl
mov [rdx - 2], bx
!jnz decode_u
pop rbx
DisableASM
EndProcedure
S.s = "This is a test string 123"
EncodeU(@S, 3)
Debug S
DecodeU(@S, 3)
Debug S
And yet I notice you still throw nibble swapping into the hat...another example of bit shifting.you guys are way overthinking this.
You are right that it shows a pattern.Bo Marchais wrote:Very nice. One of the principal weaknesses of this method (and any simple xor based method) is that a string of repeating spaces or even a common/known phrase will render a pattern that can be tested for.
Code: Select all
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
Macro rbx : ebx : EndMacro
Macro rdx : edx : EndMacro
Macro rsi : esi : EndMacro
CompilerEndIf
Procedure EncodeU(*String, i = 0)
EnableASM
mov rdx, *String
mov ecx, [p.v_i]
push rbx
push rsi
sub esi, esi
!mov eax, 0xace1
!ror ax, cl
!encode_u:
!shr eax, 1
!jnc encode_u0
!xor eax, 0x80200003
!encode_u0:
lea ecx, [esi + eax]
movzx ebx, word [rdx]
add rdx, 2
mov esi, ebx
rol bx, cl
neg bx
mov [rdx - 2], bx
!jnz encode_u
pop rsi
pop rbx
DisableASM
EndProcedure
Procedure DecodeU(*String, i = 0)
EnableASM
mov rdx, *String
mov ecx, [p.v_i]
push rbx
sub ebx, ebx
!mov eax, 0xace1
!ror ax, cl
!decode_u:
!shr eax, 1
!jnc decode_u0
!xor eax, 0x80200003
!decode_u0:
lea ecx, [ebx + eax]
movzx ebx, word [rdx]
add rdx, 2
neg bx
ror bx, cl
mov [rdx - 2], bx
!jnz decode_u
pop rbx
DisableASM
EndProcedure
S.s = Space(32)
EncodeU(@S, 3)
ShowMemoryViewer(@S, StringByteLength(S))
There's obviously a lot of C3 therewalbus wrote:This is a shot generated with the code above, for search pattern