Итак, у меня есть это назначение, где я должен создать функцию расшифровки, используя функцию «encrpypt_chars» в качестве основы. Насколько я понимаю, код берет длину строки, а ключ шифрования затем использует этот ключ шифрования для манипулирования каждым значением по отдельности в строке, которая хранится в:
temp_char = OChars[i]; // Get the next char from Original Chars array
Моя цель заключается в том, чтобы подпрограмма дешифрования, но обратная, так что я возвращаю зашифрованную строку к ее исходным значениям.
void encrypt_chars (int length, char EKey)
{
char temp_char; // Character temporary store
for (int i = 0; i < length; i++) // Encrypt characters one at a time
{
temp_char = OChars[i]; // Get the next char from Original Chars array
__asm
{
push eax // stores the "eax" register out onto the stack
push ecx // stores the "ecx" register out onto the stack
push edx // stores the "edx" register out onto the stack
movzx ecx, temp_char // zeroise "ecx" register and move values in "temp_char" varaible to "ecx" register
lea eax, EKey // copies address of values contained within the EKey varaible and moves it into "eax"register
push eax // stores the "eax" register out onto the stack
push ecx // stores the "ecx" register out onto the stack
call encrypt_5 // runs the function called "decryptX"
mov temp_char, dl // move values in "dl" register into "temp_char" variable
add esp, 8 // add 8 to the "esp" register
pop edx // removes the "edx" register from the stack
pop ecx // removes the "ecx" register from the stack
pop eax // removes the "eax" register from the stack
}
EChars[i] = temp_char; // Store encrypted char in the Encrypted Chars array
}
return;
// Inputs: register EAX = 32-bit address of Ekey,
// ECX = the character to be encrypted
// (in the low 8-bit field, CL).
// Output: register EDX = the encrypted value of the source character
// (in the low 8-bit field, DL).
__asm
{
encrypt_5:
push ebp // stores the pointer onto the stack
//
mov ebp, esp // move values in "esp" register into "ebp" register
mov eax, [ebp + 12] // take value from the stack that is 8 bits above
// from the pointer a putting it in the "eax" register
mov ecx, [ebp + 8] // take value from the stack that is 8 bits above
// from the pointer a putting it on ecx
push eax // stores the Ekey address onto the stack
mov al, byte ptr[eax] // move the pointer of the eax register to the al register in bytes
push ecx // move the encrytped charcter value on the stack
and eax, 0x7C // and eax with 0x7c (1111100 in binary)
ror eax, 1 // Rorate eax register value right by 1 byte shift
not eax // not the eax values within the eax register
ror eax, 1 // Rotate eax register value right by 1 byte shift
inc eax // increase the byte value of eax by 1
mov edx, eax // moves the values within eax to edx
pop ecx // removes ecx from the stack
pop eax // removes eax from the stack
mov byte ptr[eax], dl // move dl to the pointer of the eax register in bytes
xor edx, ecx // Exclusive or ecx with edx and stores the value with edx
rol dl, 1 // Rotate dl register value left by 1 byte shift
pop ebp // returning ebp back to the orginal value
ret // end function
}
//--- End of Assembly code
}
//*** end of encrypt_chars function
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//----------------- DECRYPTION ROUTINES -------------------------------------------------------------------------
//
void decrypt_chars (int length, char EKey)
{
char temp_char; // Character temporary store
for (int i = 0; i < length; i++) // Encrypt characters one at a time
{
temp_char = EChars[i]; // Get the next char from Original Chars array
__asm
{
push eax // stores the "eax" register out onto the stack
push ecx // stores the "ecx" register out onto the stack
push edx // stores the "edx" register out onto the stack
movzx ecx, temp_char // zeroise "ecx" register and move values in "temp_char" varaible to "ecx" register
lea eax, EKey // copies address of values contained within the EKey varaible and moves it into "eax"register
push eax // stores the "eax" register out onto the stack
push ecx // stores the "ecx" register out onto the stack
call decrypt_5 // runs the function called "decryptX"
mov temp_char, dl // move values in "dl" register into "temp_char" variable
add esp, 8 // add 8 to the "esp" register
pop edx // removes the "edx" register from the stack
pop ecx // removes the "ecx" register from the stack
pop eax // removes the "eax" register from the stack
}
DChars[i] = temp_char; // Store encrypted char in the Encrypted Chars array
}
return;
// Inputs: register EAX = 32-bit address of Ekey,
// ECX = the character to be encrypted
// (in the low 8-bit field, CL).
// Output: register EDX = the encrypted value of the source character
// (in the low 8-bit field, DL).
__asm
{
decrypt_5:
push ebp // stores the pointer onto the stack
//
mov ebp, esp // move values in "esp" register into "ebp" register
mov eax, [ebp + 12] // take value from the stack that is 8 bits above
// from the pointer a putting it in the "eax" register
mov ecx, [ebp + 8] // take value from the stack that is 8 bits above
// from the pointer a putting it on ecx
push eax // stores the Ekey address onto the stack
mov al, byte ptr[eax] // move the pointer of the eax register to the al register in bytes
push ecx // move the encrytped charcter value on the stack
and eax, 0x7C // and eax with 0x7c (1111100 in binary)
ror eax, 1 // Rorate eax register value right by 1 byte shift
not eax // not the eax values within the eax register
ror eax, 1 // Rotate eax register value right by 1 byte shift
inc eax // increase the byte value of eax by 1
mov edx, eax // moves the values within eax to edx
pop ecx // removes ecx from the stack
pop eax // removes eax from the stack
mov byte ptr[eax], dl // move dl to the pointer of the eax register in bytes
xor edx, ecx // Exclusive or ecx with edx and stores the value with edx
rol dl, 1 // Rotate dl register value left by 1 byte shift
pop ebp // returning ebp back to the orginal value
ret // end function
}
//--- End of Assembly code
}
//*** end of decrypt_chars function
//---------------------------------------------------------------------------------------------------------------
У меня такое ощущение, что ответ должен быть связан с этой частью и каким-то образом "перевернуть" ее, поскольку это единственная часть, в которой изменяется Ekey:
and eax, 0x7C // and eax with 0x7c (1111100 in binary)
ror eax, 1 // Rorate eax register value right by 1 byte shift
not eax // not the eax values within the eax register
ror eax, 1 // Rotate eax register value right by 1 byte shift
inc eax // increase the byte value of eax by 1
Пожалуйста, помогите мне разобраться в этом.