canadabeeau Posted December 27, 2009 Share Posted December 27, 2009 How hackable is this? function encrypt($string, $key) { $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result.=$char; } return $result; } print_r(encrypt('<?php..zzzzzzzzzzz... ?>', 'mysite.com'); Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 27, 2009 Share Posted December 27, 2009 How hackable is this? function encrypt($string, $key) { $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result.=$char; } return $result; } print_r(encrypt('<?php..zzzzzzzzzzz... ?>', 'mysite.com'); Define what you mean. What it does, is encodes a string with a key, splitting each character up, turning it into its ASCII form, and binding it with the key and re-encoding it into the string. You may do "return base64_encode($result)" to be in a ore easily transportable format. Since the end user does not know the custom encoding method, nor the key, it is presumably improbable for an attacker to retrieve the encoded string, what its original value is. Gave up on writing a module? lol.. You may want to use this slightly modified code, as with what I mentioned, It's more secure and will place it in a variable (what you wanted): function encrypt($string, $key) { $result = ''; for($i=0; $i<strlen($string); $i++) { $char = substr($string, $i, 1); $keychar = substr($key, ($i % strlen($key))-1, 1); $char = chr(ord($char)+ord($keychar)); $result.=$char; } return base64_encode($result); } $php_code = '<?php echo "Secret"; ?>'; //What you want encoded, but runnable $encoded_phpcode = encrypt($php_code, 'asdf1234'); //The actual encoded PHP, to be decoded by user Note you will have to use base64_decode on the decrypt function, before it is unencoded. I'd give that it's as strong as any basic encryption, but it is unique, so more obscure to decode. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.