The implementation method of Python randomly generating credit card number

Source: Internet
Author: User
Tags generator naming convention

This article illustrates the implementation of Python's randomly generated credit card number. Share to everyone for your reference. The specific analysis is as follows:

This Python code generates the credit card number according to the credit card number generation rule randomly, can pass the verification, only for the study reference, please do not use for the illegal use, otherwise the consequence is conceited.

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112-113 #!/usr/bin/python "" "Gencc:a" "" "" "" Generate "" "" "" "," "" "" "" "" "" "" "" Usefull for testing e-commerce sites during development. Copyright 2003-2012 Graham King this are free software; Can redistribute it and/or modify it under the terms of the GNU general public License as published by the free Softwa Re Foundation; Either version 2 of the License, or (at your option) any later version. This are distributed in the hope that it'll be useful and but without any WARRANTY; Without even the implied warranty of merchantability or FITNESS for A particular purpose. The GNU general public License is for more details. You are should have received a copy of the GNU general public License along and this program; If not, write to the free Software Foundation, Inc., Temple Place, Suite, Boston, MA 02111-1307 USA "" # Different naming convention, because translated from PHP # pylint:disable=c0103 from random import random ImporT copy visaprefixlist = [[' 4 ', ' 5 ', ' 3 ', ' 9 '], [' 4 ', ' 5 ', ' 5 ', ' 6 '], [' 4 ', ' 9 ', ' 1 ', ' 6 '], [' 4 ', ' 5 ', ' 3 ', ' 2 '], [' 4 ', ' 9 '] ', ' 2 ', ' 9 '], [' 4 ', ' 0 ', ' 2 ', ' 4 ', ' 0 ', ' 0 ', ' 7 ', ' 1 ', [' 4 ', ' 4 ', ' 8 ', ' 6 '], [' 4 ', ' 7 ', ' 1 ', ' 6 '], [' 4 ']] Mastercardprefi Xlist = [[' 5 ', ' 1 '], [' 5 ', ' 2 '], [' 5 ', ' 3 '], [' 5 ', ' 4 '], [' 5 ', ' 5 ']]] amexprefixlist = [[' 3 ', ' 4 '], [' 3 ', ' 7 ']] Discoverpr Efixlist = [[' 6 ', ' 0 ', ' 1 ', ' 1 ']] dinersprefixlist = [[' 3 ', ' 0 ', ' 0 '], [' 3 ', ' 0 ', ' 1 '], [' 3 ', ' 0 ', ' 2 '], [' 3 ', ' 0 ', ' 3 '], [' 3 ', ' 6 '], [' 3 ', ' 8 ']] enrouteprefixlist = [[' 2 ', ' 0 ', ' 1 ', ' 4 '], [' 2 ', ' 1 ', ' 4 ', ' 9 ']] jcbprefixlist = [[' 3 ', ' 5 ']] Voy Agerprefixlist = [[' 8 ', ' 6 ', ' 9 ', ' 9 ']] def completed_number (prefix, length): "" "' prefix ' is the start of the CC number a s a string, any number of digits. ' Length ' is the length of the CC number to generate. Typically "" "Ccnumber = prefix # generate digits while Len (Ccnumber) < (length-1): digit = str (generator.ch Oice (range (0)) ccnumber.append (digit) # Calculate sumsum = 0 pos = 0 reversedccnumber = [] Reversedccnumber.extend (Ccnumber) Reversedccnumber.reverse () while Pos < length- 1:odd = Int (Reversedccnumber[pos]) * 2 if odd > 9:odd = 9 sum + = Odd if pos!= (length-2): Sum + = Int (REVERSEDCCN Umber[pos + 1]) pos = 2 # Calculate check digit Checkdigit = ((SUM/10 + 1) * 10-sum)% ccnumber.append (str (checkdi git) return ". Join (Ccnumber) def credit_card_number (Rnd, prefixlist, Length, howmany): result = [] while Len (result) ; Howmany:ccnumber = Copy.copy (Rnd.choice (prefixlist)) Result.append (Completed_number (ccnumber, length)) return result   def output (title, numbers): result = [] Result.append (title) result.append ('-' * len (title)) Result.append (' n '. Joi N (Numbers)) Result.append (') return ' n '. Join (Result) # # Main # generator = Random () generator.seed () # Seed from Time Print ("Darkcoding credit card Generatorn") MasterCard = Credit_card_number (Generator, Mastercardprefixlist, 16, 10) Print (Output ("Mastercard",MasterCard) Visa16 = Credit_card_number (generator, visaprefixlist, all) print (output ("VISA digit", visa16)) Visa13 = Credit_card_number (Generator, visaprefixlist, 5) Print (Output ("VISA digit", visa13)) Amex = Credit_card_number (g Enerator, Amexprefixlist, 5) Print (Output ("American Express", Amex)) # Minor Cards discover = Credit_card_number (gener Ator, Discoverprefixlist, 3) print (Output ("Discover", Discover)) diners = Credit_card_number (Generator, Dinersprefixlist, 3) print (Output ("Diners Club/carte Blanche", diners)) EnRoute = Credit_card_number (generator, Enro Uteprefixlist, 3) print (Output ("EnRoute", enRoute)) JCB = Credit_card_number (generator, jcbprefixlist, 3) print (O Utput ("JCB", JCB) Voyager = Credit_card_number (Generator, voyagerprefixlist, 3) print (Output ("Voyager", Voyager))

The results of the operation are as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 The

I hope this article will help you with your Python programming.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.