How to Generate Credit Card Numbers on a Calculator

by DETHMaster

Being bored one day, I went home and wrote a program for my calculator that would have the user enter a six-digit prefix and then generate a valid credit card number.

This is not to be used for committing credit card fraud, but should be used for learning how a simple algorithm works and how to program a TI-82.  This will probably require a little bit of TI-82 programming experience.  This has been tested and shown to work.

:0->Z
:ClrHome
:{2,16}_>dim [A]
:Output(1,1,"THIS WILL MAKE A 16 DIGIT CC NUMBER.")
:Pause
:1->P
:iPart 10rand->[A](1,7)
:iPart 10rand->[A](1,8)
:iPart 10rand->[A](1,9)
:iPart 10rand->[A](1,10)
:iPart 10rand->[A](1,11)
:iPart 10rand->[A](1,12)
:iPart 10rand->[A](1,13)
:iPart 10rand->[A](1,14)
:iPart 10rand->[A](1,15)
:iPart 10rand->[A](1,16)
:Lbl 1
:ClrHome
:For(I,1,6)
:Disp "ENTER DIGIT ",P, "IN THE PREFIX:"
:INPUT A
:A->[A](1,P)
:P+1->P
:ClrHome
:End
:If [A](1,1)=0
:Then
:1->P
:ClrHome
:Output(1,1,"Invalid Prefix")
:Pause
:ClrHome
:Goto 1
:End
:Lbl 2
:[A](1,1)*2->[A](2,1)
:[A](1,2)->[A](2,2)
:[A](1,1)*2->[A](2,3)
:[A](1,2)->[A](2,4)
:[A](1,1)*2->[A](2,5)
:[A](1,2)->[A](2,6)
:[A](1,1)*2->[A](2,7)
:[A](1,2)->[A](2,8)
:[A](1,1)*2->[A](2,9)
:[A](1,2)->[A](2,10)
:[A](1,1)*2->[A](2,11)
:[A](1,2)->[A](2,12)
:[A](1,1)*2->[A](2,13)
:[A](1,2)->[A](2,14)
:[A](1,1)*2->[A](2,15)
:[A](1,2)->[A](2,16)
:For(P,1,16)
:If [A](2,P)>9
:Then
:[A](2,P)-9->[A](2,P)
:End
:End
:0->S
:For(P,1,16)
:[A](2,P)+S->S
:End
:If (S/10)=iPart (S/10)
:Then
:Goto 3
:Else
:[A](1,16)+1->[A](1,16)
:If [A](1,16)>9
:Then
:0->[A](1,16)
:[A](1,15)+1->[A](1,15)
:End
:If [A](1,15)>9
:Then
:0->[A](1,15)
:[A](1,14)+1->[A](1,14)
:End
:If [A](1,14)>9
:Then
:0->[A](1,14)
:End
:Z+1->Z
:Output(8,1,"ATTEMPTS: ")
:Output(8,11,Z)
:Goto 2
:End
:Lbl 3
:1->R
:ClrHome
:Output(1,1,"The CARD IS:")
:For(D,1,16)
:Output(3,D,[A](1,D))
:End
:Pause
:ClrHome
:Output(1,1,"THANK YOU FOR USING CC-GEN-82")
:Pause
:ClrHome

Code: CC-GEN-8.bas




In Volume 14, Number 1 DETHMaster submitted an 
excellent TI-82 progie to generate credit card numbers.
However, I found that the program had a rather glaring
bug: It was unable to generate Discover credit card num-
bers. Discover uses the prefix 6011, which caused the
program to fall into an endless loop. This modification
should solve that error: Immeditate preceding the line
0->S, insert:

:If [A](1,2)=0
:Then
:1->F
:Else
:0->F

And the line that reads:

:[A](2,P)+S->S

Should be changed to:

:[A](2,P)+S+F->S

I hope this solves any problems!

                             - Crumpet
                               2600, v14n3



----------


While reading the article entitled "How to
Generate Credit Card Numbers On a Calculator"
in the Spring issue of 2600 I found a series
of mistakes (most likely typographical) in the
code.

The idea of generating CC numbers no a TI-82 to
learn about the Luhn algorithm is a great idea
and it's a shame that a small mistake might ruin
that chance for the curious reader. The problem is 
where the code assigns numbers to the second
matrix (it starts at the bottom of the first
column). The part where it says:

[A](1,1) * 2 -> [A](2,1)
[A](1,2) -> [A](2,2)
[A](1,1) * 2 -> [A](2,3)
[A](1,2) -> [A](2,4)

etc. should read:

[A](1,1) * 2 -> [A](2,)
[A](1,2) -> [A](2,2)
[A](1,3) * 2 -> [A](2,3)
[A](1,4) -> [A](2,4)

etc. and, of course, the first matrix
should keep incrementing with the second
After this small correction is applied, the
program works perfectly.

                             - Mutter
                               2600, v14n3 


----------


I believe that the correction was in the very next issue, in a letter that I
sent. Basically what I forgot to do was to increment the index of the array
that I was using to store the individual digits of the card number, so I had
something like

a[0] = a[0];
a[1] = (a[1] * 2) - 9;
a[0] = a[0];
a[1] = (a[1] * 2) - 9;
a[0] = a[0];
a[1] = (a[1] * 2) - 9;

instead of

a[0] = a[0];
a[1] = (a[1] * 2) - 9;
a[2] = a[2];
a[3] = (a[3] * 2) - 9;
a[4] = a[4];
a[5] = (a[5] * 2) - 9;

keep in mind, that's not the real code, but it is the same mistake. just
look at the spot that the digits are multiplied by two and the result is
checked to be less than 9;

now I'd probably write a tighter loop

something like

for(int i = 0; i < cards.length(); ++i)
{
     if(i % 2)
     {
          cards[i] = (cards[i] * 2) % 9;
     }
}

--jesse
Return to $2600 Index