Skip to content

Instantly share code, notes, and snippets.

@DrARoberts
Last active May 10, 2018 02:39
Show Gist options
  • Save DrARoberts/f315e274ffc8590309d79a8740b94d74 to your computer and use it in GitHub Desktop.
Save DrARoberts/f315e274ffc8590309d79a8740b94d74 to your computer and use it in GitHub Desktop.
Simple Encryption Protector for Number Systems
/**
* protectNumbersStripper()
*
* Protects an Number System with an alpha numeric stripper by replace the number of characters to be $protect and replaced
* with an alpha character from the english characters in capitals for IP Address, Phone Numbers, Addresses!
*
* @param string $number the number string being protected
* @param integer $protect the number of character to replace 1 - 9
* @param integer $attempted the number of random stab attempt to do replacement
* @return string
*/
function protectNumbersStripper($number, $protect = 2, $attempted = 19) {
static $_poolalpha = NULL;
static $_poolcharley = NULL;
static $_pooldelta = NULL;
static $_poolgamma = NULL;
static $_seed = NULL;
if (is_numeric($seeder = substr($number, strlen($number) - 2, 1)) && is_null($_seed))
$_seed = floor($seeder / 4);
elseif ( is_null($_seed) )
$_seed = mt_rand(0, 3);
if (is_null($_poolalpha))
{
$_poolalpha = array(0=>'A', 1=>'B', 2=>'C', 3=>'D', 4=>'E', 5=>'F', 6=>'G', 7=>'H', 8=>'I', 9=>'J');
switch ("$_seed")
{
default:
case "0":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_poolalpha);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolalpha[$keys[($i==9?0:$i+1)]];
}
$_poolalpha = $tmp;
}
break;
case "1":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_poolalpha);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolalpha[$keys[($i==0?9:$i-1)]];
}
$_poolalpha = $tmp;
}
break;
case "2":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_poolalpha);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolalpha[$keys[($i==0?9:$i-1)]];
}
$_poolalpha = $tmp;
}
break;
case "3":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_poolalpha);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolalpha[$keys[($i==9?0:$i+1)]];
}
$_poolalpha = $tmp;
}
break;
}
}
if (is_null($_poolcharley))
{
$_poolcharley = array(0=>'V', 1=>'U', 2=>'T', 3=>'S', 4=>'R', 5=>'Q', 6=>'Y', 7=>'W', 8=>'X', 9=>'Z');
switch ("$_seed")
{
default:
case "0":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_poolcharley);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolcharley[$keys[($i==9?0:$i+1)]];
}
$_poolcharley = $tmp;
}
break;
case "1":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_poolcharley);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolcharley[$keys[($i==0?9:$i-1)]];
}
$_poolcharley = $tmp;
}
break;
case "2":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_poolcharley);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolcharley[$keys[($i==0?9:$i-1)]];
}
$_poolcharley = $tmp;
}
break;
case "3":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_poolcharley);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolcharley[$keys[($i==9?0:$i+1)]];
}
$_poolcharley = $tmp;
}
break;
}
}
if (is_null($_pooldelta))
{
$_pooldelta = array(0=>chr(mt_rand(ord("A"), ord("Z"))), 1=>chr(mt_rand(ord("A"), ord("Z"))), 2=>chr(mt_rand(ord("A"), ord("Z"))), 3=>chr(mt_rand(ord("A"), ord("Z"))), 4=>chr(mt_rand(ord("A"), ord("Z"))), 5=>chr(mt_rand(ord("A"), ord("Z"))), 6=>chr(mt_rand(ord("A"), ord("Z"))), 7=>chr(mt_rand(ord("A"), ord("Z"))), 8=>chr(mt_rand(ord("A"), ord("Z"))), 9=>chr(mt_rand(ord("A"), ord("Z"))));;
switch ("$_seed")
{
default:
case "0":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_pooldelta);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_pooldelta[$keys[($i==9?0:$i+1)]];
}
$_pooldelta = $tmp;
}
break;
case "1":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_pooldelta);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_pooldelta[$keys[($i==0?9:$i-1)]];
}
$_pooldelta = $tmp;
}
break;
case "2":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_pooldelta);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_pooldelta[$keys[($i==0?9:$i-1)]];
}
$_pooldelta = $tmp;
}
break;
case "3":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_pooldelta);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_pooldelta[$keys[($i==9?0:$i+1)]];
}
$_pooldelta = $tmp;
}
break;
}
}
if (is_null($_poolgamma))
{
$_poolgamma = array(0=>chr(mt_rand(ord("A"), ord("Z"))), 1=>chr(mt_rand(ord("A"), ord("Z"))), 2=>chr(mt_rand(ord("A"), ord("Z"))), 3=>chr(mt_rand(ord("A"), ord("Z"))), 4=>chr(mt_rand(ord("A"), ord("Z"))), 5=>chr(mt_rand(ord("A"), ord("Z"))), 6=>chr(mt_rand(ord("A"), ord("Z"))), 7=>chr(mt_rand(ord("A"), ord("Z"))), 8=>chr(mt_rand(ord("A"), ord("Z"))), 9=>chr(mt_rand(ord("A"), ord("Z"))));
switch ("$_seed")
{
default:
case "0":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_poolgamma);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolgamma[$keys[($i==9?0:$i+1)]];
}
$_poolgamma = $tmp;
}
break;
case "1":
for($i = 0; $i < $_seed*256; $i++)
{
$tmp = array();
$keys = array_keys($_poolgamma);
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolgamma[$keys[($i==0?9:$i-1)]];
}
$_poolgamma = $tmp;
}
break;
case "2":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_poolgamma);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolgamma[$keys[($i==0?9:$i-1)]];
}
$_poolgamma = $tmp;
}
break;
case "3":
for($i = 0; $i < $_seed*256; $i++)
{
$tmpkeys = $tmp = array();
$keys = array_keys($_poolgamma);
shuffle($keys);
foreach($keys as $key)
$tmpkeys[] = $key;
$keys = $tmpkeys;
for($id = 0; $id < count($keys) - 1; $id++)
{
$tmp[$id] = $_poolgamma[$keys[($i==9?0:$i+1)]];
}
$_poolgamma = $tmp;
}
break;
}
}
switch ("$_seed")
{
case "0":
default:
$keys = array_keys($_poolalpha);
shuffle($keys);
$attempts = $replaced = 0;
while($replaced < $protect && $attempts <= $attempted)
{
$number = str_replace($key = $keys[mt_rand(0, count($keys) - 1)], $_poolalpha[$keys[$key]], $number);
if (strpos(" $number", $_poolalpha[$keys[$key]]) > 0)
{
$replaced++;
}
$attempts++;
}
$_seed = NULL;
break;
case "1":
$keys = array_keys($_poolcharley);
shuffle($keys);
$attempts = $replaced = 0;
while($replaced < $protect && $attempts <= $attempted)
{
$number = str_replace($key = $keys[mt_rand(0, count($keys) - 1)], $_poolcharley[$keys[$key]], $number);
if (strpos(" $number", $_poolcharley[$keys[$key]]) > 0)
{
$replaced++;
}
$attempts++;
}
$_seed = NULL;
break;
case "2":
$keys = array_keys($_pooldelta);
shuffle($keys);
$attempts = $replaced = 0;
while($replaced < $protect && $attempts <= $attempted)
{
$number = str_replace($key = $keys[mt_rand(0, count($keys) - 1)], $_pooldelta[$keys[$key]], $number);
if (strpos(" $number", $_pooldelta[$keys[$key]]) > 0)
{
$replaced++;
}
$attempts++;
}
$_seed = NULL;
break;
case "3":
$keys = array_keys($_poolgamma);
shuffle($keys);
$attempts = $replaced = 0;
while($replaced < $protect && $attempts <= $attempted)
{
$number = str_replace($key = $keys[mt_rand(0, count($keys) - 1)], $_poolgamma[$keys[$key]], $number);
if (strpos(" $number", $_poolgamma[$keys[$key]]) > 0)
{
$replaced++;
}
$attempts++;
}
$_seed = NULL;
break;
}
return $number;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment