gorance Posted January 1, 2011 Share Posted January 1, 2011 I have implemented the base64_encode() function with some custom mapping table so I could encode some binary data more securely without anyone knowing how to decode it here is the class <?php class Base64 { /** * I have changed letter placement (P <=> x, S <=> 9) and the cases * You can completely redo the mapping table */ private static $BinaryMap = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', // 7 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'x', // 15 'q', 'r', '9', 't', 'u', 'v', 'w', 'x', // 23 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', // 31 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', // 39 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', // 47 'W', 'P', 'Y', 'Z', '0', '1', '2', '3', // 55 '4', '5', '6', '7', '8', 'S', '+', '/', // 63 '=', // padding char ); public function __construct() {} public function base64_encode($input) { $output = ""; $chr1 = $chr2 = $chr3 = $enc1 = $enc2 = $enc3 = $enc4 = null; $i = 0; // $input = self::utf8_encode($input); while($i < strlen($input)) { $chr1 = ord($input[$i++]); $chr2 = ord($input[$i++]); $chr3 = ord($input[$i++]); $enc1 = $chr1 >> 2; $enc2 = (($chr1 & 3) << 4) | ($chr2 >> 4); $enc3 = (($chr2 & 15) << 2) | ($chr3 >> 6); $enc4 = $chr3 & 63; if (is_nan($chr2)) { $enc3 = $enc4 = 64; } else if (is_nan($chr3)) { $enc4 = 64; } $output .= self::$BinaryMap[$enc1] . self::$BinaryMap[$enc2] . self::$BinaryMap[$enc3] . self::$BinaryMap[$enc4]; } return $output; } public function utf8_encode($input) { $utftext = null; for ($n = 0; $n < strlen($input); $n++) { $c = ord($input[$n]); if ($c < 128) { $utftext .= chr($c); } else if (($c > 128) && ($c < 2048)) { $utftext .= chr(($c >> 6) | 192); $utftext .= chr(($c & 63) | 128); } else { $utftext .= chr(($c >> 12) | 224); $utftext .= chr((($c & 6) & 63) | 128); $utftext .= chr(($c & 63) | 128); } } return $utftext; } } ?> and the usage as follows: <?php $string = pack('H*', "31c85c5aaa56c1f0102301ea497d0ab010e4e131af261787"); //HEX echo Base64::base64_encode($string); echo "<br />"; echo base64_encode($string); ?> and the output will be: mCHCwQPwWFaqiWhQ9x0kSbdK4tgVjHEh // with custom mapping MchcWqpWwfAQIwHqSX0KsBDk4TGvJheH // the base64_encode() I need help how to decode the this key Link to comment https://forums.phpfreaks.com/topic/223160-need-php-help-for-base64-decode/ Share on other sites More sharing options...
gorance Posted January 2, 2011 Author Share Posted January 2, 2011 i use this to decode base64 code its work only for base64 bat dont work to decode this mCHCwQPwWFaqiWhQ9x0kSbdK4tgVjHEh // with custom mapping <? $id = base64_decode($_GET["channel"]); $fp = FOpen ("bolt.txt", "r"); $blem = FRead ($fp, FileSize ("bolt.txt")); $id = str_replace ("\n", " ", $id); $id = str_replace ("SELECT", " ", $id); $id = str_replace ("FROM", " ", $id); $id = str_replace ("select", " ", $id); $id = str_replace ("from", " ", $id); $id = str_replace (">", ">", $id); $id = str_replace ("<", "<", $id); $stream = base64_decode("proxy list URL"); $kontrola_funkcnosti_odkazu = file_get_contents("$stream"); $adresa = StrChr($id, "|"); $adresa = str_replace ("|", "", $adresa); $heslo = current(explode("|", $id, 2)); if (($heslo==$blem) AND ($kontrola_funkcnosti_odkazu=="OK")){ header('Content-type: application/octet-stream'); $q = "$adresa"; readfile ($q); } else{ header('Content-type: application/octet-stream'); $q = "http://stramlink/Intro.mp4"; readfile ($q); } ?> Link to comment https://forums.phpfreaks.com/topic/223160-need-php-help-for-base64-decode/#findComment-1153800 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.