;Secret Stamp
;For FreeBSD/MacOS X
;By Batareya 2016
section .bss
filename resb 50
filename2 resb 50
keyes resb 31
bytee resb 1
descr1 resd 1
descr2 resd 1
kolvo resd 1
section .data
msg1 db "Vvedite ishodniy fail (50 max)", 10
msg1_len equ $-msg1
msg2 db "Vvedite fail dlya shifrovaniya (50 max)",10
msg2_len equ $-msg2
msg3 db "Vvedite klu4 shifrovaniya (30 max)",10
msg3_len equ $-msg3
section .text
global start
start:
push dword msg1_len
push dword msg1
push dword 1
mov eax,4
push eax
int 80h
add esp,16
mov edi,filename
cld
vod:
push dword 1
push dword bytee
push dword 0
mov eax,3
push eax
int 80h
add esp,16
cmp byte [bytee],10
je vvodi
mov al,byte [bytee]
stosb
jmp vod
vvodi:
xor eax,eax
stosb
push dword 0666q
push dword 0
push dword filename
mov eax,5
push dword eax
int 80h
add esp,16
mov dword [descr1],eax
push dword msg2_len
push dword msg2
push dword 1
mov eax,4
push eax
int 80h
add esp,16
mov edi,filename2
cld
vod2:
push dword 1
push dword bytee
push dword 0
mov eax,3
push eax
int 80h
add esp,16
cmp byte [bytee],10
je vvodi2
mov al,byte [bytee]
stosb
jmp vod2
vvodi2:
xor eax,eax
stosb
push dword 0666q
push dword 601h
push dword filename2
mov eax,5
push dword eax
int 80h
add esp,16
mov dword [descr2],eax
push dword msg3_len
push dword msg3
push dword 1
mov eax,4
push eax
int 80h
add esp,16
mov edi,keyes
cld
vod3:
push dword 1
push dword bytee
push dword 0
mov eax,3
push eax
int 80h
add esp,16
cmp byte [bytee],10
je vvodi3
mov al,byte [bytee]
stosb
jmp vod3
vvodi3:
xor eax,eax
stosb
xor ecx,ecx
mov esi,keyes
xor eax,eax
vozvrat:
lodsb
cmp al,0
je dalee
add ecx,1
jmp vozvrat
dalee:
mov dword[kolvo],ecx
xor eax,eax
xor ebx,ebx
xor ecx,ecx
cycl:
mov eax,ecx
div dword [kolvo]
mov ebx,edx
push dword 1
push bytee
push dword [descr1]
mov eax,3
push eax
int 80h
add esp,16
mov dl,byte [bytee]
cmp eax,0
je exit
xor dl,byte [keyes+ebx]
mov [bytee],dl
;--[
push dword 1
push dword bytee
push dword [descr2]
mov eax,4
push eax
int 80h
add esp,16
;--]
add ecx,1
jmp cycl
exit:
;----
push dword 0
mov eax,1
push eax
int 80h