Помогите перевести код из языка Java на язык Php

  • Автор темы LEXASOFT
  • Дата начала
L

LEXASOFT

Гость
#1
Нужна аналогичная функция на входе которой password и seq для получения значения pass.
<!--shcode--><pre><code class='java'>p = new StringBuffer(Code.Code(password.getPassword(), Utl.ParseHexToChar(getParameter("seq"))));
url = new URL(getDocumentBase(), getParameter("uri") + "msisdn=" + m + "&pass=" + p.toString() + "&par=" + getParameter("seq") + "&site=" + getParameter("site") + "&lang=" + lng + "&sid=" + getParameter("sid") + "&serv=" + getParameter("serv"));[/CODE]
<div class="sp-wrap"><div class="sp-head-wrap"><div class="sp-head folded clickable">Файлики с классами</div></div><div class="sp-body"><div class="sp-content">Tbinary.java
<!--shcode--><pre><code class='java'>final class Tbinary
{

final void SetNull(int start)
{
if(start < 31)
{
for(int i = start; i < 31; i++)
boolArr = false;

pos = start - 1;
}
}

Tbinary(long value)
{
boolArr = new boolean[31];
if(value > (long)0)
Assign(value);
else
SetNull(0);
}

final void Assign(long value)
{
long l_num = value;
SetNull(0);
for(byte i = 30; i >= 0; i--)
{
if(hexArr > l_num)
continue;
boolArr = true;
if(l_num == value)
pos = i;
if(hexArr == l_num)
break;
l_num -= hexArr;
}

}

final long GetNumber()
{
long res = 0L;
for(byte i = 0; i <= pos; i++)
if(boolArr)
res += hexArr;

return res;
}

final void Copy(Tbinary copyBin)
{
for(byte i = 0; i <= copyBin.pos; i++)
boolArr = copyBin.boolArr;

SetNull(copyBin.pos + 1);
}

private static final byte hexCount = 31;
boolean boolArr[];
int pos;
private static long hexArr[];

static
{
hexArr = new long[31];
hexArr[0] = 1L;
for(byte i = 1; i < 31; i++)
hexArr = hexArr[i - 1] << 1;

}
}[/CODE]

Code.java
<!--shcode--><pre><code class='java'>public final class Code
{

private Code()
{
}

private static void BinMul(Tbinary binRes, Tbinary binMul1, Tbinary binMul2)
{
binRes.SetNull(0);
byte k;
for(k = 0; k <= binMul2.pos; k++)
{
if(!binMul2.boolArr[k])
continue;
for(byte i = 0; i <= binMul1.pos; i++)
binRes.boolArr[i + k] ^= binMul1.boolArr;

}

k = (byte)(binRes.boolArr.length - 1);
do
{
if(k < 0)
break;
if(binRes.boolArr[k])
{
binRes.pos = k;
break;
}
k--;
} while(true);
}

private static void BinRest(Tbinary binRes, Tbinary binDiv1, Tbinary binDiv2)
{
binRes.Copy(binDiv1);
while(binRes.pos > binDiv2.pos)
{
int k = binRes.pos;
int i = binDiv2.pos;
while(i >= 0)
{
binRes.boolArr[k] ^= binDiv2.boolArr;
if(!binRes.boolArr[k] && binRes.pos == k)
binRes.pos--;
k--;
i--;
}
}
if(binRes.pos == binDiv2.pos)
{
for(byte i = 0; i <= binDiv2.pos; i++)
binRes.boolArr ^= binDiv2.boolArr;

binRes.pos--;
}
}

public static final String Code(char pass[], char mix[])
{
int poly[] = {
283, 313, 299, 301, 379, 285, 319, 451, 451, 463,
471, 477, 487, 499, 501, 397, 395, 395, 419, 425,
505, 445, 333, 351, 355, 357, 361, 369, 375, 433,
391, 415
};
int len = pass.length;
String res = "";
char shTemp[] = new char[len];
char rand[] = new char[len];
Tbinary poly256[] = new Tbinary[len];
Tbinary factor256[] = new Tbinary[len];
long lTemp = 0L;
for(byte i = 0; i < len; i++)
{
poly256 = new Tbinary(0L);
factor256 = new Tbinary(0L);
lTemp += pass;
}

lTemp %= 256;
for(byte i = 0; i < len; i++)
{
rand = (char)(int)(((lTemp ^ (long)pass ^ (long)mix) + (long)mix) % (long)256);
lTemp += rand;
shTemp = (char)poly[(rand + (pass << 1)) % 32];
poly256.Assign(shTemp);
factor256.Assign((rand + (mix << 1)) % (shTemp - 2) + 2);
}

Tbinary binSrc = new Tbinary(0L);
Tbinary binTemp = new Tbinary(0L);
Tbinary binTemp1 = new Tbinary(0L);
for(byte i = 0; i < len; i++)
{
binSrc.Assign(rand);
BinMul(binTemp, binSrc, factor256);
BinRest(binTemp, binTemp, poly256);
lTemp = (long)rand ^ binTemp.GetNumber();
res = String.valueOf(res) + String.valueOf(String.valueOf(Integer.toHexString((int)(lTemp >>> 4))) + String.valueOf(Integer.toHexString((int)(lTemp & (long)15))));
}

return res;
}
}[/CODE]

