I needed this recently for a toy I am playing with. Note that the three algos require a pad at least as long as the data to be encrypted and while the example is written using alphabetical characters, it is designed to work on the full binary range.
IF 0 ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Build this template with "CONSOLE ASSEMBLE AND LINK"
ENDIF ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
include \masm32\include\masm32rt.inc
rolbytes PROTO :DWORD,:DWORD,:DWORD
rorbytes PROTO :DWORD,:DWORD,:DWORD
xorbytes PROTO :DWORD,:DWORD,:DWORD
.data?
value dd ?
.data
txt1 db "This is a test",0
pad1 db "qpwoeirutyalsk",0
pad2 db "kslayturieowpq",0
.code
start:
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
call main
inkey
exit
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
main proc
; encrypt
invoke xorbytes,ADDR txt1,ADDR pad1,LENGTHOF txt1 - 1
invoke rolbytes,ADDR txt1,ADDR pad2,LENGTHOF txt1 - 1
; decrypt
invoke rorbytes,ADDR txt1,ADDR pad2,LENGTHOF txt1 - 1
invoke xorbytes,ADDR txt1,ADDR pad1,LENGTHOF txt1 - 1
print ADDR txt1,13,10
ret
main endp
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
xorbytes proc psrc:DWORD,ppad:DWORD,lpad:DWORD
mov eax, [esp+4] ; psrc
mov edx, [esp+8] ; ppad
mov ecx, [esp+12] ; lpad
add eax, ecx
add edx, ecx
neg ecx
push ebx
lbl0:
movzx ebx, BYTE PTR [edx+ecx]
xor [eax+ecx], bl
add ecx, 1
jz lbl1
movzx ebx, BYTE PTR [edx+ecx]
xor [eax+ecx], bl
add ecx, 1
jz lbl1
movzx ebx, BYTE PTR [edx+ecx]
xor [eax+ecx], bl
add ecx, 1
jz lbl1
movzx ebx, BYTE PTR [edx+ecx]
xor [eax+ecx], bl
add ecx, 1
jnz lbl0
lbl1:
pop ebx
ret 12
xorbytes endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
rolbytes proc psrc:DWORD,ppad:DWORD,lpad:DWORD
push ebx
mov eax, [esp+4][4] ; psrc
mov edx, [esp+8][4] ; ppad
mov ebx, [esp+12][4] ; lpad
add eax, ebx
add edx, ebx
neg ebx
lbl0:
movzx ecx, BYTE PTR [edx+ebx]
rol BYTE PTR [eax+ebx], cl
add ebx, 1
jz lbl1
movzx ecx, BYTE PTR [edx+ebx]
rol BYTE PTR [eax+ebx], cl
add ebx, 1
jz lbl1
movzx ecx, BYTE PTR [edx+ebx]
rol BYTE PTR [eax+ebx], cl
add ebx, 1
jz lbl1
movzx ecx, BYTE PTR [edx+ebx]
rol BYTE PTR [eax+ebx], cl
add ebx, 1
jnz lbl0
lbl1:
pop ebx
ret 12
rolbytes endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
rorbytes proc psrc:DWORD,ppad:DWORD,lpad:DWORD
push ebx
mov eax, [esp+4][4] ; psrc
mov edx, [esp+8][4] ; ppad
mov ebx, [esp+12][4] ; lpad
add eax, ebx
add edx, ebx
neg ebx
lbl0:
movzx ecx, BYTE PTR [edx+ebx]
ror BYTE PTR [eax+ebx], cl
add ebx, 1
jz lbl1
movzx ecx, BYTE PTR [edx+ebx]
ror BYTE PTR [eax+ebx], cl
add ebx, 1
jz lbl1
movzx ecx, BYTE PTR [edx+ebx]
ror BYTE PTR [eax+ebx], cl
add ebx, 1
jz lbl1
movzx ecx, BYTE PTR [edx+ebx]
ror BYTE PTR [eax+ebx], cl
add ebx, 1
jnz lbl0
lbl1:
pop ebx
ret 12
rorbytes endp
OPTION PROLOGUE:ProrogueDef
OPTION EPILOGUE:EpilogueDef
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
end start
nice ...