Bonjour,

J'aurais besoin d'aide pour convertir le code suivant vers delphi
Sachant que les fonctions "AcquireToken", "InputFromPort" et "OutputToPort" sont connues et fonctionnent déjà sous Delphi. Elles sont mises en commentaires
Merci d'avance a tous ceux qui pourront m'aider

Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
unsigned ReturnValue1, ReturnValue2;
char A1, A2L, A2H, A3L, A3H, A4L, A4H;
 
char RotateLeft8(char Target, char rotateCount)
{
    return ( ((Target << rotateCount) & 0xff) |
             ((Target & 0xff) >> (8 - rotateCount))
           );
}
 
//**************************** KTASK ************************************
void KTASK(int CommandCode, int Argument2, int Argument3, int Argument4)
{
    unsigned long int ReturnValue=0;
    char RV1Lo, RV1Hi, RV2Lo, RV2Hi, Temp1Lo, Temp1Hi, Temp2Lo, Temp2Hi;
    char R1, R2;            // Random Numbers
    char S1, S2;        // Byte rotation counts
    char Xor1, Xor2;        // XOR Values
 
    Xor1 = (char) 0xd5;
    Xor2 = (char) 0x2d;
    S1 = 0x6;
    S2 = 0x7;
    R1 = (CHAR)rand();
    R2 = (CHAR)rand();
    EncodeArguments( CommandCode, Argument2, Argument3, Argument4, R1, R2);
//    AcquireToken(A1);
//    OutputToPort(hSerial, R1);
//    OutputToPort(hSerial, R2);
//    OutputToPort(hSerial, A2L);
//    OutputToPort(hSerial, A2H);
//    OutputToPort(hSerial, A3L);
//    OutputToPort(hSerial, A3H);
//    OutputToPort(hSerial, A4L);
//    OutputToPort(hSerial, A4H);
 
//    InputFromPort(hSerial, &Temp1Lo);
    RV1Lo = RotateLeft8(Temp1Lo, S2) ^ R1;
//    InputFromPort(hSerial, &Temp1Hi);
    RV1Hi = RotateLeft8(Temp1Hi, S1) ^ R2;
//    InputFromPort(hSerial, &Temp2Lo);
    RV2Lo = RotateLeft8((char)(Temp2Lo ^ Xor2 ^ R1), S1);
//    InputFromPort(hSerial, &Temp2Hi);
    RV2Hi = RotateLeft8((char)(Temp2Hi ^ Xor1 ^ R2), S2);
    ReturnValue1 = (((WORD)(RV1Hi) << 8) | ((WORD)RV1Lo & 0xff)) & 0xffff;
    ReturnValue2 = (((WORD)(RV2Hi) << 8) | ((WORD)RV2Lo & 0xff)) & 0xffff;
}
 
void EncodeArguments(int CommandCode, int Argument2, int Argument3, int Argument4, char R1, char R2)
{
    char Xor1, Xor2;    // XOR Values
    char S1, S2;    // Slide (rotate left) bit positions of Value
 
    Xor1 = (char) 0xd5;
    Xor2 = (char) 0x2d;
    S1 = 0x6;
    S2 = 0x7;
    A1 = LOBYTE(LOWORD(CommandCode)) | ((R2 & 0xe) << 4);  // Top 3 bit random
    A2L = RotateLeft8((char)(Argument2 ^ (ULONG)Xor1), S1);
    A2H = RotateLeft8(HIBYTE(LOWORD(Argument2)),(char)(Xor2 & 0x7)) ^ Xor2 ^ R1;
    A3L = RotateLeft8((char)(Argument3 ^ (ULONG)R2 ^ (ULONG)R1), S2);
    A3H = RotateLeft8( R1, S2) ^ (HIBYTE(LOWORD(Argument3))) ^ Xor1;
    A4L = RotateLeft8( R2, S1) ^ (LOBYTE(LOWORD(Argument4))) ^ Xor2;
    A4H = RotateLeft8((char)(Xor1 ^ Xor2), S1) ^ (HIBYTE(LOWORD(Argument4)));
}