Topic: PHP encryption help

I am trying to learn how to send data from a webpage written in php that a person types in, to be encrypted when they click send, and to arrive in an email encrypted. My php hosting does NOT have Mcrypt and it wont be possible to get it.

However I did come up with a script that on the face 'seems' to work, but damned if I can get it to show me the encrypted data, my knowledge of php seems to short still to make it want to show me $result at the different stages? Or maybe I am missing something else?

Anyways here is the original script I obtained. I made a separate notation for $string = "hello world" and $key = "goodbye"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<?php
function Encrypt($string, $key)
{
$result = '';
for($i=1; $i<=strlen($string); $i++)
{
$char = substr($string, $i-1, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return $result;
}

function Decrypt($string, $key)
{
$result = '';
for($i=1; $i<=strlen($string); $i++)
{
$char = substr($string, $i-1, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
?>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


This is the actual code I am trying after my edits:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



<?php

$string = "hello world";
$key = "goodbye";

function Encrypt($string, $key)
{
$result = '';
for($i=1; $i<=strlen($string); $i++)
{
$char = substr($string, $i-1, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return $result;
}

echo $result;

function Decrypt($string, $key)
{
$result = '';
for($i=1; $i<=strlen($string); $i++)
{
$char = substr($string, $i-1, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}
echo $result;
?>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This does not need to be the mona lisa, aka DES or 256 bit encryption of some sort... just needs to be able to encrypt in a fair way, and decrypt as well. If anyone can help me I would love you to pieces. This is for my self educational efforts to learn more about php and security related aspects (Imma security freak after all)

Everything bad in the economy is now Obama's fault. Every job lost, all the debt, all the lost retirement funds. All Obama. Are you happy now? We all get to blame Obama!
Kemp currently not being responded to until he makes CONCISE posts.
Avogardo and Noir ignored by me for life so people know why I do not respond to them. (Informational)

Re: PHP encryption help

<?php
$string = "hello world";
$key = "goodbye";


function Encrypt($string, $key)
{
$result = '';
for($i=1; $i<=strlen($string); $i++)
{
$char = substr($string, $i-1, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)+ord($keychar));
$result.=$char;
}
return $result;
}

function Decrypt($string, $key)
{
$result = '';
for($i=1; $i<=strlen($string); $i++)
{
$char = substr($string, $i-1, 1);
$keychar = substr($key, ($i % strlen($key))-1, 1);
$char = chr(ord($char)-ord($keychar));
$result.=$char;
}
return $result;
}

$encrypted_output = encrypt($string, $key);
$decrypted_output = decrypt($encrypted_output, $key);

echo $encrypted_output;
echo "<br />";
echo $decrypted_output;
?>

Elrohir
"Abstract art is the product of the untalented, sold by the unprincipled to the utterly bewildered.."

Re: PHP encryption help

Thank you kindly smile

Everything bad in the economy is now Obama's fault. Every job lost, all the debt, all the lost retirement funds. All Obama. Are you happy now? We all get to blame Obama!
Kemp currently not being responded to until he makes CONCISE posts.
Avogardo and Noir ignored by me for life so people know why I do not respond to them. (Informational)