Hello,

I am currently looking into hutch`s XorData procs (masm32.lib) ,
but what i am missing there is a conversion from the
encoded stringoutput into a hexvalue.

Reason:
Once i encountered problems in storing encrypted strings
in their "plain" encrypted stringvalue. (Windows somehow
overwrote some special characters while saving them
on CD and the encryption was lost!!! )


Can someone please post me a short code how to convert
string into hex and hex into string. (using MASM)

regards

Ranma
This message was written entirely in my Messageboard Editor v4.0
Posted on 2003-11-11 06:25:37 by Ranma_at
I could not resist it so let me say it here. Xor encryption is weak. I have some hextostring routine, but have no stringtohex routine. Here's it:

dwtoh:

push eax
push ecx
mov ecx, 32
@@:
sub ecx, 4
jz @F
mov eax, edx
shr eax, cl
or eax, eax
jz @B
@@:
mov eax, edx
shr eax, cl
and eax, 01111y
cmp al, 0Ah
sbb al,69h
das
stosb
sub ecx, 4
jns @B
mov byte ptr[edi], 0
pop ecx
pop eax
retn


You will need to edit it because it is very specific (passing parameters via registers etc).
Posted on 2003-11-11 07:08:45 by roticv
Hi roticv,

Thanks for your fast reply.

I dont know much about encryption and its math, cause i am just a database programmer, but sometimes i have to
store some usernames/passwords somehow.

In VB i use Blowfish, Serpent256, DES, Skipjack, 2fish blah blah ...
In assembler hutch`s XorData is the only working code i found till now ( there are some others on this forum, but
without how-to-implement-instruction )

Maybe you have some better proc i can use, then please post it.

regards,

Ranma
This message was written entirely in my Messageboard Editor v4.0
Posted on 2003-11-11 07:18:34 by Ranma_at
Here's my implementation of tea:



teadecode:
mov edi, [esp+4]
mov esi, [esp+8]
mov ebx, [edi]
mov ecx, [edi+4]
mov eax, 0C6EF3720h ; eax = 20h * delta
@@:
mov edx, ebx
shl edx, 4
sub ecx, edx
mov edx, [esi+8]
xor edx, ebx
sub ecx, edx
mov edx, ebx
shr edx, 5
xor edx, eax
sub ecx, edx
sub ecx, [esi+0Ch]
mov edx, ecx
shl edx, 4
sub ebx, edx
mov edx, [esi]
xor edx, ecx
sub ebx, edx
mov edx, ecx
shr edx, 5
xor edx, eax
sub ebx, edx
sub ebx, [esi+4]
sub eax, 9E3779B9h
jnz @B
mov [edi], ebx
mov [edi+4], ecx
retn 8

teaencode:
mov edi, [esp+4]
mov esi, [esp+8]
mov ebx, [edi]
mov ecx, [edi+4]
xor eax, eax
@@:
add eax, 9E3779B9h
mov edx, ecx
shl edx, 4
add ebx, edx
mov edx, [esi]
xor edx, ecx
add ebx, edx
mov edx, ecx
shr edx, 5
xor edx, eax
add ebx, edx
add ebx, [esi+4]
mov edx, ebx
shl edx, 4
add ecx, edx
mov edx, [esi+8]
xor edx, ebx
add ecx, edx
mov edx, ebx
shr edx, 5
xor edx, eax
add ecx, edx
add ecx, [esi+0Ch]
cmp eax, 0C6EF3720h
jnz @B
mov [edi], ebx
mov [edi+4], ecx
;add edi, 8
mov byte ptr [edi+8], 0 ;important -> something new
retn 12

Posted on 2003-11-11 07:57:05 by roticv
Just about all the numeric conversions you'll ever want to use can be found in the HLA Standard Library (versions for HLA and MASM32 users). You can grab a copy of this library at

http://webster.cs.ucr.edu/Page_AdvAsm/0_HLA4MASM.html

Cheers,
Randy Hyde
Posted on 2003-11-11 13:34:34 by rhyde
thanks Randy,

I ll go and check this
Posted on 2003-11-12 04:07:21 by Ranma_at
hex2ascii:

push ebx
mov ebx,eax
ror ebx,04h
and bl,0fh
cmp bl,09h
ja $+07h
add bl,30h
jmp $+05h
add bl,37h
and al,0fh
cmp al,09h
ja $+06h
add al,30h
jmp $+04h
add al,37h
mov ah,bl
xchg ah,al
pop ebx
ret

Ascii2Hex:
push esi
mov al,
cmp al,39h
ja $+09h
sub al,30h
shl al,04h
jmp $+0dh
test al,020h
jz $+04h
sub al,20h
sub al,37h
shl al,04h
mov ah,al
inc esi
mov al,
cmp al,39h
ja $+06h
sub al,30h
jmp $+0ah
test al,020h
jz $+04h
sub al,20h
sub al,37h
or al,ah
pop esi
ret
Posted on 2003-11-15 01:43:33 by mrgone
here is my ugly code snippet to convert String into hex (DWORD Size only)
; inline asm Snippet



DWORD StringToDword(char *Text)
{
DWORD AsmDwordNum=(DWORD)Text;
DWORD DwordNum=0;

_asm{
PUSHAD
PUSHF
XOR ECX,ECX
XOR EAX,EAX
XOR EDI,EDI
MOV EDI,8H
MOV ESI,AsmDwordNum // ESI Points to the string
_start:
MOV CL,[ESI]
CMP CL,30H
JL _lower
CMP CL,39H
JG _upper
SUB CL,30H
JMP _jmp1
_upper:
SUB CL,37H
JMP _jmp1
_lower:
_jmp1:
ADD EAX,ECX
CMP EDI,1
JZ _out
SHL EAX,4H
_out:
INC ESI
DEC EDI
JNZ _start
MOV DwordNum,EAX
POPF
POPAD
}

return DwordNum;
}
Posted on 2003-11-15 03:57:53 by wizzra