1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| format PE console 4.0
include 'include/win32a.inc'
section '.text' code readable executable
entry start
start:
stdcall xor_cipher, buf1, 32, buf2 ; Chiffre buf1 -> buf2
stdcall xor_cipher, buf2, 32, buf3 ; Déchiffre buf2 -> buf3
cinvoke printf, format_str, buf3 ; Affiche le résultat
invoke ExitProcess, 0
; ------------------------------------------------------------
; XOR cipher : applique un XOR entre chaque byte d'entrée
; et la clé issue de la table (en boucle)
; inbuf = source
; len = longueur
; outbuf = destination
; ------------------------------------------------------------
proc xor_cipher inbuf:DWORD, len:DWORD, outbuf:DWORD
push esi edi ecx eax ebx
mov esi, [inbuf] ; Source
mov edi, [outbuf] ; Destination
mov ecx, [len] ; Taille à traiter
xor ebx, ebx ; Index dans la table
@@:
mov al, [esi] ; Lire byte source
mov dl, [table + ebx] ; Lire octet de la table
xor al, dl ; Chiffrement XOR
mov [edi], al ; Stocker résultat
inc esi
inc edi
inc ebx
cmp byte [table + ebx], 0
jne .no_reset
xor ebx, ebx ; Recommence depuis le début de la table
.no_reset:
dec ecx
jnz @b
pop ebx eax ecx edi esi
ret
endp
section '.data' data readable writeable
buf1 db 'la petite maison dans la prairie', 0
buf2 rb 256
buf3 rb 256
table db 0x7D, 0x72, 0x6F, 0xD7, 0x84, 0x09, 0xB2, 0x18,\
0x12, 0xD7, 0x43, 0xF3, 0x33, 0x1B, 0xA4, 0x6F, 0
format_str db 'Résultat : %s', 13, 10, 0
section '.idata' import data readable writeable
library msvcrt, 'msvcrt.dll',\
kernel32, 'kernel32.dll'
import msvcrt,\
printf, 'printf'
import kernel32,\
ExitProcess, 'ExitProcess' |
Partager