2013-04-10 3 views
0

어떻게 델파이로 작성된 특정 코드를 JAVA로 변환 할 수 있습니까?delphi 암호 해독 Java 코드로 변환

델파이 코드는 암호 해독 코드입니다. 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'

Question1의 호의에 의해 해결되었다! 그래서 지금까지 델파이의 암호 해독 코드를 JAVA로 변환하려고 시도했습니다 !!! 정말로 hum ... 그러나 나는 그것에 관해 해결할 수 없었다! 세상에! 나는 수치 스럽다 ..... 하지만 너를 도와주고 싶다. 다시 ... 내가 코드를 해독해야합니다 ..

자바 암호화 코드는

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)); 
    } 
    } 
} 

자바 코드를 해독하십시오! . .

이것은 내가 뭘하려 :

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); 
} 
+0

특정 질문이 있으십니까? – Reimeus

+0

나는 이것에 대해 시도했다 ... http://479lgs.blog.me/150165814698 그러나 나는 성공하지 못했다. – user2258581

+0

어떻게 성공하지 못했습니까? 무엇이 잘못 되었습니까? –

답변

1

은 여기 델파이 코드의 번역이다 :

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)); 
    } 
} 

이 쓰신 자바의 lamest 조각은 아마이다. 이전 질문에 대한 답변과 함께 두 개의 Java 프로그램을 작성했습니다.

+0

고맙습니다. 나는 당신의 대답을 빚졌고 나는 자바 언어를 더 공부할 것이다. – user2258581