Credit Card number generator


SUBMITTED BY: Guest

DATE: Jan. 12, 2014, 7:26 p.m.

FORMAT: Text only

SIZE: 2.3 kB

HITS: 1454

  1. # Coded by Cody8295 #
  2. # http://codyprojects.info #
  3. # Random Credit Card Number Generator #
  4. import random
  5. def two_sum(n): #Returns the difference of the 2 digits of a number above 9
  6. #16... 1+6 = 7....16-9 = 7
  7. return n-9
  8. def is_valid(cc): #performs the Luhn check on a number
  9. if cc==0: return False
  10. total = 0
  11. nums = []
  12. count = 1
  13. for x in str(cc):
  14. if count%2==0:
  15. nums.append(int(x))
  16. else:
  17. nums.append(int(x)*2)
  18. count+=1
  19. for y in nums:
  20. if y>9:
  21. total+=two_sum(y)
  22. else: total+=y
  23. if total%10==0: return True
  24. return False
  25. def generate(n, iin): #generates n number of random working credit card numbers
  26. s = ""
  27. if iin!="visa" and iin!="mastercard" and iin!="amex" and iin!="discover" and iin!="dinersclub": return "Unrecognized issuer"
  28. for x in xrange(0, n):
  29. cc = 0
  30. while not is_valid(cc):
  31. if iin=="visa": cc = random.randrange(4000000000000000, 4999999999999999)
  32. if iin=="mastercard": cc = random.randrange(5100000000000000, 5599999999999999)
  33. if iin=="amex":
  34. if random.randrange(0, 2)==0:
  35. cc = random.randrange(340000000000000, 349999999999999)
  36. else: cc = random.randrange(370000000000000, 379999999999999)
  37. if iin=="discover":
  38. if random.randrange(0, 2)==0:
  39. cc = random.randrange(6011000000000000, 6011999999999999)
  40. else: cc = random.randrange(6500000000000000, 6599999999999999)
  41. if iin=="dinersclub":
  42. cc = random.randrange(5400000000000000, 5599999999999999)
  43. s+=str(cc)+"\n"
  44. return s
  45. def main():
  46. n = raw_input("\nHow many random working credit card numbers would you like to generate? ")
  47. iin = raw_input("\nFor what issuer would you like to generate these cards? (visa, mastercard, amex, discover, dinersclub)")
  48. if not n.isdigit(): n = 10
  49. if iin=="": iin="visa"
  50. ccs = generate(int(n), iin)
  51. print ccs
  52. output = raw_input("Output to log?")
  53. if output == "y" or output == "Y":
  54. f = open("log"+str(random.randrange(11111, 999999999999))+".txt", "w")
  55. f.write(ccs)
  56. else: main()
  57. main()

comments powered by Disqus