delphi解密转换Java代码
如何将用Delphi编写的特定代码转换为JAVA Delphi代码是解密代码delphi解密转换Java代码,java,delphi,encryption,Java,Delphi,Encryption,如何将用Delphi编写的特定代码转换为JAVA Delphi代码是解密代码 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(FirstRe
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;
由“David Heffernan”和“stackoverflow.com”提供解决了加密问题
问题1:
非常感谢!
所以我一直尝试将Delphi中的解密代码转换为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));
}
}
}
类SO15885898{
私有静态字符串ValueToHex(int myInt)
{
StringBuilder sb=新的StringBuilder();
sb.append(Integer.toHexString(myInt&0xff));
如果(sb.length()<2){
sb.插入(0,'0');//如果需要,用前导零填充
}
使某人返回字符串();
}
公共静态void main(字符串[]args)
{
int键1=11;
int key2=22;
int key3=33;
字符串值=“ABCDE”;
对于(int i=0;i>8);
key1=((右值+key1)*key2+key3)&0xffff;
系统输出打印(ValueToHex(右值));
}
}
}
请用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);
}
publicstaticvoidmain(字符串[]args)
{
int-key1=111;
int key2=222;
int key3=333;
我试过这个。。。
字符串resultH=“”;
字符串resultEncrypt=“”;
字符串resultDecrypt=“”;
字符串值=“ABCDEF”;
对于(int i=0;i>8);
key1=((右值+key1)*key2+key3)&0xffff;
resultEncrypt+=ValueToHex(右值);
resultH+=HexToValue(ValueToHex(rValue.getBytes());
}
键1=111;
对于(int i=0;i>8);
key1=((右值+key1)*key2+key3)&0xffff;
结果Decrypt+=右值;
}
//41db791e06a9
System.out.println(“resultEncrypt:+resultEncrypt”);
//91242156862519211605712161341202650962331971751025.......................
System.out.println(“resultDecrypt:+resultDecrypt”);
}
公共静态字节[]HexToValue(字节[]szSrc){
int nLen=szSrc.length;
字节[]szDest=新字节[nLen/2];
char szChar[]=新字符[2];
对于(int I=0;I
以下是您的Delphi代码的翻译:
class SO15933038
{
private static int[] hexStringToIntArray(String s)
{
int len = s.length();
int[] data = new int[len / 2];
for (int i=0; i<len; i+=2) {
data[i / 2] = ((Character.digit(s.charAt(i), 16) << 4)
+ Character.digit(s.charAt(i+1), 16));
}
return data;
}
private static String intArrayToHexString(int[] a)
{
StringBuilder sb = new StringBuilder(a.length);
for (int i=0; i<a.length; i++)
{
sb.append((char) a[i]);
}
return sb.toString();
}
public static String Decrypt(String encrypted, int key1, int key2, int key3)
{
int[] input = hexStringToIntArray(encrypted);
int[] output = new int[input.length];
for (int i=0; i<output.length; i++)
{
output[i] = input[i]^(key1>>8) & 0xff;
key1 = ((input[i]+key1)*key2+key3) & 0xffff;
}
return intArrayToHexString(output);
}
public static void main(String[] args)
{
System.out.println(Decrypt("41db791e06a9", 111, 222, 333));
}
}
等级SO15933038
{
私有静态int[]HextStringToIntArray(字符串s)
{
int len=s.length();
int[]数据=新的int[len/2];
对于(int i=0;我有一个具体的问题吗?我试过了……但没有成功。它怎么没有成功?出了什么问题?我希望'resultDecrypt'的值是'ABCDEF',如果你给我们完整的程序,这会容易得多。我无法按原样编译你的Java。我在哪里找到HexToValue
?我希望你能花更多的时间并给我们完整的可编译程序。这对你们来说很简单。谢谢你们。我欠你们的回答,我会更多地学习java语言。