aditya109 / git-osp-for-beginners

A GitHub Repository to encourage and involve beginners in Open Source Contributions
GNU General Public License v3.0
106 stars 250 forks source link

Implementation of Luhn's Algorithm in any language #178

Closed hryxna closed 4 years ago

hryxna commented 4 years ago

So What's Luhn's Algorithm πŸ€”

Basically it checks whether a credit card is a valid one or not.

Luhn's Algorithm

This is an algorithm that checks whether the given credit card is valid or not as well as displays it belongs to which company. That is whether it belongs to MASTERCARD, VISA, AMERICAN EXPRESS. One can check the implementation in JAVA from here : Luhn's Algorithm

NOTE:

Input should only be digits no alphabets or any special characters or whitespaces should be allowed.

For the mentioned cards it will check their first digits as well as the total no. of digits that are mentioned below :

- MASTERCARD
  * First Digits  = 51, 52, 53, 54, 55. 
  * No. of digits = 16

- AMERICAN EXPRESS          
  * First Digits  = 34 or 37.
  * No. of digits = 15

- VISA                               
  * First Digits  = 4.
  * No. of digits = 13 or 16

For the main part find whether checksum % 10 is "0" or not?

- In order to calculate checksum we have to do two things :

  1A. Multiply the even no. of digits starting from the rear-end till front-end.
    * E.g: 123456 = 5*2 + 3*2 + 1*2 = 10 + 6 + 2.
    * Also if any product is 2-digit no. then we have to split them add them.
    * i.e : 5 * 2  = 10  which would be written as 1 + 0 + 6 + 2 = 9.

  1B. Add the digits that are not multiplied by 2 starting from rear-end till front-end.
    * E.g: 6 + 4 + 2 = 12.

  2. Lastly add both sum of even and odd no. of digits which we calculated earlier.
    * E.g checksum = odd + even = 9 + 12 = 21.

Very Last step is to check whether the checksum divided by 10 would give us remainder "0" or not?

If so then the credit no. is valid and needs to verify its the length and if it's also valid then woo-hoo :tada: you have a valid credit card.

Else if it doesn't which means you have an invalid card :stuck_out_tongue:.

In our example 21 % 10 = 1. which means our credit card is not valid.

KRHero03 commented 4 years ago

Hi, this seems interesting. Can I work on this?

hryxna commented 4 years ago

Hi, this seems interesting. Can I work on this?

Sure why not go ahead @KRHero03 πŸ˜„.

cyenney commented 4 years ago

Can I work on this in C#?

Ajordat commented 4 years ago

I can try to work on this in Python.

momosetti commented 4 years ago

I would make it using JavaScript, its possible.?

hryxna commented 4 years ago

Yes sure @cyenney @Ajordat @momosetti go ahead implement. A suggestion for you guys do add the comments/explanations about the program. you guys can also check my code in java for reference πŸ˜„ Luhn's Algorithm

Also, I would also assign this to you guys as per the language you would be implementing.

deep1112002 commented 4 years ago

Can i work on this in C++??

hryxna commented 4 years ago

Sure @deep1112002, go ahead πŸ˜„.

Ajordat commented 4 years ago

Sure thing. I added the PR #181 as it adds the code for Python.

deep1112002 commented 4 years ago

I added the pull request #185 for Luhn's algorithm in C++

momosetti commented 4 years ago

@aditya109 @hryxna go check PR #182 - thank's in advance.

hryxna commented 4 years ago

@Ajordat @momosetti @deep1112002 I have reviewed the code from my perspective and commented for necessary changes if required kindly check it πŸ˜„.

kanishq1 commented 4 years ago

Hey @aditya109 can I make it using javascript?

hryxna commented 4 years ago

@kanishq1 go ahead πŸ˜„.

maverickLez-zz commented 4 years ago

Hi, this seems interesting. Can I work on this?

hryxna commented 4 years ago

Yeah sure @maverickLez, go ahead 😁.

hryxna commented 4 years ago

Hey everyone I was having a doubt regarding my explanation that I have given on the issue Should I directly add the one which I have made in README.md or keep this one as it is?

maverickLez-zz commented 4 years ago

@hryxna will this PR be counted towards hacktoberfest 2020, as it is not labelled as "hacktoberfest-accepted"?

hryxna commented 4 years ago

@maverickLez it will be counted until and unless we have labelled it after reviewing it thoroughly. So first implement it make a PR and then sit back and let us review it πŸ˜„.

aditya109 commented 4 years ago

Hey everyone I was having a doubt regarding my explanation that I have given on the issue Should I directly add the one which I have made in README.md or keep this one as it is?

Make a change in README.md or add clarification in the issue description itself.

aditya109 commented 4 years ago

Hey @hryxna ! I see you are really interested in open source grooming. I really that. Would you like to become a collaborator in this repo. That way I could add you as a reviewer and you could provide your insights as a moderator. If you are, accept the invite I have sent to you.

hryxna commented 4 years ago

Sure @aditya109 why not I would be happy to become a collaborator πŸ˜„. It would help me too as well As I'm new to GitHub and git Thanks for inviting me πŸ˜„.

hryxna commented 4 years ago

Hey everyone I was having a doubt regarding my explanation that I have given on the issue Should I directly add the one which I have made in README.md or keep this one as it is?

Make a change in README.md or add clarification in the issue description itself.

I think I would change this one with the one I wrote it. it would be much easier to understand.

If anyone doesn't understand then feel free to comment mentioning me along with the doubts πŸ˜„.

aditya109 commented 4 years ago

Sure @aditya109 why not I would be happy to become a collaborator πŸ˜„. It would help me too as well As I'm new to GitHub and git Thanks for inviting me πŸ˜„.

Pleasure is all mine.