Does the Luhn algorithm work for all mainstream credit cards? (Discover, Visa, Mastercard, Amex) - e-commerce

Reference: Luhn Algorithm
The Luhn Algorithm is a great way to quickly verify that the user typed their CC # in correctly.
However, I am concerned that there may be a subset of mainstream credit cards that do not use Luhn-Algorithm-friendly numbers.
I do have logging in place in our application to detect a pattern in all Luhn-Algorithm-rejections, but I'd rather know definitively.

Almost.
China UnionPay and one kind of Diners Club card (enRoute) do not use Luhn validation. (LazyOne’s answer is wrong about Diners Club.)
Nearly everyone else does.
Citing Wikipedia's 'Bank card' page:
Don't validate at all:
Diners Club enRoute
China UnionPay
Validate with Luhn 2:
American Express
Bankcard
Diners Club Carte Blanche
Diners Club International
Diners Club United States & Canada
Discover Card
InstaPayment
JCB
Laser
Maestro
Dankort
MasterCard
Solo
Switch
Visa
Visa Electron

Yes -- it works for all mainstream card types.
I have a custom PHP class to handle card data that was compiled from various "validate card number" and alike functions from few programming languages + information from Wikipedia & some Payment Processing systems. It successfully validates test card numbers (every payment system has few of such numbers) for these card types:
VISA debit / credit
VISA Electron
VISA Delta
MasterCard
AMEX
Maestro
Switch
Solo
Diners Club
Discover
JCB

The LUN check works on most credit cards. It is a modulus 10 check digit system to guarantee that the card number has been accurately read/recorded (mag stripe, virtual terminal or manual entry in the old days of the manual card imprinter).
Back in the days of manual data entry, these check systems were used to make sure that keys like UPS's pickup book numbering system were accurately entered (modulus 7 check digit).
It is even used in barcoding systems like code 128 which needs a modulus 103 digit added to the encoded data string to verify that the code was read right.

Related

Python Regex: Match a sentence starting with title and contains "ask'

