home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / asm / CardCheck.lha / CardChecker.s < prev   
Encoding:
Text File  |  1996-12-27  |  5.2 KB  |  265 lines

  1.  
  2.         Opt    o+,ow-,c-,d+
  3.  
  4.         Incdir    Inx:
  5.         INCLUDE    macros.i
  6.         INCLUDE    LVO.Gs
  7.         Include    Reqtools.i
  8.  
  9. ProgStart    Move.l    4.w,a6
  10.         Lea    Variables(PC),a5
  11.  
  12.         Lea    ReqToolsName(pc),a1
  13.         Call    Openlibrary
  14.         Move.l    d0,ReqToolsBase(a5)
  15.         beq.b    NoReqtools
  16.  
  17.         Move.l    ReqToolsBase(a5),a6
  18.         Moveq.l    #RT_ReqInfo,d0
  19.         Sub.w    a0,a0
  20.         Call    RTAllocRequestA
  21.         Move.l    d0,ReqInfo(a5)
  22.  
  23.  
  24.         Bsr    GetCardNumber
  25.         Bsr    ConvertCard
  26.         Tst.b    InvalidCard(a5)
  27.         Bne.b    .CardInvalid
  28.  
  29.         Bsr    CheckSumCard
  30.         Tst.b    InvalidCard(a5)
  31.         Bne.b    .CardInvalid
  32.  
  33.         Lea    Issuer(a5),a4
  34.  
  35.         Lea    IssuerStruct(PC),a0
  36.         Move.l    CardNumber(a5),d0
  37.  
  38. .Loop        Move.l    (a0),d1        ; Get struct card #
  39.         Beq.b    .FoundMatch
  40.         Cmp.l    d0,d1
  41.         Beq.b    .FoundMatch
  42.         Addq.l    #6,a0
  43.         Bra.b    .Loop
  44.  
  45. .FoundMatch    Lea    IssuerStruct(PC),a1
  46.         Add.w    4(a0),a1
  47.         Move.l    a1,(a4)
  48.         Lea    CardValidTxt(PC),a1
  49.         Bsr    DoEzReqArgs
  50.  
  51.  
  52. .CardInvalid    Move.l    ReqToolsBase(a5),a6
  53.         Move.l    ReqInfo(a5),a1
  54.         Call    RTFreerequest
  55.  
  56.         Move.l    a6,a1            ; RT base
  57.         Move.l    4.w,a6
  58.         Call    Closelibrary
  59.         Moveq.l    #0,d0
  60. NoReqtools    Rts
  61.  
  62.  
  63. ;------------------------------------------------------------------
  64. GetCardNumber    Move.l    ReqToolsBase(a5),a6
  65.         Lea    TagList(PC),a0
  66.         Lea    InputBuffer(a5),a1
  67.         Lea    Title(pc),a2
  68.         Move.l    ReqInfo(a5),a3
  69.         Moveq.l    #19,d0            ; Max chars
  70.         Jump    RTGetStringa
  71.  
  72. ;------------------------------------------------------------------
  73. ConvertCard    Lea    InputBuffer(a5),a0
  74.         Lea    CardNumber(a5),a1
  75.  
  76. .Loop        Move.b    (a0)+,d0    ; get char
  77.         Beq.b    .FoundEnd
  78.  
  79.         Cmp.b    #"-",d0
  80.         Beq.b    .Loop
  81.         Cmp.b    #" ",d0
  82.         Beq.b    .Loop
  83.  
  84.         Cmp.b    #"0",d0
  85.         Blt.b    .InvalidChar
  86.         Cmp.b    #"9",d0
  87.         Bgt.b    .InvalidChar
  88.  
  89.         Sub.b    #'0',d0
  90.         Move.b    d0,(a1)+
  91.         Addq.b    #1,NumOfChars(a5)
  92.  
  93.         Cmp.b    #16,NumOfChars(a5)
  94.         Bgt.b    .WrongNumOfDigits
  95.         Bra.b    .Loop
  96.  
  97. .FoundEnd    
  98.         Cmp.b    #16,NumOfChars(a5)
  99.         Beq.b    .OkayNumOfChars
  100.  
  101.         Cmp.b    #13,NumOfChars(a5)
  102.         Bne.b    .WrongNumOfDigits
  103.  
  104. .OkayNumOfChars    St.b    (a1)+
  105.         Rts
  106.  
  107.  
  108.  
  109. .InvalidChar    Lea    InvalidCharTxt(PC),a1
  110.         St.b    InvalidCard(a5)
  111.         Bra.b    DoEZReq
  112.  
  113. .WrongNumOfDigits
  114.         Lea    WrongNumCharsTxt(PC),a1
  115.         St.b    InvalidCard(a5)
  116.  
  117. ;------------------------------------------------------------------
  118. DoEZReq        Sub.l    a4,a4
  119. DoEZReqArgs    Move.l    ReqToolsBase(a5),a6
  120.         Lea    EZTagList(PC),a0
  121.         Lea    OkayGadgetTxt(pc),a2
  122.         Move.l    ReqInfo(a5),a3
  123.         Jump    RTEZRequestA
  124.  
  125.  
  126. ;------------------------------------------------------------------
  127. ;Credit cards use the Luhn Check Digit Algorithm.  The main purpose of
  128. ;this algorithm is to catch data entry errors, but it does double duty
  129. ;here as a weak security tool.
  130. ;
  131. ;For a card with an even number of digits, double every odd digit and
  132. ;subtract 9 if the product is greater than 10.  Add up all the even
  133. ;digits as well as the doubled-odd digits, and the result must be a
  134. ;multiple of 10 or it's not a valid card.  If the card has an odd
  135. ;number of digits, perform the same addition doubling the even digits
  136. ;instead.
  137.  
  138. CheckSumCard    Lea    CardNumber(a5),a0
  139.         Moveq.l    #-1,d0
  140. .Cnt        Addq.l    #1,d0
  141.         Cmp.b    #-1,(a0)+
  142.         Bne.b    .Cnt
  143.  
  144.         Push    d0
  145.  
  146.         Lea    CardNumber(a5),a0
  147.         Btst    #0,d0            ; Even # of digits?
  148.         Beq.b    .Even
  149.         Addq.l    #1,a0            ; Read odd digits.
  150.  
  151. .Even        Lsr.l    #1,d0            ; Div by 2
  152.  
  153.  
  154.         Subq.l    #1,d0            ; Correct for dbra
  155.         Moveq.l    #0,d2
  156. .Check        Move.b    (a0),d1
  157.         Lsl.b    #1,d1
  158.         Cmp.b    #10,d1
  159.         Blt.b    .Ok
  160.         Sub.b    #9,d1
  161.  
  162. .ok        Add.b    d1,d2
  163.         Addq.l    #2,a0
  164.         Dbra    d0,.Check
  165.  
  166.  
  167.         Pop    d0
  168.  
  169.         Lea    CardNumber(a5),a0
  170.         Btst    #0,d0            ; Even # of digits?
  171.         Bne.b    .Odd
  172.         Addq.l    #1,a0            ; Read odd digits.
  173.  
  174. .Odd        Lsr.l    #1,d0            ; Div by 2
  175.  
  176.         Subq.l    #1,d0            ; Correct for dbra
  177.  
  178.         Moveq.l    #0,d1
  179. .Check2        Add.b    (a0),d1
  180.         Addq.l    #2,a0
  181.         Dbra    d0,.Check2
  182.  
  183.         Add.l    d1,d2
  184.  
  185.         Lea    CardInvalidTxt(PC),a1
  186.         St.b    InvalidCard(a5)
  187.  
  188.         And.l    #%1111,d2
  189.         Cmp.l    #%1010,d2
  190.         Bne    DoEZReq
  191.  
  192.         Clr.b    InvalidCard(a5)
  193.         Rts
  194.  
  195. *****************************************************************************
  196. *****                Variables                *****    
  197. *****************************************************************************
  198.  
  199. TagList        Dc.l    RT_WaitPointer,1
  200.         Dc.l    RTGS_TextFmt,Text
  201.         Dc.l    Tag_End,0
  202.  
  203. EZTagList    Dc.l    RT_WaitPointer,1
  204.         Dc.l    RT_ReqPos,ReqPos_Pointer
  205.         Dc.l    RT_UnderScore,"_"
  206.         Dc.l    RTEZ_Flags,EZReqF_CenterText
  207.         Dc.l    Tag_End,0
  208.  
  209.  
  210.  
  211. IssuerStruct    Dc.l    $04050309
  212.         Dc.w    BarclaysTxt-IssuerStruct
  213.         Dc.l    $04090201
  214.         Dc.w    LloydsTxt-IssuerStruct
  215.         Dc.l    $04090106
  216.         Dc.w    MidlandVisaTxt-IssuerStruct
  217.         Dc.l    $05040304
  218.         Dc.w    MidlandBVisaTxt-IssuerStruct
  219.         Dc.l    $04050007
  220.         Dc.w    BofScotBVisaTxt-IssuerStruct
  221.         Dc.l    0
  222.         Dc.w    UnknownIssueTxt-IssuerStruct
  223.  
  224. BarclaysTxt    dc.b    "Barclays VISA",0
  225. LloydsTxt    dc.b    "Lloyds VISA",0
  226. MidlandVisaTxt    dc.b    "Midland VISA",0
  227. MidlandBVisaTxt    dc.b    "Midland Business VISA",0
  228. BofScotBVisaTxt    dc.b    "Bank Of Scotland Business VISA",0
  229. UnknownIssueTxt    dc.b    "Unknown",0
  230.  
  231.         Dc.b    "$VER: CardChecker v1.1",0
  232.  
  233. Text        Dc.b    "Please enter Credit Card number.",0
  234.  
  235. InvalidCharTxt    Dc.b    "You entered an invalid character!",10
  236.         Dc.b    "Card not processed.",0
  237.  
  238. WrongNumCharsTxt
  239.         Dc.b    "Card should be 13 or 16 digits.",10
  240.         Dc.b    "Card not processed.",0
  241.  
  242. CardInValidTxt    Dc.b    "Card checksum invalid.",10
  243.         Dc.b    "Reject Card",0
  244.  
  245. CardValidTxt    Dc.b    "Card is Valid",10
  246.         Dc.b    "Issuer & Type: %s",0
  247.  
  248. OkayGadgetTxt    Dc.b    "_Okay",0
  249.  
  250. Reqtoolsname    dc.b    "reqtools.library",0
  251.  
  252. title        dc.b    "Longword requestor",0
  253.  
  254. Variables    RsReset
  255. reqtoolsbase    Rs.l    1
  256. ReqInfo        Rs.l    1
  257. ;CheckSum    Rs.l    1
  258. Issuer        Rs.l    1
  259. InputBuffer    Rs.b    20
  260. CardNumber    Rs.b    20+1
  261. NumOfChars    Rs.b    1
  262. InvalidCard    Rs.b    1
  263. VarsSize    Rs.b    0
  264.         Ds.b    VarsSize
  265.