Hey, I was wondering if you could debug this program. It won't let me xor the string with a DWORD:
NOTE: The Irvine32 include file has some called functions that I used. WriteString write the contents of edx to the console. ReadInt reads a number into eax.

If you need the include and lib files, just ask.


INCLUDE Irvine32.inc

.data

EnterKey BYTE 'Please enter a security key between 1 and 255: ',0
EnterText BYTE 'Please enter your string: ',0
Divider BYTE '-------------------------------------------------------',0
CryptedText BYTE 'Encrypted string: ',0
DecryptedText BYTE 'Decrypted string: ',0
Buffer BYTE 128 dup(0)
BufferSize DWORD ?
CryptKey DWORD ?
.code

start PROC

call GetCryptKey
call GetString
call CryptString
mov edx,OFFSET CryptedText
call ShowMsg
call DecryptString
mov edx,OFFSET DecryptedText
call ShowMsg

exit
start ENDP

GetCryptKey PROC
mov edx,OFFSET EnterKey
call WriteString
call ReadInt
mov CryptKey,eax
ret

GetCryptKey ENDP

GetString PROC
pushad
mov edx,OFFSET EnterText
call WriteString
mov ecx,128
mov edx,OFFSET Buffer
call ReadString
mov BufferSize,eax
call Crlf
popad
ret

GetString ENDP

CryptString PROC
mov ecx,BufferSize
mov esi,0
@1:
xor buffer[esi],CryptKey
inc esi
loop @1
ret

CryptString ENDP

ShowMsg PROC

call WriteString
mov edx,offset buffer
call WriteString
call Crlf
call Crlf
ret

ShowMsg ENDP

DecryptString PROC

mov ecx,BufferSize
mov esi,0
@2:
xor buffer[esi],CryptKey
inc esi
loop @2
ret

DecryptString ENDP
END start
Posted on 2003-06-24 16:21:43 by psyphen
xor buffer[esi],CryptKey

you cannot use memory addresses as both source and destination.
Posted on 2003-06-24 17:01:07 by Tola
In addition, you want to XOR each byte with a byte.
mov eax,CryptKey

xor buffer[esi],al

Raymond
Posted on 2003-06-24 19:21:43 by Raymond
Please never use the words "xor" and "encryption" in the same sentence again.
Posted on 2003-06-24 19:55:26 by Sephiroth3
Alright, so can someone fix it and make it work for me?
Posted on 2003-06-24 22:23:47 by psyphen
Hi,

You can use this, it takes a string inside a 256 byte buffer and writes it back to a 256 byte buffer. The key can be a string of any length. Instead of operating on the byte level it does dword chunks and rotates the bits a little so that each character doesn't necessarily output the same character in the buffer. It's not secure by any means, it's barely enough to be called encryption but for simple stuff it's what I use.

All buffers (except lpKeyString are 256 bytes. For different sizes change the 64 to SIZE/4)

GenKey proc uses edi esi lpKeyString:DWORD

invoke StrLen,lpKeyString
mov edi,0
mov ecx,eax
mov esi,lpKeyString

.REPEAT
push ecx
dec ecx
mov eax,[esi+ecx]
add edi,eax
pop ecx
.UNTILCXZ
clc
mov Key,edi
ret

GenKey ENDP

EncryptString proc uses edi esi lpDataString:DWORD, CryptKey:DWORD, lpOutString:DWORD

mov ecx,64
mov edi,lpOutString
mov esi,lpDataString

.REPEAT
push ecx
dec ecx
mov eax,[esi+ecx*4]
rol eax,6
xor eax,CryptKey
ror eax,5
mov [edi+ecx*4],eax
pop ecx
.UNTILCXZ

ret
EncryptString ENDP

DecryptString proc uses edi esi lpDataString:DWORD, CryptKey:DWORD, lpOutString:DWORD

mov ecx,64
mov edi,lpOutString
mov esi,lpDataString

.REPEAT
push ecx
dec ecx
mov eax,[esi+ecx*4]
rol eax,5
xor eax,CryptKey
ror eax,6
mov [edi+ecx*4],eax
pop ecx
.UNTILCXZ

ret

DecryptString ENDP
Posted on 2003-06-24 23:27:59 by donkey

Please never use the words "xor" and "encryption" in the same sentence again.

Agreed

Try my tean :)
Use it like
invoke teanencode, addr data, addr key
invoke teandecode, addr encrypteddata, addr key
Please note that the key size is 128 bit and the data size is 64 bit.


teanencode:
limit equ 0E6D5C622h;lower 32bit of 32*delta
push ebx
push esi
push edi
mov ecx,[esp+4+3*4];64 data
mov esi,[esp+8+3*4];128 bit key
mov edx,[ecx+4];z
mov ecx,[ecx];y
xor eax,eax
@@:
mov ebx,edx
shl ebx,4
mov edi,edx
shr edi,5
xor ebx,edi
add ebx,edx
xor ebx,eax
mov edi,eax
and edi,3
; lea edi,[esi+edi*4]
; add ebx,[edi]
add ebx,[esi+edi*4];y+=(z<<4 ^ z>>5) + z^sum + key[sum & 3]
add ecx,ebx
add eax,9e3779b9h ;sum += delta
mov ebx,ecx
shl ebx,4
mov edi,ecx
shr edi,5
xor ebx,edi
add ebx,ecx
xor ebx,eax
mov edi,eax
shr edi,11
and edi,3
; lea edi,[esi+edi*4]
; add ebx,[edi]
add ebx,[esi+edi*4];z+=(y<<4 ^ y>>5) + y^sum + key[sum>>11 & 3]
add edx,ebx
cmp eax,limit
jnz @B
mov edi,[esp+4+3*4]
mov dword ptr[edi],ecx
mov dword ptr[edi+4],edx
pop edi
pop esi
pop ebx
ret 8

teandecode:
push ebx
push esi
push edi
mov eax,limit
mov ecx,[esp+4+3*4]
mov esi,[esp+8+3*4]
mov edx,[ecx+4];z
mov ecx,[ecx];y
@@:
mov ebx,ecx
shl ebx,4;z-=(y<<4 ^ y>>5) + y^sum + key[sum>>11 & 3]
mov edi,ecx
shr edi,5
xor ebx,edi
add ebx,ecx
xor ebx,eax
mov edi,eax
shr edi,11
and edi,3
; lea edi,[esi+edi*4]
; add ebx,[edi]
add ebx,[esi+edi*4]
sub edx,ebx
sub eax,9e3779b9h;sum -= delta
mov ebx,edx
shl ebx,4
mov edi,edx
shr edi,5
xor ebx,edi ;y-=(z<<4 ^ z>>5) + z^sum + key[sum & 3]
add ebx,edx
xor ebx,eax
mov edi,eax
and edi,3
; lea edi,[esi+edi*4]
; add ebx,[edi]
add ebx,[esi+edi*4]
sub ecx,ebx
test eax,eax
jnz @B
mov edi,[esp+4+3*4]
mov dword ptr[edi],ecx
mov dword ptr[edi+4],edx
pop edi
pop esi
pop ebx
ret 8
Posted on 2003-06-24 23:49:16 by roticv
Hi Roticv,

Did you derive that from the "tiny encryption algorithm" by David Wheeler and Roger Needham ? I use an algo very similar by them for any place that I need decent encryption and that looks alot like it.
Posted on 2003-06-25 00:06:19 by donkey
Hi psyphen,

This is the best source I have found for info about encryption and algorithms for just about any type of encryption. You might want to take a look there are many MASM implementations:

http://packetstormsecurity.org.pk/crypt/


There are a few links that require that you are in the US or Canada in order to access them. Various hard encryption algos source are not allowed out of North America. :rolleyes:

disclaimer on page :

If you are outside the United States or Canada, or if you are on the US DOC shitlist, then do not download any of this software.
Posted on 2003-06-25 00:16:50 by donkey
There are 3 versions of tea (tea, xtea and tean) if I recall correctly.

Some tiny enryption algorithm links:
http://www.cix.co.uk/~klockstone/xtea.pdf
http://cypher.cyber.brad.ac.uk/tea/
http://www.ftp.cl.cam.ac.uk/ftp/papers/djw-rmn/djw-rmn-tea.html

This is the best source I have found for info about encryption and algorithms for just about any type of encryption. You might want to take a look there are many MASM implementations:

Many? They look more like c code to me. :rolleyes:

Anyway I wonder why there a disclaimer on the site. Seems like aes candiates could be found on www.rsa.com through there is something wrong with the link to the source code. However it is possible to download the pdf and implenent your own. :)
Posted on 2003-06-25 00:36:18 by roticv
Thank you all very much.
Posted on 2003-06-25 12:11:32 by psyphen
drocon says hi.
Posted on 2003-07-17 18:25:56 by akcom
He said hi to me today, too. Then he said he was really 1337, etc. The usual :P.
Posted on 2003-07-17 18:34:34 by psyphen
"l33t" enough not to confuse xor (just a bitwise operator) with a decent method of symmetric encryption
Posted on 2003-07-17 20:42:06 by akcom
Haha, I'm new with encryption.
Posted on 2003-07-17 20:56:54 by psyphen