Exemplo n.º 1
0
	if (event.type==pygame.KEYDOWN):
		strtext=""
		if (event.key==pygame.K_BACKSPACE):
			if listtxt != []:
				listtxt.pop()
				for character in listtxt: strtext += character
		else:
			listtxt.append(chr(event.key))  #build up the strtext with each key press
			for character in listtxt: strtext += character
		screen.fill(background)
		for value in listtxt:
			if value in numbers: valid = True
			else:
				valid = False; break
		if valid:
			if luhn.ccn_valid(strtext) and len(strtext)>0 and len(strtext)==16:
				ccndiags = "CCN: VALID!"
				ccncolor = [0,255,0]
			else:
				ccndiags = "CCN: INVALID!"
				ccncolor = [255,0,0]
			if luhn.sin_valid(strtext) and len(strtext)==9:
				sindiags = "SIN: VALID!"
				sincolor = [0,255,0]
			else:
				sindiags = "SIN: INVALID!"
				sincolor = [255,0,0]
			if len(strtext) == 15: ccn_csum = "Valid check digit for this as a CCN: " + str(luhn.calc_ccn(int(strtext)))
			else: ccn_csum = " "
			if len(strtext) == 8: sin_csum = "Valid check digit for this as a SIN: " + str(luhn.calc_sin(strtext))
			else: sin_csum = " "
Exemplo n.º 2
0
		except TypeError: print "What?"
		except NameError: print "What?"
		except SyntaxError: print "What?"

	if choice == 1:
		print "Random credit card number:",luhn.rand_ccn()
		print "Random Canadian Social Insurance Number:",luhn.rand_sin()

	elif choice == 2:
		validDigits=['0','1','2','3','4','5','6','7','8','9']
		while True:
			try:
				digits = raw_input("Please input a 9 or 16 digit long string of numbers to check for validity: ")
				if len(digits) != 9 and len(digits) != 16: raise UserWarning
				for digit in digits:
					if digit not in validDigits:
						raise ValueError
				break
			except UserWarning:
				print "\'Please input a 9 or 16 digit long string.\'\n\'...input a 9 or 16 digit long string.\'\n\'...9 or 16 digit long string.\'\n\'...9 or 16 digit...\'\nHoo boy, I wonder where you went wrong!"
			except ValueError:
				print "I said OF NUMBERS."
		del validDigits
		sin_num = digits
		ccn_num = digits
		if luhn.ccn_valid(ccn_num): print digits,"is a valid credit card number."
		else: print digits,"is not a valid credit card number."
		if luhn.sin_valid(sin_num): print digits,"is a valid Canadian Social Insurance Number."
		else: print digits,"is not a valid Canadian Social Insurance Number."

	elif choice == 3: break