The copy-paste of the page "Luhn Number Checksum" or any of its results, is allowed as long as you cite dCode!Ĭite as source (bibliography): Luhn Number Checksum on dCode. Except explicit open source licence (indicated Creative Commons / free), the "Luhn Number Checksum" algorithm, the applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or the "Luhn Number Checksum" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) and all data download, script, or API access for "Luhn Number Checksum" are not public, same for offline use on PC, mobile, tablet, iPhone or Android app! Ask a new question Source codeĭCode retains ownership of the "Luhn Number Checksum" source code. ret Run the 'luhn' routine on the argument given on the MS-DOS command line.No, in the magnetic strip is the information of the credit card completed by a different checksum control: the Longitudinal redundancy check. out: cld Clean up: clear direction flag, pop es and restore ES. out stc Set carry (remainder wasn't 0, the test failed). done: xor ah, ah Divide total by 10 mov al, bl div dh and ah, ah If remainder 0, then return with carry clear jz. done No more characters = stop lodsb Get number in even position sub al, dl Subtract ASCII zero add al, al Multiply by two xor ah, ah AX = AL div dh Divide by 10 AL=quotient, AH=remainder add al, ah Add the two "digits" together add bl, al Add to total loop. Fill in the box below to have it instantly computed. loop: lodsb Get number in odd position sub al, dl Subtract ASCII zero add bl, al Add to total dec cx One fewer character jz. Calculate check digit using the Luhn algorithm. done Empty string = stop dec si We don't need the zero itself std Seek backwards. push ds "REP DS:SCASB" is a bad idea, because the 286 has a pop es bug where it "forgets" the 2nd prefix if interrupted! mov di, si DI = pointer xor ax, ax Zero to test against xor bl, bl BL = S1+S2 mov dx, 0 A30h DH = 10 (divisor), DL = '0' (ASCII zero) xor cx, cx Set counter to 65535 dec cx cld Seek forwards repnz scasb Find zero dec di SCASB goes one byte too far xchg si, di SI = pointer, DI = end (or rather, beginning) mov cx, si CX = counter sub cx, di jcxz. luhn: push es Keep original ES, and set ES=DS so SCASB can be used. Returns with carry clear if the string passes, carry set if the string fails. text jmp demo Check whether the 0-terminated string at DS:SI passes the Luhn test. Run the routine on the argument given on the CP/M command lineĭemo: lxi h,80h Zero-terminate the command line argumentīits org 100 h section. Rc If carry, it is not divisible, return (carry set) Rz If zero, it is divisible, return (carry clear) Lchk: sub b Trial subtraction, subtract 10 Ldone: mov a,d See if total is divisible by 10 Ldiv: inr c Find two digits using trial subtraction Mvi c,9 10-1, compensate for extra subtraction loop Mov d,b D = S1+S2 (we don't need to keep them separate) The last digit of a credit card number is the check digit, which protects against transcription errors such as an error in a. Returns with carry clear if the string passes, carry set Ĝheck if the 0-terminated string at HL passes the Luhn test. OI CL16+15,X'F0' zoned to char (zap sign) MVC 0(1,R4),0(R5) mid(w,iw,1)=mid(s,is,1) The Luhn algorithm, a simple checksum verification algorithm, is also known as Luhn formula, modulus 10 algorithm, or mod 10 algorithm. Use it to validate the following numbers: Write a function/method/procedure/subroutine that will validate a number with the Luhn test, and S1 + s2 = 70 which ends in zero which means that 49927398716 passes the Luhn test
0 Comments
Leave a Reply. |