Utl.java
<!--shcode--><pre><code class='java'>public final class Utl
{

private Utl()
{
}

public static final String ParseCharToHex(char chArr[])
{
String st = "";
for(int i = 0; i < chArr.length; i++)
{
String sTemp = Integer.toHexString(chArr);
switch(sTemp.length())
{
case 1: // '\001'
st = String.valueOf(st) + String.valueOf("000".concat(String.valueOf(String.valueOf(sTemp))));
break;

case 2: // '\002'
st = String.valueOf(st) + String.valueOf("00".concat(String.valueOf(String.valueOf(sTemp))));
break;

case 3: // '\003'
st = String.valueOf(st) + String.valueOf("0".concat(String.valueOf(String.valueOf(sTemp))));
break;

default:
st = String.valueOf(st) + String.valueOf(sTemp);
break;
}
}

return st;
}

public static final char[] ParseHexToChar(String st)
{
char chArr[] = new char[st.length() >>> 2];
for(int i = 0; i < chArr.length; i++)
chArr = (char)Integer.decode("0x".concat(String.valueOf(String.valueOf(st.substring(i << 2, (i << 2) + 4))))).intValue();

return chArr;
}

public static final String CodePswd(char pswd[], char key[])
{
String st = "";
int iTemp = 0;
for(int i = 1; i < key.length; i++)
iTemp += ((key[i - 1] << 3) + key + iTemp) % 256;

for(int i = 0; i < key.length; i++)
{
iTemp = (iTemp + (key << 4)) % 256;
key = (char)((iTemp + ((key ^ iTemp) % 256 << 8)) % 256);
}

for(int i = 0; i < pswd.length; i++)
{
String sTemp = Integer.toHexString(pswd ^ key[i % key.length]);
if(sTemp.length() == 1)
st = String.valueOf(st) + String.valueOf("0".concat(String.valueOf(String.valueOf(sTemp))));
else
st = String.valueOf(st) + String.valueOf(sTemp);
}

return st;
}

public static final String DecodePswd(String pswd, char key[])
{
char pswdChar[] = new char[pswd.length() >>> 1];
for(int i = 0; i < pswdChar.length; i++)
pswdChar = (char)Integer.decode("0x".concat(String.valueOf(String.valueOf(pswd.substring(i << 1, (i << 1) + 2))))).intValue();

int iTemp = 0;
for(int i = 1; i < key.length; i++)
iTemp += ((key[i - 1] << 3) + key + iTemp) % 256;

for(int i = 0; i < key.length; i++)
{
iTemp = (iTemp + (key << 4)) % 256;
key = (char)((iTemp + ((key ^ iTemp) % 256 << 8)) % 256);
}

for(int i = 0; i < pswdChar.length; i++)
pswdChar ^= key[i % key.length];

return String.valueOf(pswdChar);
}
}[/CODE]
Файлики архивом
Посмотреть вложение java.zip