Developers Archive for the 'Developer algorithms' Category

Credit Card Validation - An Over View

Credit Card Validation - An Over View Wednesday, March 12th, 2008

Nowadays, Online Payment Processing is the main part of Web Programming regardless of the Programming language in which the application is been created.

The Payment Processing can be done by using the Payment GateWays. The Payment GateWays widely used are as following:

1. Paypal.
2. Google Checkout
3. Link Point
4. SecPay
5. E-Bullion.

All these Payment GateWays includes the CreditCard or Debit Card as their main processing unit.

They Validate the CreditCard Numbers and then the Payment Processing is done.

Usually we get the CreditCardNumbers in our application page and forward the details to these Gateways.

However these GateWays have their Own Way of Validating the Credit Card and Details. In Our application we need to Validate them to save in our Database Table for later verification.

The Credit Card Numbers can be of 4 Major Widely Used Types. There are more Types of Credit Cards Available. Listed down are major used Credit Card Types.

1. AMEX
2. VISA
3. MASTERCARD
5. DISCOVER.

Credit Card Numbers are special case of ISO 7812 numbers.

All these CreditCards have the CreditCardNumber and the Number of Digits in them varying from each other.

They are

AMEX - American Express - have 15 Digits.

MasterCard - have 16 Digits

Visa - have 13 or 16 Digits

Discover Card - have 16 Digits.

All the Credit Card are Validated using an Algorithm. Luhn Algorithm.

See the below WikiPedia Link to Know more about Credit Cards

Credit Card numbers - Wikipedia

Change text into binary and vice versa

Change text into binary and vice versa Tuesday, March 13th, 2007

The following two function change text into binary and vice versa.

<?php
function bin2text($bin_str)
{
$text_str = ‘’;
$chars = explode(”\n”, chunk_split(str_replace(”\n”, ‘’, $bin_str), 8) );
$_I = count($chars);
for($i = 0; $i < $_I; $text_str .= chr(bindec($chars[$i])), $i );
return $text_str;
}

function text2bin($txt_str)
{
$len = strlen($txt_str);
$bin = ‘’;
for($i = 0; $i < $len; $i )
{
$bin .= strlen(decbin(ord($txt_str[$i]))) < 8 ? str_pad(decbin(ord($txt_str[$i])), 8, 0, STR_PAD_LEFT) : decbin(ord($txt_str[$i]));
}
return $bin;
}
?>

Merge Sort Algorithm

Merge Sort Algorithm Tuesday, February 20th, 2007

The basic idea behide the merge sort algorithm is recursively split the array into two halves till last and sorth them at the end.
// Include files
#include <iostream> // used for cin, cout
#include <conio.h>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;

// Global Type Declarations

// Function Prototypes
void instruct (void);
void pause ();
void mergesort(int data[], size_t n);
void merge(int data[], size_t n1, size_t n2);
void display(int data[], size_t n);

//Global Variables - should not be used without good reason.

int main ()
{
// Declaration section
const size_t size = 6;
int num[size];
srand (time (0) );

// Executable section
instruct ();

for (int i = 0; i < size; i++)
num[i] = rand() % 50;

cout << “Unsorted Array” << endl;
display(num,size);

mergesort(num, size);

cout << “\n\nSorted Array” << endl;
display(num, size);

pause ();
return 0;
}

void mergesort(int data[], size_t n)
{
size_t n1;
size_t n2;

if (n > 1)
{
n1 = n / 2;
n2 = n - n1;

mergesort(data, n1);
mergesort((data + n1), n2);

merge(data, n1, n2);
}
}

void merge(int data[], size_t n1, size_t n2)
{
int *temp;
size_t copied = 0;
size_t copied1 = 0;
size_t copied2 = 0;
size_t i;

temp = new int[n1 + n2];

while ((copied1 < n1) && (copied2 < n2))
{
if(data[copied1] < (data + n1)[copied2])
temp[copied++] = data[copied1++];

else
temp[copied++] = (data + n1)[copied2++];
}

while (copied1 < n1)
temp[copied++] = data[copied1++];
while (copied2 < n2)
temp[copied++] = (data + n1)[copied2++];

for (i = 0; i < n1 + n2; ++i)
data[i] = temp[i];
delete [] temp;

}

void display(int data[], size_t n)
{
int row = 0;

for (int i = 0; i < n; i++)
{
cout << data[i] << ” “;

row++ ;
if (row % 10 == 0 )
{
cout << “\n”;
}

}
}

void instruct (void)
{
// Declaration section

// Executable section
}

void pause ()
{
// Declaration section

// Executable section
cout << “\nPress any key to continue…”;
getch();
cout << “\r”;
cout << ” “;
cout << “\r”;
}

/*
Program Output

Unsorted Array
40 16 23 13 23 6

Sorted Array
6 13 16 23 23 40
Press any key to continue…

*/


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.