Sunday, 29 March 2020

You have entered a wrong credit card number : dcode.luhn



   

You have entered a wrong credit card number : dcode.luhn                    




 We  are  surrounded by numbers from everywhere , like our pin , password etc;
These numbers really amazed me when I was buying something from Flipkart &accidentally entered a digit wrong of my card number in payment page .It displayed the message as shown below:








After surfing the internet I  learnt about an interesting algorithm behind our card numbers called Luhn's Algorithm.The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, named after its creator, IBM scientist hans Peter luhn., so we're gonna dcode.luhn.

Logic behind numbers

    
Step 1:
Multiply the digits at odd position by 2.






Step 2: 
If the digits multiplied by 2 becomes two digit no or no. greater than 10 then add them . For eg: 
5×2= 10 >>>1+0 = 1. 
7×2= 14 >>>1+4 = 5. 
9×2= 18 >>> 1+8 = 7.



Step 3:
Now add the new odd places digits & even places digits.
1+4+2+2+5+5+6+4+1+6+5+8+9+0+2+0 = 60


Step 4:
Check S the sum obtained in step 3 is divisible by 10 or not ,if it is then the card is valid otherwise not .


so 60/10 Remainder = 0 [true].


Therefore, the above example we use is a valid card number.

Click this link for validating

a different card numbers inputs


Note: dcode.luhn was designed to protect against accidental errors, not malicious attacks



Pseudocode [dcode.luhn]



function checkLuhn(string purportedCC) {
    int sum := integer(purportedCC[length(purportedCC)-1])
    int nDigits := length(purportedCC)
    int parity := nDigits modulus 2
    for i from 0 to nDigits - 2 {
        int digit := integer(purportedCC[i])
        if i modulus 2 = parity
            digit := digit × 2
        if digit > 9
            digit := digit - 9 
        sum := sum + digit
    }
    return (sum modulus 10) = 0
}

Applications


  • IMEI numbers
  • National Provider Identification number
  • Survey codes appearing on MC Donalds' ,Taco Bell etc.
  • Social Security Numbers .....so on



Strength

•It can detect any single error.


Weakness:

• Even a 16 digit 0 code will be  a valid card number.
Transposition of two digits 09 to 90 [vice-versa] is not detectable.
• It can't detect in twin digits 22 <-->55 
  For eg:
      22......... till 16 digits

           2+(4)=6.       [ 2×2=4]     
     
     55..... till 16 digits
        5×(1+0)= 6      [5×2=10]

One more thing I didn't mentioned other things  in are also considered validation

"Comment your queries ,love below &; don't forget to share it"



Tuesday, 11 February 2020

Why to learn C++ ?





C++ is created by Bjarne Strousoup is one of the  widely used language nowadays .
It is the successor of c language which is a procedural programming language (where we  do a problem step wise) .

Why C++?

•We brought a new concept in our programming language to solve any real life problem easily called OOPS [Object Oriented Programming Language] .
This concept brought power to our  languages .

•It is a generic programming language which means i.e algorithm written for one data type will not be different for different data types.

•It got  rich libraries ,from which we can make new codes.

•It is very fast.

•It's best to use while making system softwares.

APPLICATIONS

•Firefox & chrome have codes written in this language.

•Being closer to hardware mainly used to create system softwares.

•Used as an embedded language in machines.

•Various games like Doom,Counter Strike.

•Database softwares like MySQL
More...
It is written in c++


Job & Salary


Salary information from  gooroo.io
                                

               
•Junior Programmer

•Senior Programmer

•Software Developer

•Quality Analyst

•Game Programmer

•Software Developer Engineer

•C/C++ Analyst

Wednesday, 5 February 2020

Real meaning of programming language


 Programming language


A computer don't understand  human language as it is a machine.
So in order to interact with a machine
we need to learn a language called machine language or binary language[0 or 1]
In simple words On / Off.
But it is difficult for us to understand or write it.

So in order to communicate with computer we developed a language called programming language / high level language.

This is how a programming language looks like


Computer programs are written in various
programming language which is then converted to machine language using
translators like assembler,compiler & interpreter.
Pic credit: geeks for geeks


Have you ever wondered how double clicking an icon on the windows opens the application well it's because all OS are made up of programming languages so there is a statement in program which tells the computer to open the application if someone presses double click on it.
Android is a program


Every application or machine you use it's made from programming language.

From oldest programming language
[ COBOL & Fortran] to the advanced programming language we use today like
C++,java,python ,PHP etc. which can easily solve any real life problem.We are still working on more..
and each programming language has its own syntax .So one must learn it before writing a program.
Top 10 programming languages

But if you're thinking that whenever a new Programming language comes  it has to replace the old one , then you're wrong
Because every language has its own beauty.









Subarray with given sum

Given: Unsorted array  Find: Subarray starting index  to last index on summing up gives the given sum arr[] = {1, 4, 20, 3, 10, 5}, sum = 33...