Skip to content

Instantly share code, notes, and snippets.

@rab
Forked from ryanbriones/gist:430455
Created June 8, 2010 20:43
Show Gist options
  • Save rab/430629 to your computer and use it in GitHub Desktop.
Save rab/430629 to your computer and use it in GitHub Desktop.
def mask(x)y=x.dup;y[6...-4]=y[6...-4].gsub(/./,'*');y end
[ ['Discover', '6011111111111117', '601111******1117'],
['MasterCard', '5555555555554444', '555555******4444'],
['Visa', '4012888888881881', '401288******1881'],
['American Express', '378282246310005', '378282*****0005' ],
['Diners Club', '30569309025904', '305693****5904' ],
].each do |card, number, masked|
actual = mask(number)
next if actual == masked
puts "%20s %-20s => %-20s (expected %s)"%[card,number,actual,masked]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment