1

Hi so i was making a python script that reads magnetic strips from credit cards and i needed something to allow me to cut from B to ^ so i tried split but its giving me an error. The card output is fake its only for testing. Really need help with the split thing in python really want this to work!

Credit Card output:

%B4146452892178642^SMITH/JOHN ^1505101100001100000000387000000?;E?

Erro:

Credit card detected
Traceback (most recent call last):
  File "Cloner.py", line 102, in <module>
    main()
  File "Cloner.py", line 46, in main
    clone_startUP()
  File "Cloner.py", line 60, in clone_startUP
    clone_type()
  File "Cloner.py", line 67, in clone_type
    CreditCard()
  File "Cloner.py", line 80, in CreditCard
    number = data.split("B", "^")
TypeError: 'str' object cannot be interpreted as an integer

Code:

import pickle
import os
import sys
import time


def main():



os.system('cls' if os.name == 'nt' else 'clear')

if not os.path.exists("Credit Cards") and not os.path.exists("Other Cards"):

    os.makedirs("Credit Cards") 
    os.makedirs("Other Cards")  

    print("Creating needed files")                          
    print("Please Whait")
    print("-----5-----")        
    time.sleep(1)                                                       
    print("-----4-----")        
    time.sleep(1)                                                       
    print("-----3-----")        
    time.sleep(1)                                                       
    print("-----2-----")        
    time.sleep(1)                                                       
    print("-----1-----")        
    time.sleep(1)   

    if os.path.exists("Credit Cards") and os.path.exists("Other Cards"):                                                
        os.system('cls' if os.name == 'nt' else 'clear')    

        print("Files created")  

        clone_startUP()                                                                                                                     
    else:                                                                                       
        os.system('cls' if os.name == 'nt' else 'clear')    

        print("If this erro continues plz create files manually")
        print("------------------------------------------------")
        print("Foulder Names:")
        print("1 - Creadit Cards")
        print("2 - Other Cards")

        sys.exit()                                                                  
else:   
    clone_startUP()

def clone_startUP():

global data

os.system('cls' if os.name == 'nt' else 'clear')

print("Please insert a card:")
data = input()

if data == "":
    clone_startUP()
else:
    clone_type()

def clone_type():

if data[1:2] == "B":
    os.system('cls' if os.name == 'nt' else 'clear')
    print("Credit card detected")
    CreditCard()
else:
    OtherCard()

def CreditCard():

global number
global first_date
global second_date
global first_name
global last_name
global cvv

number = data.split("B", "^")
first_date = data.split("^",2)
second_date = data.split("^",2,5)
first_name = data.split("^","/")
last_name = data.split("/","^")
cvv = data[-14:-10]
credit_info()

def credit_info():

os.system('cls' if os.name == 'nt' else 'clear')

print(first_name)
print(last_name)
print(number)
print(first_date + "/" + second_date)
print(cvv)





main()

1 Answers1

0

The error is caused by the second argument of split which is maxsplit

From the docs:

If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements)

But your are specifying a ^ in for example number = data.split("B", "^")

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
  • So what can i do to prevent this error, because in this case i need ^ because in the case of the number it goes from B to ^ . –  Dec 02 '18 at 11:32
  • @DeadSec One option could be to use a regex. But where should the numbers start and end? Which are the separate parts that you need? Can you give an example? – The fourth bird Dec 02 '18 at 11:44
  • So in the credit card number %B4146452892178642^SMITH/JOHN ^1505101100001100000000387000000?;E? I wanna cut evry thing that is outside B to the first ^ so i can have a string with name number that contains evrything between B and the first ^ –  Dec 02 '18 at 12:01
  • In that string, what is the number, first_name, last_name, first_date, second_date and cvv? Do you mean like this? [Demo](https://regex101.com/r/yoPCwq/1) – The fourth bird Dec 02 '18 at 12:04
  • Yes like that the card number in that case would be the green part –  Dec 02 '18 at 12:12
  • This is an example of how you might get that value using a named capturing group `number` https://ideone.com/qUN1dO – The fourth bird Dec 02 '18 at 12:15
  • I tried to make it my self but i´m still trying to to understand the module. Now how can i remove the date 1505 making the string first_date = 15 and second_date = 05 –  Dec 02 '18 at 12:32
  • @DeadSec What is the cvv number or what is the logic to get that value? Is that 0378? This will match the values except cvv https://ideone.com/WSwYdA – The fourth bird Dec 02 '18 at 12:36
  • The cvv would be 378 –  Dec 02 '18 at 12:42
  • @DeadSec What is the logic to find 378? Is there a fixed length until the `?` Or are there only zeroes preceding or following? – The fourth bird Dec 02 '18 at 12:44
  • I think the logic would be allways 6 zeros between 8 and ? –  Dec 02 '18 at 12:47
  • @DeadSec Then this would give you the numbers you are looking for: https://ideone.com/WSwYdA using this [regex](https://regex101.com/r/Ou7Kte/1) – The fourth bird Dec 02 '18 at 12:55
  • Thanks dude! I will get you profile in the credits part of the script! –  Dec 02 '18 at 12:56
  • @DeadSec You are welcome. It is your script, you don't have to add me to the credits part. – The fourth bird Dec 02 '18 at 13:02
  • Because data in defined by the user its giving me this erro File "Cloner.py", line 84 matches = re.search(regex, f({data}) ^ IndentationError: unindent does not match any outer indentation level –  Dec 02 '18 at 13:04
  • I think that has to do with the indenting of the code. You can check for example [this page](https://stackoverflow.com/questions/492387/indentationerror-unindent-does-not-match-any-outer-indentation-level) or [this page](https://stackoverflow.com/questions/26720841/python-indentationerror-unindent-does-not-match-any-outer-indentation-level/34100174) – The fourth bird Dec 02 '18 at 13:07
  • Working 100% now! Thank you allot and sorry if i bothered you i´m a student and i´m still learning! –  Dec 02 '18 at 13:14
  • @DeadSec No problem, as long as your program has no malicious intent. – The fourth bird Dec 02 '18 at 13:39