forked from KolibriOS/kolibrios
LuhnA - yet another useless program. Just for fun :)
git-svn-id: svn://kolibrios.org@2838 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
6e1fbdb7b4
commit
d51745da57
7
programs/other/luhna/build.bat
Normal file
7
programs/other/luhna/build.bat
Normal file
@ -0,0 +1,7 @@
|
||||
@fasm luhna.asm luhna
|
||||
@kpack luhna
|
||||
@pause
|
||||
|
||||
|
||||
|
||||
|
94
programs/other/luhna/luhna.asm
Normal file
94
programs/other/luhna/luhna.asm
Normal file
@ -0,0 +1,94 @@
|
||||
; LuhnA - Luhn algorithm
|
||||
; by Albom
|
||||
|
||||
use32
|
||||
org 0
|
||||
db 'MENUET01'
|
||||
dd 1
|
||||
dd _start
|
||||
dd _end
|
||||
dd _memory
|
||||
dd _stack
|
||||
dd _param
|
||||
dd 0
|
||||
|
||||
include '../../macros.inc'
|
||||
|
||||
|
||||
align 4
|
||||
_start:
|
||||
|
||||
mov al, [_param]
|
||||
test al, al
|
||||
jz exit
|
||||
|
||||
call luhna
|
||||
xor edx, edx
|
||||
mov ecx, 10
|
||||
div ecx
|
||||
|
||||
test edx, edx
|
||||
jz valid
|
||||
mov ebx, msg_not
|
||||
jmp print
|
||||
valid:
|
||||
mov ebx, msg_valid
|
||||
|
||||
print:
|
||||
mov [notifyapp+2*4], ebx
|
||||
mcall 70, notifyapp
|
||||
|
||||
|
||||
exit:
|
||||
mcall -1
|
||||
|
||||
|
||||
|
||||
|
||||
align 4
|
||||
luhna:
|
||||
xor edx, edx
|
||||
xor ecx, ecx
|
||||
xor eax, eax
|
||||
mov esi, _param
|
||||
@@:
|
||||
lodsb
|
||||
test al, al
|
||||
jz .exit
|
||||
sub al, '0'
|
||||
mov dl, [odd+eax]
|
||||
add ecx, edx
|
||||
lodsb
|
||||
test al, al
|
||||
jz .exit
|
||||
sub al, '0'
|
||||
add ecx, eax
|
||||
jmp @b
|
||||
.exit:
|
||||
mov eax, ecx
|
||||
ret
|
||||
|
||||
align 4
|
||||
msg_not db 'NOT '
|
||||
msg_valid db 'VALID', 0
|
||||
|
||||
align 4
|
||||
odd: db 0, 2, 4, 6, 8, 1, 3, 5, 7, 9
|
||||
|
||||
align 4
|
||||
notifyapp:
|
||||
dd 7
|
||||
dd 0
|
||||
dd 0 ; ¤à¥á á®®¡é¥¨ï
|
||||
dd 0
|
||||
dd 0
|
||||
db '@notify', 0
|
||||
|
||||
|
||||
_end:
|
||||
align 4
|
||||
rb 256
|
||||
_stack:
|
||||
align 4
|
||||
_param rb 256
|
||||
_memory:
|
9
programs/other/luhna/readme.txt
Normal file
9
programs/other/luhna/readme.txt
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
LuhnA - алгоритм Луна (Luhn algorithm) для проверки правильности номера банковской карты.
|
||||
|
||||
Ещё одна бесполезная утилита. Написана в электричке на листе бумаги, для развлечения и разминки мозга.
|
||||
http://ru.wikipedia.org/wiki/Алгоритм_Луна
|
||||
|
||||
================
|
||||
Albom
|
||||
01/07/2012
|
Loading…
Reference in New Issue
Block a user