Example Encoding / Decoding Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Example Encoding / Decoding Script

    a little script to get people started on there own encoding/decoding script

    made this post cos alot of people continue to this day to ask how to either make one
    or how to encode / decode something.

    all you need to do is make your own file, add this code to it. then run the script to see
    the working result.

    then you can add the rest of the alphabet/symbols you want to be included into your
    encode/decode sequence and what type of style you want to decode the letter/symbols in.

    example:
    right now i set it so
    A = 9E
    but you could make it stronger by setting it to something like
    A = 6GH42RR
    etc etc..

    PHP Code:
    <?php
              
    /** An Example Encoding / Decoding Script
                  By Ghost
               */

    /** Encode */
    function Encode($Data

    $Encode_From = array('A''B''C'); 
    $Encode_To = array('9E''R4''D1'); 
    for(
    $m 0$m<count($Encode_From); $m++)  

    $Data str_replace($Encode_From[$m], rtrim($Encode_To[$m]), $Data); 
    }  
    Return 
    $Data
    }
    echo 
    '<b>Encoded Data:</b><br/>';
    echo 
    Encode('ABC');

    echo 
    '<br/><br/>';

    /** Decode */
    function Decode($Data

    $Decode_From = array('9E''R4''D1'); 
    $Decode_To = array('A''B''C'); 
    for(
    $m 0$m<count($Decode_From); $m++)  

    $Data str_replace($Decode_From[$m], rtrim($Decode_To[$m]), $Data); 
    }  
    Return 
    $Data
    }
    echo 
    '<b>Decoded Data:</b><br/>';
    echo 
    Decode('9ER4D1');

    ?>
    you would also want to prob put your own upper/lowercase checking in also.
    as right now this only looks for uppercase chars, as i put them all in as uppercase in the array.

    anyway this should help you make your own version anyhow.

    hope it helps people.
    <?php
    include ('Ghost');
    if ($Post == true) {
    echo '

    sigpic
    alt='coding-talk.com!!' />';
    echo 'Sharing Is Caring!';
    } else {
    echo '

    alt='the username GHOST has been comprimised!' />';
    echo 'OMG SOMEBODY HELP ME!!';
    }
    ?>

    #2
    Use associative arrays and functions array_keys / array_values instead of that loop.
    Here's my variant of that code:
    PHP Code:
    class crypt
    {
        private static 
    $chars=array(
            
    'A'        =>        '9E',
            
    'B'        =>        'R4',
            
    'C'        =>        'D1'//and so on...
            
    );

        public static function 
    decode($str)
        {
            return 
    str_replace(array_values(self::$chars),array_keys(self::$chars),$str);
        }

        public static function 
    encode($str)
        {
            return 
    str_replace(array_keys(self::$chars),array_values(self::$chars),$str);
        }
    }
    echo 
    crypt::decode('9ER4D1');
    //^will echo 'ABC' 
    Last edited by Andrew.; 20.09.12, 09:33.

    Comment


      #3
      Originally posted by Andrew. View Post
      Use associative arrays and functions array_keys / array_values instead of that loop.
      Here's my variant of that code:
      PHP Code:
      class crypt
      {
          private static 
      $chars=array(
              
      'A'        =>        '9E',
              
      'B'        =>        'R4',
              
      'C'        =>        'D1'//and so on...
              
      );

          public static function 
      decode($str)
          {
              return 
      str_replace(array_values(self::$chars),array_keys(self::$chars),$str);
          }

          public static function 
      encode($str)
          {
              return 
      str_replace(array_keys(self::$chars),array_values(self::$chars),$str);
          }
      }
      echo 
      crypt::decode('9ER4D1');
      //^will echo 'ABC' 
      i like this alot more than my version lol. does exactly the same thing. just not using the loop.
      thanks. im not that upto date on classes. hardly ever use them. but a great example of how to use one.
      <?php
      include ('Ghost');
      if ($Post == true) {
      echo '

      sigpic
      alt='coding-talk.com!!' />';
      echo 'Sharing Is Caring!';
      } else {
      echo '

      alt='the username GHOST has been comprimised!' />';
      echo 'OMG SOMEBODY HELP ME!!';
      }
      ?>

      Comment

      Working...
      X