如何将用Delphi编写的特定代码转换为JAVA?delphi解密转换Java代码
Delphi代码是解密代码。 delphi encrypt convert Java Code
感谢这么多:
function Decrypt(const S: String; Key1, Key2, Key3: WORD): String;
var
i: Byte;
FirstResult: String;
begin
FirstResult:=HexToValue(S);
SetLength(Result, Length(FirstResult));
for i:=1 to Length(FirstResult) do begin
Result[i]:=Char(Byte(FirstResult[i]) xor (Key1 shr 8));
Key1 :=(Byte(FirstResult[i])+Key1)*Key2+Key3;
end;
end;
function HexToValue(const S: String) : String;
var i: Integer;
begin
SetLength(Result, Length(S) div 2);
for i:=0 to (Length(S) div 2)-1 do begin
Result[i+1] := Char(StrToInt('$'+Copy(S,(i*2)+1, 2)));
end;
end;
的加密问题是由 '大卫·赫弗南' 和 'stackoverflow.com'
问题1的礼貌解决了! 所以我试图将Delphi中的Decrypt代码转换为JAVA直到现在!真的很呃... 但我解决不了!哦,我的上帝! 我很遗憾..... 但我希望你能帮助我。再次... 我需要解密代码..
的Java加密代码
class SO15885898 {
private static String ValueToHex(int myInt)
{
StringBuilder sb = new StringBuilder();
sb.append(Integer.toHexString(myInt & 0xff));
if (sb.length() < 2) {
sb.insert(0, '0'); // pad with leading zero if needed
}
return sb.toString();
}
public static void main(String[] args)
{
int key1=11;
int key2=22;
int key3=33;
String value = "ABCDE";
for(int i=0; i<value.length(); i++){
byte bValue = value.substring(i).getBytes()[0];
int rValue = bValue^(key1>>8);
key1 = ((rValue+key1)*key2+key3) & 0xffff;
System.out.print(ValueToHex(rValue));
}
}
}
请的Java代码解密! 。 。
这是我的尝试:
public static void main(String[] args)
{
int key1=111;
int key2=222;
int key3=333;
i tried about this...
String resultH = "";
String resultEncrypt = "";
String resultDecrypt = "";
String value = "ABCDEF";
for(int i=0; i<value.length(); i++){
byte bValue = value.substring(i).getBytes()[0];
int rValue = bValue^(key1>>8);
key1 = ((rValue+key1)*key2+key3) & 0xffff;
resultEncrypt += ValueToHex(rValue);
resultH += HexToValue(ValueToHex(rValue).getBytes()) ;
}
key1=111;
for(int i=0; i<resultH.length(); i++){
byte bValue = resultH.substring(i).getBytes()[0];
int rValue = bValue^(key1>>8);
key1 = ((rValue+key1)*key2+key3) & 0xffff;
resultDecrypt += rValue;
}
//41db791e06a9
System.out.println("resultEncrypt : " + resultEncrypt);
//91242156862519211605712161341202650962331971751025.......................
System.out.println("resultDecrypt : " + resultDecrypt);
}
public static byte[] HexToValue(byte[] szSrc) {
int nLen = szSrc.length;
byte[] szDest = new byte[nLen/2];
char szChar[] = new char[2];
for (int I = 0; I < nLen/2; I++) {
szChar[0] = (char) szSrc[I * 2];
szChar[1] = (char) szSrc[I * 2 + 1];
byte btDest = (byte) HexToDecimal(szChar);
int nDest = btDest < 0 ? (Byte.MAX_VALUE + 1) * 2 + btDest : btDest;
szDest[I] = (byte) nDest;
}
String sRet = new String(szDest);
return szDest;
}
public static int HexToDecimal(char[] szSrc) {
int nRet = 0;
int nLen = szSrc.length;
for (int i = 0; i < nLen; i++) {
byte cChar = (byte) szSrc[i];
nRet = nRet * 16;
nRet += HexToDecimal(cChar);
}
return nRet;
}
public static int HexToDecimal(byte cChar) {
if (cChar == 'A' || cChar == 'a')
return 10;
if (cChar == 'B' || cChar == 'b')
return 11;
if (cChar == 'C' || cChar == 'c')
return 12;
if (cChar == 'D' || cChar == 'd')
return 13;
if (cChar == 'E' || cChar == 'e')
return 14;
if (cChar == 'F' || cChar == 'f')
return 15;
return (cChar - 48);
}
您有具体问题吗? – Reimeus 2013-04-10 17:59:49
我试过这个... http://479lgs.blog.me/150165814698 但是我没有成功。 – user2258581 2013-04-10 18:19:40
它怎么没成功?什么地方出了错? – 2013-04-10 18:22:25