News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

making and arabic encryption

Started by wiraperkasa, March 17, 2007, 09:07:01 AM

Previous topic - Next topic

wiraperkasa

hello...i'm newbie here....I've been thinking....how to change dis code so that it can encrypt and decrypt back an arabic word...the decryption should not exactly follow the meaning rite...


INCLUDE Irvine32.inc
KEY = 12
BUFMAX = 128

.data
sPrompt BYTE "Enter the plain text: ",0
sEncrypt BYTE "Cipher text:        ",0
sDecrypt BYTE "Decrypted:         ",0
buffer BYTE BUFMAX +1 dup(0)
bufSize DWORD ?

.code
main PROC   

   call InputTheString
   
   
   call TranslateBuffer
   mov edx,OFFSET sEncrypt
   call DisplayMessage
   
   call TranslateBuffer
   mov edx,OFFSET sDecrypt
   call DisplayMessage
   
   exit
   
main ENDP

InputTheString PROC
   pushad
   mov edx,OFFSET sPrompt
   call WriteString
   mov ecx, BUFMAX
   mov edx, OFFSET buffer
   call ReadString
   mov bufSize, eax
   call Crlf
   popad
   ret
InputTheString ENDP

DisplayMessage PROC
   pushad
   call WriteString
   mov edx,OFFSET buffer
   call WriteString
   call Crlf
   call Crlf
   popad
   ret
DisplayMessage ENDP

TranslateBuffer PROC
   pushad
   mov ecx, bufSize
   mov esi,0
L1:
   xor buffer[esi], KEY
   inc esi
   loop L1
   
   popad
   ret
TranslateBuffer ENDP

END main

PBrennick

wiraperkasa,

When you are using an XOR encryptor, the first pass through encrypts the word (phrase). Run it again in exactly the same way and it will decrypt the word (phrase)

Paul
The GeneSys Project is available from:
The Repository or My crappy website

MichaelW

As far as I can tell the program works OK.

Enter the plain text: my other brother darryl

Cipher text:        au,cxdi~,n~cxdi~,hm~~u`

Decrypted:         my other brother darryl

eschew obfuscation

MaynardG_Krebs

I wouldn't use it for anything with security critical needs as it can be decrypted fairly easy.

wiraperkasa

erm..yeah the program works well...it just how to set the decryption so that it will display in arabic words...

sinsi

Light travels faster than sound, that's why some people seem bright until you hear them.

wiraperkasa

hmm..i got it at last...just change the xor code so that it become like this...

L1:
   xor buffer[esi], 65120            ;translate a byte
   inc esi                     ;point to next byte
   loop L1



and for the buffer declaration....change BYTE to DWORD...

buffer DWORD BUFMAX+1 dup(0)



......

Tedd

Unless you're using a codepage encoding, arabic characters will be represented by multiple bytes each (probably just two) - but this is still not a problem as when encrypting you simple treat the data as a string of bytes, it doesn't matter what they're suppsoed to represent. So whether you xor each byte or each character, it does not matter (from a functional perspective.)

One point though:

L1:
   xor buffer[esi], 65120            ;translate a byte
   inc esi                     ;point to next byte
   loop L1


65120 is not a byte - it requires 16 bits (two bytes) - so the next instruction should really be "add esi,2" and not "inc esi"
Though it will still work this way, as long as you decrypt in the same way, but the effect you will get is that the bytes are xor-ed with the xor of the two bytes of the key (except for the very first byte) effectively making your key one byte in length again (value = 158; try it :P)
If you want to generalise the method a little, modify it so that the key can be a string of any length. Then you xor the first byte of the message with the first byte of the key, the second with the second of the key, .... if you reach the end of the key, start at the beginning again, until you reach the end of the message.
No snowflake in an avalanche feels responsible.