当前位置:网站首页 > 更多 > web > 正文

[Python代码] 生成指定前缀信用卡卡号

作者:CC下载站 日期:2019-10-29 15:21:34 浏览:2043 分类:web

[Python代码] 生成指定前缀信用卡卡号

本文转载自 狗仔小分队  马甲简单的封装了一下。

马甲手里有一份在线生成信用卡的代码,支持定制卡号,生成有效期,CCV 等。等整理好分享给大家。

生成指定前缀的信用卡卡号,再也不用在线版啦

撸东西更方便了,开心~


函数代码


from random import Randomimport copydef completed_number(prefix, length):"""'prefix' is the start of the CC number as a string, any number of digits.'length' is the length of the CC number to generate. Typically 13 or 16"""generator = Random()generator.seed()# Seed from current timeccnumber = prefix# generate digitswhile len(ccnumber) < (length - 1):digit = str(generator.choice(range(0, 10)))ccnumber.append(digit)# Calculate sumsum = 0pos = 0reversedCCnumber = []reversedCCnumber.extend(ccnumber)reversedCCnumber.reverse()while pos < length - 1:odd = int(reversedCCnumber[pos]) * 2if odd > 9:odd -= 9sum += oddif pos != (length - 2):sum += int(reversedCCnumber[pos + 1])pos += 2# Calculate check digitcheckdigit = ((sum // 10 + 1) * 10 - sum) % 10ccnumber.append(str(checkdigit))return ''.join(ccnumber)def credit_card_number(prefixList, howMany=1, length=16):generator = Random()generator.seed()# Seed from current timeif type(prefixList)==str:prefixList=[[i for i in prefixList]]if type(prefixList[0])==str:prefixList=[[i for i in List] for List in prefixList]result = []while len(result) < howMany:ccnumber = copy.copy(generator.choice(prefixList))result.append(completed_number(ccnumber, length))return result


调用示例


#生成前缀为'123456',1个,卡号长度16位 fakecard = credit_card_number('123456') #生成前缀为'123456',1个,卡号长度16位 fakecard = credit_card_number('123456',1,16) #生成前缀为'123'或'234'的信用卡卡号,共15个,卡号长度16位 fakecard = credit_card_number(['123','234'], 15,16)


简单封装


wget https://raw.githubusercontent.com/malaohu/ruyo-shell/master/credit_card_number.pypython credit_card_number.py


您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