I've made this PHP encrypt script. Now I was wondering how this could be done in Java. I was considering giving this up, and coding it in Javascript so it could be used in both languages. This is unfortunately not what I want. How can I do so in Java?
<?php
$encrypted = encrypt("Hello goodbye", "Pizza");
$decrypted = decrypt($encrypted, "Pizza");
echo $encrypted;
echo "<br/>";
echo $decrypted;
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);
}
function decrypt($string, $key) {
$result = '';
$string = base64_decode($string);
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;
}
?>
I am not asking to write some code for me (but it would be great), but I would like to be helped or get a push in the right direction
EDIT: I do not want to post and get to the PHP file via Java