Jump to content

Recommended Posts

Quick question about encription. Is there a way of encoding information and then having a relable way of decoding it? Preferable with a easter egg. Such as:

 

$encoded_string = "Testing".$secretword;

 

I tried using base64_encode and _decode, and it worked perfectly. The only problem is that the string length is not constant. I need a way of encoding so that the length is always the same.. 4 Charactors.. 50 Charactors. It doesnt matter, It just has to be constant. So that "test" and "Hello my name is billy bob joe" Would both encode with a str length of like.. 18. You know what I mean?

Link to comment
https://forums.phpfreaks.com/topic/174109-solved-md5-base64_encode-help/
Share on other sites

So you're after a method of encoding data where the single character string "A" and a 10MB binary document would both encrypt to the same size. Such a creature doesn't exist, for pretty obvious reasons.

 

But can you explain exactly why you think you need this?

I'm not sure what your trying to do either but this is an example of basic XOR and base_64 encryption:

 

<?php

function XOREncryption($InputString, $KeyPhrase){

    $KeyPhraseLength = strlen($KeyPhrase);

    // Loop trough input string
    for ($i = 0; $i < strlen($InputString); $i++){

        // Get key phrase character position
        $rPos = $i % $KeyPhraseLength;

        // Magic happens here:
        $r = ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]);

        // Replace characters
        $InputString[$i] = chr($r);
    }

    return $InputString;
}

//SALT
$salt = 'my_special_phrase';

//ENCRYPT
$crypted = XOREncryption('my string', $salt);

//DECRYPT
$decrypted  = XOREncryption($crypted, $salt);

?>

Try this one .... I pulled the function out of some code that I was building and my head was in 5 different spots ... I didn't get it all.  Here you go:

 

<?php

   function XOREncryption($InputString, $KeyPhrase){
    
       $KeyPhraseLength = strlen($KeyPhrase);
    
       // Loop trough input string
       for ($i = 0; $i < strlen($InputString); $i++){
    
           // Get key phrase character position
           $rPos = $i % $KeyPhraseLength;
    
           // Magic happens here:
           $r = ord($InputString[$i]) ^ ord($KeyPhrase[$rPos]);
    
           // Replace characters
           $InputString[$i] = chr($r);
       }
    
       return $InputString;
   }

//SALT
$salt = 'my_special_phrase';

//ENCRYPT
$crypted = base64_encode(XOREncryption('my string', $salt));
echo "Encrypted: " . $crypted . "<br />";

//DECRYPT
$decrypted  = XOREncryption(base64_decode($crypted), $salt);
echo "Decrypted: " . $decrypted;

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.