Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* Response to Yahoo Answers Question */
- /* Your's Cleaned Up and Working */
- $alphaex = range('a','z');
- $inputwordex = range('a','e');
- echo '<pre>';
- print_r($inputwordex);
- echo '</pre>';
- $iword = 0;
- $decodeword = "";
- while ($iword < 5){
- $ialpha = 0;
- $found = "N";
- while ($found == "N"){
- if ($inputwordex[$iword] == $alphaex[$ialpha]) {
- $i = $ialpha + 24;
- $i = $i % count($alphaex); // Remainder of $i / count($alphaex) or $i / 26; Remeber that a is = 0 and z is 25; Array Indexes start at 0 not 1;
- $decodeword .= $alphaex[$i];
- echo "<br>" . $decodeword;
- $found = "Y";
- }else{
- $ialpha += 1;
- }
- }
- $iword += 1;
- }
- echo "<br>";
- echo $decodeword;
- /* Using Functions to offset a string. Only Does LowerCase */
- function offset_encode($str, $offset=24){
- $alphaex = range('a','z');
- $r = '';
- for($i=0; $i < strlen($str); ++$i){
- $num = (array_search($str{$i}, $alphaex) + $offset) % count($alphaex);
- $r .= $alphaex[$num];
- }
- return $r;
- }
- function offset_decode($str, $offset=24){
- $alphaex = range('a','z');
- $r = '';
- for($i=0; $i < strlen($str); ++$i){
- $num = (array_search($str{$i}, $alphaex) - $offset);
- if($num < 0){
- $num += count($alphaex);
- }
- $r .= $alphaex[$num];
- }
- return $r;
- }
- $offset = 24;
- $str = 'abcde';
- $encoded = offset_encode($str, $offset);
- $decoded = offset_decode($encoded, $offset);
- echo 'String: ' . $str . '<br>' . 'Encoded: ' . $encoded . '<br>' . 'Decoded: ' . $decoded . '<br>';
- /* String Encoding and Decoding */
- echo '<h3>str_encode() and str_decode()</h3>';
- defined('STR_SALT')? null : define('STR_SALT','Dwnp=MduTHp0Bn4x>u0p:hf=*[smx5T+ieL9Zr-.Wc4Xc{r0rjjT[Qhv,v{$)sGl');
- function str_encode($i){
- return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5(STR_SALT), ($i . sha1(STR_SALT) . STR_SALT) , MCRYPT_MODE_CBC, md5(md5(STR_SALT))));
- }
- function str_decode($i){
- return str_replace(Array(sha1(STR_SALT),STR_SALT),'', rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5(STR_SALT), base64_decode($i), MCRYPT_MODE_CBC, md5(md5(STR_SALT))), "\0"));
- }
- $str = 'abcde';
- $encoded = str_encode($str);
- $decoded = str_decode($encoded);
- echo 'String: ' . $str . '<br>' . 'Encoded: ' . $encoded . '<br>' . 'Decoded: ' . $decoded . '<br>';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement