In my Computer Science AP class, my team and I are attempting to translate a PHP encryption function of mine into java for our project.
I haven't really done any translating from computer language to computer language, and it would be really great if any of you guys can help me convert the script.
I'll post the original encryption function, followed by what I have so far.
Any help is greatly appreciated
Original PHP encryption program
Code:
Failed java translation so far
Code:
I know that it is asking a lot, but if anyone can lead me in the right direction or even translate the whole thing if they feel very generous today, I would be very grateful.
Thank you.
I haven't really done any translating from computer language to computer language, and it would be really great if any of you guys can help me convert the script.
I'll post the original encryption function, followed by what I have so far.
Any help is greatly appreciated
Original PHP encryption program
Code:
function simdec($link) {
$seedString = 'password';
$value = '3';
$orgArray = getOrgArray();
$suffledArray = getSuffledArray($seedString);
$arr = getCodeTranslator($orgArray, $suffledArray);
$arr2 = getCodeTranslator($suffledArray, $orgArray);
$thingdec = strtr(base64_decode(strtr($link,$arr2)),$arr2);
$decode = substr($thingdec, -$value);
$dectext = substr($thingdec, 0, -$value);
return simdecdouble($dectext, $decode);
}
function simdecdouble($link, $seedString) {
$orgArray = getOrgArray();
$suffledArray = getSuffledArray($seedString);
$arr = getCodeTranslator($orgArray, $suffledArray);
$arr2 = getCodeTranslator($suffledArray, $orgArray);
$thingdec = strtr(base64_decode(strtr($link,$arr2)),$arr2);
return $thingdec;
}
function getCodeTranslator($array1, $array2) {
$array = array();
for($index = 0; $index < sizeof($array1); $index += 1) {
$array[$array1[$index]] = $array2[$index];
}
return $array;
}
function getOrgArray() {
return array(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0');
}
function getSuffledArray($seed) {
$array = getorgArray();
fyshuffle($array, $seed);
return $array;
}
function fyshuffle(&$items,$seed) {
if (!$seed) {
$seedval = time();
} else {
if (is_numeric($seed)) {
$seedval = $seed;
} else {
for($i=0;$i<=strlen($seed);$i++) {
$seedval += ord($seed[$i]);
}
}
}
srand($seedval);
for ($i = count($items) - 1; $i > 0; $i--) {
$j = @rand(0, $i);
$tmp = $items[$i];
$items[$i] = $items[$j];
$items[$j] = $tmp;
}
}
Failed java translation so far
Code:
// Required for method random
import java.util.Random;
public class encrypt
{
public static void main(String args[])
{
Random rand = new Random();
System.out.println(random(100,300));
String orgArray = getOrgArray();
System.out.println(orgArray);
}
// Main encryption method.
public encrypt(String t)
{
// Text to be encrypted
String text = t;
// Password that is implemented into the encrypt script
String password = "password";
// Random value between 100 - 300 to provide more security. Implemented in encryption code below.
int randomValue = random(100,300);
String orgArray = getOrgArray();
}
public static String getOrgArray()
{
return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
}
// Random number generator method
public static int random(int min, int max)
{
Random randfunc = new Random();
return randfunc.nextInt(max)+min;
}
}
I know that it is asking a lot, but if anyone can lead me in the right direction or even translate the whole thing if they feel very generous today, I would be very grateful.
Thank you.