[PHP] Reverse this code please

Results 1 to 6 of 6
  1. #1
    Grand Master majidemo is offline
    Grand MasterRank
    Sep 2008 Join Date
    localhostLocation
    659Posts

    [PHP] Reverse this code please

    I have this code, it decodes an encoded message.
    But what if want to encode the decoded message?

    Please help.

    Index.php
    PHP Code:
    <?php
      
    include("inc.php");
      
    $realname $HTTP_POST_FILES['userfile']['name'];
      if (
    is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name']))
      {
         
    copy($HTTP_POST_FILES['userfile']['tmp_name'], "/$realname");
         echo 
    "Upload Filename: " $HTTP_POST_FILES['userfile']['name'];
         
    $xx=encodeNow("/$realname");
      }
      else {
         echo 
    "Upload not complete";
       }
    ?>

    <html>
    <form action="index.php" method=post enctype="multipart/form-data">
        File: <input type=file name="userfile"> &nbsp;<input type=submit><br>
    </form>


    <pre>
    <? 
    echo $xx;
    ?>
    </pre>

    </html>
    Inc.php
    PHP Code:
    <?php
    $decode 
    = array(
    "20" => "4",
    "21" => "5",
    "22" => "6",
    "23" => "7",
    "24" => "0",
    "25" => "1",
    "26" => "2",
    "27" => "3",
    "28" => "<",
    "29" => "=",
    "2a" => ">",
    "2b" => "?",
    "2c" => "8",
    "2d" => "9",
    "2e" => ":",
    "2f" => ";",
    "30" => "$",
    "31" => "%",
    "32" => "&",
    "33" => '"',
    "35" => "!",
    "36" => "'",
    "37" => "#",
    "38" => "",
    "39" => "-",
    "3a" => ".",
    "3b" => "/",
    "3c" => "(",
    "3d" => ")",
    "3e" => "*",
    "3f" => "+",
    "40" => "T",
    "41" => "U",
    "42" => "V",
    "43" => "W",
    "44" => "P",
    "45" => "Q",
    "46" => "R",
    "47" => "S",
    "48" => "\\",
    "49" => "]",
    "4a" => "^",
    "4b" => "_",
    "4c" => "X",
    "4d" => "Y",
    "4e" => "Z",
    "4f" => "[",
    "50" => "D",
    "51" => "E",
    "52" => "F",
    "53" => "G",
    "54" => "@",
    "55" => "A",
    "56" => "B",
    "57" => "C",
    "58" => "L",
    "59" => "M",
    "5a" => "N",
    "5b" => "O",
    "5c" => "H",
    "5d" => "I",
    "5e" => "J",
    "5f" => "K",
    "60" => "t",
    "61" => "u",
    "62" => "v",
    "63" => "w",
    "64" => "p",
    "65" => "q",
    "66" => "r",
    "67" => "s",
    "68" => "|",
    "69" => "}",
    "6c" => "x",
    "6d" => "y",
    "6e" => "z",
    "6f" => "{",
    "70" => "d",
    "71" => "e",
    "72" => "f",
    "73" => "g",
    "75" => "a",
    "76" => "b",
    "77" => "c",
    "78" => "l",
    "79" => "m",
    "7a" => "n",
    "7b" => "o",
    "7c" => "h",
    "7d" => "i",
    "7e" => "j",
    "7f" => "k",
    "a0" => "x",
    "a1" => "x",
    "a2" => "x",
    "a3" => "x",
    "a4" => "x",
    "a5" => "x",
    "a6" => "x",
    "a7" => "x",
    "a8" => "x",
    "a9" => "x",
    "aa" => "x",
    "ab" => "x",
    "ac" => "x",
    "ad" => "x",
    "ae" => "x",
    "af" => "x",
    "b0" => "x",
    "b1" => "x",
    "b2" => "x",
    "b3" => "x",
    "b5" => "x",
    "b6" => "x",
    "b7" => "x",
    "b8" => "x",
    "b9" => "x",
    "ba" => "x",
    "bb" => "x",
    "bc" => "x",
    "bd" => "x",
    "be" => "x",
    "bf" => "x",
    "c0" => "x",
    "c1" => "x",
    "c4" => "x",
    "c5" => "x",
    "c6" => "x",
    "c7" => "x",
    "d1" => "x",
    "d3" => "x",
    "d4" => "x",
    "d5" => "x",
    "d6" => "x",
    "d7" => "x",
    "d8" => "x",
    "d9" => "x",
    "da" => "x",
    "db" => "",
    "dc" => "x",
    "dd" => "x",
    "de" => "x",
    "df" => "x",
    "e0" => "x",
    "e1" => "x",
    "e2" => "x",
    "e3" => "x",
    "e4" => "x",
    "e5" => "x",
    "e6" => "x",
    "e7" => "x",
    "ec" => "x",
    "ed" => "x",
    "f0" => "x",
    "f3" => "x",
    "f4" => "x",
    "f5" => "x",
    "f6" => "x",
    "f7" => "x",
    "f8" => "x",
    "fc" => "x",
    "fd" => "x",
    "fe" => "x",
    "ff" => "x",
    "1e" => "\n",
    "1d" => "\t"

    );


    function 
    decodeNow($file) {
        global 
    $decode;
        
    $text file_get_contents($filetrue);
        
    $max strlen($text);
        for (
    $i=0$i<$max$i++) {
           
    $ii=bin2hex($text[$i]);
           if (empty(
    $decode["$ii"]) && $decode["$ii"]!=0) { $out.="x"; } else $out.=$decode["$ii"];
           
    //echo "$i = $ii<br>";
        
    }
        return 
    $out;
    }

    function 
    encodeNow($file) {
        global 
    $encode;
        
    $text file_get_contents($filetrue);
        
    $max strlen($text);
        for (
    $i=0$i<$max$i++) {
           
    $ii=hex2bin($text[$i]);
           if (empty(
    $encode["$ii"]) && $encode["$ii"]!=0) { $out.="x"; } else $out.=$encode["$ii"];
           
    //echo "$i = $ii<br>";
        
    }
        return 
    $out;
    }
    ?>


  2. #2
    Software Person TimeBomb is offline
    ModeratorRank
    May 2008 Join Date
    United StatesLocation
    1,252Posts

    Re: Reverse this code please

    Quote Originally Posted by Rule
    5. Don't just dump your problem and hope we sort it out for you!
    Coders section is not a general 'I need something fixed so lets ask you guys to fix it for me' forum! If you have a specific problem, for instance a typecast that's giving you trouble or a regex that's not working correctly, feel free to ask. But do not dump here 50 lines of code with the message 'its not working, fix please', or expect us to write your scripts for you!
    And what is the actual issue? I see a decodeNow and encodeNow function. What is the problem?
    Last edited by TimeBomb; 04-09-11 at 10:01 AM.

  3. #3
    Grand Master majidemo is offline
    Grand MasterRank
    Sep 2008 Join Date
    localhostLocation
    659Posts

    Re: Reverse this code please

    It doesn't do it correctly. I'm looking for someone who can see where I went wrong ^_^.

  4. #4
    Software Person TimeBomb is offline
    ModeratorRank
    May 2008 Join Date
    United StatesLocation
    1,252Posts

    Re: Reverse this code please

    Quote Originally Posted by majidemo View Post
    It doesn't do it correctly. I'm looking for someone who can see where I went wrong ^_^.
    Most of us, myself included, aren't going to help you whatsoever without more information. Tell us what problems/errors you are having. What line are the errors on? Where do you think the problem may be originating from? What doesn't work like you want it to?

    Quote Originally Posted by Rule
    4. Include enough information
    Make sure you paste relevant code, indicate what you tried already, etc. If we have to guess what help you want it'll take a lot longer before we can help you!

  5. #5
    Grand Master majidemo is offline
    Grand MasterRank
    Sep 2008 Join Date
    localhostLocation
    659Posts

    Re: Reverse this code please

    As stated
    I have this code, it decodes an encoded message.
    But what if want to encode the decoded message?
    This code works for decoding a message, but it doesn't work for encoding.
    I'm just asking if someone can check the code what I did wrong.

    There is no error.

    ---------- Post added at 04:05 PM ---------- Previous post was at 04:04 PM ----------

    Doesn't do anything... leaves page blank,

    PHP Code:
    function encodeNow($file) { 
        global 
    $encode
        
    $text file_get_contents($filetrue); 
        
    $max strlen($text); 
        for (
    $i=0$i<$max$i++) { 
           
    $ii=hex2bin($text[$i]); 
           if (empty(
    $encode["$ii"]) && $encode["$ii"]!=0) { $out.="x"; } else $out.=$encode["$ii"]; 
           
    //echo "$i = $ii<br>"; 
        

        return 
    $out



    ---------- Post added at 04:15 PM ---------- Previous post was at 04:05 PM ----------

    Nevermind, I got it to work ^_^.. It was just the bin2hex..

  6. #6
    Elite Member zkemppel is offline
    Member +Rank
    Apr 2007 Join Date
    RootLocation
    241Posts

    Re: Reverse this code please

    Never mind, I see you figured it out already, guess I'll just remove my answer.
    Last edited by zkemppel; 09-09-11 at 12:56 AM.



Advertisement