I just want to extract all instances of a sentence
starts with a title (ie. Mr, Miss, Ms or Dr)
contains the word "asked"
end with .
I tried the below regex but got back an empty list. Thank you
import re
text_list="26 Mr Kwek Hian Chuan Henry asked the Minister for the Environment and Water Resources whether Singapore will stay the course on fighting climate change and meet our climate change commitments despite the current upheavals in the energy market and the potential long-term economic impact arising from the COVID-19 situation. We agree with the Panel and will instead strengthen regulations to safeguard the safety of path users. With regard to Ms Rahayu Mahzam's suggestion of tapping on the Small Claims Tribunal for personal injury claims up to $20,000, we understand that the Tribunal does not hear personal injury claims.  Mr Gan Thiam Poh, Ms Rahayu Mahzam and Mr Melvin Yong have asked about online retailers of PMDs. Mr Melvin Yong asked about the qualifications and training of OEOs."
asked_regex=re.compile(r'^(Mr|Miss|Ms|Dr)(.|\n){1,}(asked)(.|\n){1,}\.$')
asked=re.findall(asked_regex, text_list)
Desired Output:
["Mr Kwek Hian Chuan Henry asked the Minister for the Environment and Water Resources whether Singapore will stay the course on fighting climate change and meet our climate change commitments despite the current upheavals in the energy market and the potential long-term economic impact arising from the COVID-19 situation. ",
"Mr Gan Thiam Poh, Ms Rahayu Mahzam and Mr Melvin Yong have asked about online retailers of PMDs.",
"Mr Melvin Yong asked about the qualifications and training of OEOs."]
try this regex pattern:
import re
text_list="26 Mr Kwek Hian Chuan Henry asked the Minister for the Environment and Water Resources whether Singapore will stay the course on fighting climate change and meet our climate change commitments despite the current upheavals in the energy market and the potential long-term economic impact arising from the COVID-19 situation. We agree with the Panel and will instead strengthen regulations to safeguard the safety of path users. With regard to Ms Rahayu Mahzam's suggestion of tapping on the Small Claims Tribunal for personal injury claims up to $20,000, we understand that the Tribunal does not hear personal injury claims. Mr Gan Thiam Poh, Ms Rahayu Mahzam and Mr Melvin Yong have asked about online retailers of PMDs. Mr Melvin Yong asked about the qualifications and training of OEOs."
asked_regex=re.compile(r'(Mr|Miss|Ms|Dr)[^\.]*asked[^\.]*\.')
asked=re.findall(asked_regex, text_list)
(Mr|Miss|Ms|Dr)
this will search for all sentences that start with Mr,Miss,Ms,Dr (your pattern would only look for those that were at start of the string.)
[^\.]*asked[^\.]*
this part accepts any string that has word asked in it and before and after of asked is not a full stop or ..
\.
checks that sentence ends with full stop or .
I'm sure regex is right but I don't know why it doesn't work with findall.
here is the code that regex101.com generated based on the pattern and it works.
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(Mr|Miss|Ms|Dr)[^\.]*asked[^\.]*\."
test_str = "26 Mr Kwek Hian Chuan Henry asked the Minister for the Environment and Water Resources whether Singapore will stay the course on fighting climate change and meet our climate change commitments despite the current upheavals in the energy market and the potential long-term economic impact arising from the COVID-19 situation. We agree with the Panel and will instead strengthen regulations to safeguard the safety of path users. With regard to Ms Rahayu Mahzam's suggestion of tapping on the Small Claims Tribunal for personal injury claims up to $20,000, we understand that the Tribunal does not hear personal injury claims. Mr Gan Thiam Poh, Ms Rahayu Mahzam and Mr Melvin Yong have asked about online retailers of PMDs. Mr Melvin Yong asked about the qualifications and training of OEOs."
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.```

Is Spacy's Tok2Vec components required for POS tagging?

I am using Spacy to do POS tagging and lemmatization. I believe the best practice is to disable unneeded components to maximize performance. Having disabled several components however it now seems that every token POS is noun!
It seems the tok2vec component is required for POS tagging. Is that correct, and if so, is this explained anywhere?
Additionally, is there a better way to optimize Spacy pipelines besides removing components?
import spacy
txt = '''ex-4.1 2 d879007dex41.htm ex-4.1 ex-4.1 exhibit 4.1 amendment no. 6 to note amendment no. 6 to note (this " amendment "), dated and effective as of january 30, 2020, is made by and between the u.s. small business administration (" sba "), an agency of the united states, and its successors and assigns, and freshstart venture capital corporation (the " licensee "), a small business investment borrower, licensed under the small business investment act of 1958, as amended, whose principal office is located at 437 madison avenue, new york, ny 10022. recitals whereas , the licensee issued that certain note, effective as of march 1, 2017 in the principal amount of $34,024,755.58 (thirty-four million twenty-four thousand seven hundred fifty-five and 58/100 dollars) in favor of sba (the " existing note "). whereas , sba and the licensee have agreed, subject to the terms and conditions of this amendment, that the existing note be amended to reflect certain agreed upon revisions to the terms of the existing note. now therefore, sba and the licensee hereby agree, in consideration of the mutual premises and mutual obligations set forth herein, that the existing note is hereby amended as follows: section 1. defined terms . except as otherwise indicated herein, all words and terms defined in the existing note shall have the same meanings when used herein. section 2. amendments . a. in the last sentence of the second paragraph of the existing note the phrase, "february 1, 2020" is hereby deleted in its entirety and replaced with the following: "april 1, 2020" b. in the third paragraph of the existing note the phrase, "february 1, 2020" is hereby deleted in its entirety and replaced with the following: "april 1, 2020" section 3. representations and warranties . each party hereby represents and warrants to the other party that it is in compliance with all the terms and provisions set forth in the existing note on its part to be observed or performed and hereby confirms and reaffirms each of its representations and warranties contained in the existing note. section 4. limited effect . except as expressly amended and modified by this amendment, the existing note shall continue to be, and shall remain, in full force and effect in accordance with its terms (and as duly amended). 1 section 5. counterparts . this amendment may be executed by each of the parties hereto on any number of separate counterparts, each of which shall be an original and all of which taken together shall constitute one and the same instrument. delivery of an executed signature page of this amendment in portable document format (pdf) or by facsimile transmission shall be effective as delivery of an executed original counterpart of this amendment. section 6. governing law . pursuant to section 101.106(b) of part 13 of the code of federal regulations, this amendment is to be construed and enforced in accordance with the act, the regulations and other federal law, and in the absence of applicable federal law, then by applicable new york law to the extent it does not conflict with the act, the regulations or other federal law. [signatures appear on next page] 2 in witness whereof, the parties have caused this amendment to be executed by their respective officers thereunto duly authorized, as of the date first above written. freshstart venture capital corporation by: /s/ thomas j. munson name: thomas j. munson title: svp u.s. small business administration by: /s/ thomas g. morris name: thomas g. morris title: director, o/l & acting deputy a/a oii 3'''
nlp = spacy.load('en_core_web_sm')
nlp.disable_pipe("parser")
nlp.disable_pipe("tok2vec") # it seems this is needed in fact?
nlp.disable_pipe("ner")
nlp.enable_pipe("senter")
nlp.max_length = 5000000
doc = nlp(txt)
print(nlp.pipe_names)
for token in doc:
print(token.text, token.pos_, token.lemma_)
NER is not required for POS tagging. Assuming are actually using the above code, the tok2vec is the issue, as that is required for POS tagging.
For advice on making spaCy faster, please see the spaCy speed FAQ. Besides disabling components you aren't using, another thing you can do is use nlp.pipe to batch requests.

VIN Vehicle Identification Number, how to figure out the WMI part?

I am trying to figure out how to breakdown a vehicle vin number.
There is an explanation of how a VIN is build (http://en.wikipedia.org/wiki/Vehicle_Identification_Number#Components_of_the_VIN) but it fails to explain what to do with manufacturers that only have 2 digits assigned instead of 3 digits.
If I understand correct what is written there then every VIN number must be 17 characters long, and the first 3 characters are the WMI (World Manufaturer Identification).
Then there is a list of WMI on the same page, but some manufacturers only have 2 characters in that list, not 3.
How to read such a VIN number ? Will it be only 16 characters long or how do I regognize that a WMI is 2 or 3 characters ?
for example nissan has WMI = JN which is only 2 characters.
2 VIN numbers for Nissan that I know that are valid are :
JN1UC4E26F9001391 and JNKCP0106TT541680
How can I know that for these 2 VIn numbers only the first 2 digits are to be read and used for the WMI ?
In you examples it is in fact 3 characters that Set the WMI information
JN1UC4E26F9001391
NISSAN MOTOR COMPANY, LTD. JN1,1N4 3995 RESEARCH PARK DRIVE ANN ARBOR MI 48104 PASSENGER CAR SEE MEMO 7/29/1986
JNKCP0106TT541680
NISSAN RESEARCH & DEVELOPMENT JN1,JNK 750 17TH STREET, N.W. WASHINGTON DC 20006 PASSENGER CAR ALL 1/13/1992
1st character- Identifies the country in which the vehicle was manufactured.
For example: U.S.A.(1or 4), Canada(2), Mexico(3), Japan(J), Korea(K), England(S), Germany(W), Italy(Z)
2nd character- Identifies the manufacturer. For example; Audi(A),
BMW(B), Buick(4), Cadillac(6), Chevrolet(1), Chrysler(C), Dodge(B),
Ford(F), GM Canada(7), General Motors(G), Honda(H), Jaquar(A), Lincoln(L), Mercedes Benz(D), Mercury(M), Nissan(N), Oldsmobile(3), Pontiac(2or5), Plymouth(P), Saturn(8), Toyota(T), VW(V), Volvo(V).
3rd character- Identifies vehicle type or manufacturing division.
Per VIN descriptor
This link contains the most current WMI information for all, this is were I got my data
WMI for all manufactures
In any Case it is not 3 or 2 for WMI it is
1 for country
2 for manufacturer
3 for type
this gets a little tricky because IF "2" = "N" that is not necessarily Nissan, for example 1N9 = NOMAD CUSTOM CYCLES INC.
Let me know if that helps or if you find a place to get VDS information
Your wiki page seems pretty clear that it's either a 3-character WMI, or a 2-character WMI followed by a 9.
There are an abundance of libraries out there, on GitHub and elsewhere, which are designed to decode VINs. "Do not do a thing already done."

How to get card type information using unimag credit card reader

I want to integrate card swipe feature in my application using unimag card reader device provided by ID Tech. It provides name, account number and expiry date in a single string. But no information about the card type. Is there a way to retrieve the information about the "The type of Card" user hols. Like visa, master, etc.
Card type is determine from first couple of digits
example code here
http://cuinl.tripod.com/Tips/o-1.htm
a quick google for implementations :-)
The cliff notes version:
If card starts with:
3 - Amex (15 digits)
4 - Visa (13-19 digits, usually 16)
5 - Mastercard (16 digits)
6 - Discover (16 digits)
There are some other more rare card types like JCB and Diners which you might need to account for if your solution has to deal with those.

Tracking number patterns

Is there any place to get patterns for shipping tracking numbers for all shipping companies like UPS,FedEX, DHL, AirBorne, USPS ...
Fedex: 12, 14, 15, 20, 22 digits are all valid tracking number
UPS: 1Z + 16 digits or begin with W,T,H + 10 digits
DHL: 10 digits ONLY (if u mention the express shipping, as DHL also have cargo, sea shipment etc)
usps: https://tools.usps.com/go/TrackConfirmAction!input.action
Notice that as far as i know, there is not a complete list there.
If anyone know the new tracking number format, please let me know too.
As I run a startup http://www.aftership.com which also need to detect the tracking number pattern.
Fedex:
XXXXXXXXXXXX (12 numbers)
DHL:
International Air Freight Shipments -
7 digit HAWB number 1234567
International Ocean Shipments - 9
character HBL number SEA123456
U.S. Domestic Shipments* – 3
character origin code and HAWB
number, which can be up to 10 digits
in length. SEA1234567
DHL Tracking Number Information Page
Canadian Postal Service:
Canadian Postal Service Tracking Information Page
UPS:
Begins with 1Z
If it's UPS, Fedex or USPS, you can send the number into Google and get the type from the Google result.
Airborne is now DHL.