Otherwise, you are solely responsible for the consequences. This Python code generates a random credit card number based on the rules generated by the credit card number. it can generate a credit card number and has some reference value, for more information about how to randomly generate a credit card number using Python, see the following example. luhn :: String -> Bool on luhn ( s ) - True if the digit string represents - a valid Luhn credit card number.This article mainly introduces how to generate a credit card number at random in Python. data pass: db ' Pass$ ' fail: db ' Fail$ ' demo: mov si, 80 h Zero-terminate the argument xor bh, bh mov bl, mov, bh inc si inc si call luhn Call the routine mov ah, 9 mov dx, pass If carry is clear, print 'Pass' jnc print mov dx, fail Otherwise, print 'fail' print: int 21 h ret section. ret Run the 'luhn' routine on the argument given on the MS-DOS command line. 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. 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. 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) 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) 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. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |