任何人都可以在汇编时告诉我这个加密程序的解密代码 [英] Can anybody temm me the decryption code for this encryption program in assembly

查看:100
本文介绍了任何人都可以在汇编时告诉我这个加密程序的解密代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个加密解密程序,

以下程序编译并正常工作。

但我无法弄清楚要为解密部分写什么。



有人可以告诉我编写相应的decrypt_chars()例程的代码吗?



谢谢





-------------------------- -------------





// C ++和ASM中的加密程序非常简单加密方法 - 只需在角色上加1即可。



#include< conio.h> //对于kbhit

#include< iostream> // for cin>>和cout<<

#include< iomanip> //用于花哨的输出

使用命名空间std;



#define MAXCHARS 6 //随意改变这个,但6是最小的

#define dollarchar'$'//字符串终止符



char OChars [MAXCHARS],EChars [MAXCHARS],DChars [MAXCHARS] = 不久!; //全局原始,加密,解密的字符串



// ---------------------- ------- C ++函数----------------------------------------- -----------------





void get_char(char& a_character)

{

cin>> a_character;

while(((a_character<'0')|(a_character>'z'))&&(a_character!= dollarchar))

{

cout<< 仅限字母数字字符,请再试一次>;

cin>> a_character;

}

}

// -------------------- -------------------------------------------------- ---------------------------------------



void get_original_chars(int& length)

{

char next_char;

length = 0;

get_char(next_char);



while((长度< MAXCHARS)&&(next_char!= dollarchar))

{

OChars [length ++] = next_char;

get_char(next_char);

}

}



// ----------------------------------- -------------------------------------------------- --------------------------

// -------------- --- ENCRYPTION ROUTINES --------------------------------------------- ----------------------------



void encrypt_chars(int length, char EKey)

{

char temp_char; // char临时商店



for(int i = 0; i< length; i ++)//一次加密一个字符

{

temp_char = OChars [i]; //

__asm {//

push eax //保存堆栈上的寄存器值是安全的

push ecx //

movzx ecx,temp_char //

lea eax,EKey //

呼叫加密//加密角色

mov temp_char, al //

pop ecx //从堆栈恢复原始寄存器值

pop eax //

}

EChars [i] = temp_char; //将加密的字符存储在加密的字符数组中

}

返回;



// ---汇编代码开始

__asm {





//输入:寄存器EAX = 32位地址Ekey,

// ECX =要加密的字符(在低8位字段中,CL)。

//输出:寄存器EAX =加密值源字符(在低8位字段,AL)。





encrypt5:push eax

mov al,byte ptr [eax]

push ecx

和eax,0x7C

ror eax,1

ror eax,1

inc eax

mov edx,eax

pop ecx

pop eax
mov byte ptr [eax],dl

xor edx,ecx

mov eax,edx

rol al,1 < br $>
ret







加密:

mov eax,ecx //获取角色

inc eax //简单地添加1 t o性格!这个简单版本没有使用EKey值。

ret

}



// ---结束汇编代码

}

// encrypt_chars函数结束

// --------------- -------------------------------------------------- ----------------------------------------------



// ------------------------------------ -------------------------------------------------- -------------------------

// --------------- - DECRYPTION ROUTINES ---------------------------------------------- ---------------------------

//

void decrypt_chars(int length ,char EKey)

{/ ***待写*** /





返回;



}





// decrypt_chars函数结束

// ------------------------------------------- -------------------------------------------------- ------------------





int main(void)

{

int char_count; //输入的实际字符数(最大MAXCHARS限制)。

char EKey; //加密密钥。



cout<< \ n请输入您的加密密钥(EKey)信:; get_char(EKey);



cout<< \\\
Now enter upto<< MAXCHARS<< 字母数字字符:\ n;

get_original_chars(char_count);

cout<< \ n \ nOriginal source string =<< OChars<< \tHex =;

for(int i = 0; i< char_count;>

encrypt_chars(char_count,EKey);

cout<<\ n\\\
Encrypted string =<<<<<<<<<" \ tHex =;

for(int i = 0; i< char_count ;>

decrypt_chars(char_count,EKey);

cout<<\ n\\\
Decrypted string =<<< DChars<< \tHex =;

for(int i = 0; i< char_count;>

cout<<\ n \ n按一个键结束......;

while(!_kbhit()); //按住屏幕直到按下一个键

return(0);





} //整个加密/解密程序结束-------------------- ------------------------------------------------

解决方案

'// string终结者



char OChars [MAXCHARS],EChars [MAXCHARS],DChars [MAXCHARS ] =很快!; //全球原创,加密,解密字符串



// ----------------------------- C ++功能 - - - - - - - - - - - - - - - - - - - - - - - - - ---------





void get_char(char& a_character)

{

cin>> a_character;

while(((a_character<'0')|(a_character>'z'))&&(a_character!= dollarchar))

{

cout<< 仅限字母数字字符,请再试一次>;

cin>> a_character;

}

}

// -------------------- -------------------------------------------------- ---------------------------------------



void get_original_chars(int& length)

{

char next_char;

length = 0;

get_char(next_char);



while((长度< MAXCHARS)&&(next_char!= dollarchar))

{

OChars [length ++] = next_char;

get_char(next_char);

}

}



// ----------------------------------- -------------------------------------------------- --------------------------

// -------------- --- ENCRYPTION ROUTINES --------------------------------------------- ----------------------------



void encrypt_chars(int length, char EKey)

{

char temp_char; // char临时商店



for(int i = 0; i< length; i ++)//一次加密一个字符

{

temp_char = OChars [i]; //

__asm {//

push eax //保存堆栈上的寄存器值是安全的

push ecx //

movzx ecx,temp_char //

lea eax,EKey //

呼叫加密//加密角色

mov temp_char, al //

pop ecx //从堆栈恢复原始寄存器值

pop eax //

}

EChars [i] = temp_char; //将加密的字符存储在加密的字符数组中

}

返回;



// ---汇编代码开始

__asm {





//输入:寄存器EAX = 32位地址Ekey,

// ECX =要加密的字符(在低8位字段中,CL)。

//输出:寄存器EAX =加密值源字符(在低8位字段,AL)。





encrypt5:push eax

mov al,byte ptr [eax]

push ecx

和eax,0x7C

ror eax,1

ror eax,1

inc eax

mov edx,eax

pop ecx

pop eax
mov byte ptr [eax],dl

xor edx,ecx

mov eax,edx

rol al,1 < br $>
ret







加密:

mov eax,ecx //获取角色

inc eax //简单地添加1 t o性格!这个简单版本没有使用EKey值。

ret

}



// ---结束汇编代码

}

// encrypt_chars函数结束

// --------------- -------------------------------------------------- ----------------------------------------------



// ------------------------------------ -------------------------------------------------- -------------------------

// --------------- - DECRYPTION ROUTINES ---------------------------------------------- ---------------------------

//

void decrypt_chars(int length ,char EKey)

{/ ***待写*** /





返回;



}





// decrypt_chars函数结束

// ------------------------------------------- -------------------------------------------------- ------------------





int main(void)

{

int char_count; //输入的实际字符数(最大MAXCHARS限制)。

char EKey; //加密密钥。



cout<< \ n请输入您的加密密钥(EKey)信:; get_char(EKey);



cout<< \\\
Now enter upto<< MAXCHARS<< 字母数字字符:\ n;

get_original_chars(char_count);

cout<< \ n \ nOriginal source string =<< OChars<< \tHex =;

for(int i = 0; i< char_count;>

encrypt_chars(char_count,EKey);

cout<<\ n\\\
Encrypted string =<<<<<<<<<" \ tHex =;

for(int i = 0; i< char_count ;>

decrypt_chars(char_count,EKey);

cout<<\ n\\\
Decrypted string =<<< DChars<< \tHex =;

for(int i = 0; i< char_count;>

cout<<\ n \ n按一个键结束......;

while(!_kbhit()); //按住屏幕直到按下一个键

return(0);





} //整个加密/解密程序结束-------------------- ------------------------------------------------


我在你重新发布这个问题时回答了这个问题。


Hi , I have got this encryption decryption program ,
the following program compiles and works alright .
However I cannot figure out what to write for the decryption section.

Can anybody please tell me the code for writing the corresponding decrypt_chars() routine?

Thank you


---------------------------------------


// The encryption program in C++ and ASM with a very simple encryption method - it simply adds 1 to the character.

#include <conio.h> // for kbhit
#include <iostream> // for cin >> and cout <<
#include <iomanip> // for fancy output
using namespace std;

#define MAXCHARS 6 // feel free to alter this, but 6 is the minimum
#define dollarchar '$' // string terminator

char OChars[MAXCHARS], EChars[MAXCHARS], DChars[MAXCHARS] = "Soon!"; // Global Original, Encrypted, Decrypted character strings

//----------------------------- C++ Functions ----------------------------------------------------------


void get_char(char& a_character)
{
cin >> a_character;
while (((a_character < '0') | (a_character > 'z')) && (a_character != dollarchar))
{
cout << "Alphanumeric characters only, please try again > ";
cin >> a_character;
}
}
//-------------------------------------------------------------------------------------------------------------

void get_original_chars(int& length)
{
char next_char;
length = 0;
get_char(next_char);

while ((length < MAXCHARS) && (next_char != dollarchar))
{
OChars[length++] = next_char;
get_char(next_char);
}
}

//---------------------------------------------------------------------------------------------------------------
//----------------- ENCRYPTION ROUTINES -------------------------------------------------------------------------

void encrypt_chars(int length, char EKey)
{
char temp_char; // char temporary store

for (int i = 0; i < length; i++) // encrypt characters one at a time
{
temp_char = OChars[i]; //
__asm { //
push eax // save register values on stack to be safe
push ecx //
movzx ecx, temp_char //
lea eax, EKey //
call encrypt // encrypt the character
mov temp_char, al //
pop ecx // restore original register values from stack
pop eax //
}
EChars[i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;

// --- Start of Assembly code
__asm {


// Inputs: register EAX = 32-bit address of Ekey,
// ECX = the character to be encrypted (in the low 8-bit field, CL).
// Output: register EAX = the encrypted value of the source character (in the low 8-bit field, AL).


encrypt5: push eax
mov al, byte ptr[eax]
push ecx
and eax, 0x7C
ror eax, 1
ror eax, 1
inc eax
mov edx, eax
pop ecx
pop eax
mov byte ptr[eax], dl
xor edx, ecx
mov eax, edx
rol al, 1
ret



encrypt :
mov eax, ecx // get character
inc eax // simply add 1 to character! EKey value not used in this simple version.
ret
}

//--- End of Assembly code
}
// end of encrypt_chars function
//---------------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------------
//----------------- DECRYPTION ROUTINES -------------------------------------------------------------------------
//
void decrypt_chars(int length, char EKey)
{ /*** to be written ***/


return;

}


// end of decrypt_chars function
//---------------------------------------------------------------------------------------------------------------


int main(void)
{
int char_count; // The number of actual characters entered (upto MAXCHARS limit).
char EKey; // Encryption key.

cout << "\nPlease enter your Encryption Key (EKey) letter: "; get_char(EKey);

cout << "\nNow enter upto " << MAXCHARS << " alphanumeric characters:\n";
get_original_chars(char_count);
cout << "\n\nOriginal source string = " << OChars << "\tHex = ";
for (int i = 0; i<char_count;>
encrypt_chars(char_count, EKey);
cout << "\n\nEncrypted string = " << EChars << "\tHex = ";
for (int i = 0; i<char_count;>
decrypt_chars(char_count, EKey);
cout << "\n\nDecrypted string = " << DChars << "\tHex = ";
for (int i = 0; i<char_count;>
cout << "\n\nPress a key to end...";
while (!_kbhit()); //hold the screen until a key is pressed
return (0);


} // end of whole encryption/decryption program --------------------------------------------------------------------

解决方案

' // string terminator

char OChars[MAXCHARS], EChars[MAXCHARS], DChars[MAXCHARS] = "Soon!"; // Global Original, Encrypted, Decrypted character strings

//----------------------------- C++ Functions ----------------------------------------------------------


void get_char(char& a_character)
{
cin >> a_character;
while (((a_character < '0') | (a_character > 'z')) && (a_character != dollarchar))
{
cout << "Alphanumeric characters only, please try again > ";
cin >> a_character;
}
}
//-------------------------------------------------------------------------------------------------------------

void get_original_chars(int& length)
{
char next_char;
length = 0;
get_char(next_char);

while ((length < MAXCHARS) && (next_char != dollarchar))
{
OChars[length++] = next_char;
get_char(next_char);
}
}

//---------------------------------------------------------------------------------------------------------------
//----------------- ENCRYPTION ROUTINES -------------------------------------------------------------------------

void encrypt_chars(int length, char EKey)
{
char temp_char; // char temporary store

for (int i = 0; i < length; i++) // encrypt characters one at a time
{
temp_char = OChars[i]; //
__asm { //
push eax // save register values on stack to be safe
push ecx //
movzx ecx, temp_char //
lea eax, EKey //
call encrypt // encrypt the character
mov temp_char, al //
pop ecx // restore original register values from stack
pop eax //
}
EChars[i] = temp_char; // Store encrypted char in the encrypted chars array
}
return;

// --- Start of Assembly code
__asm {


// Inputs: register EAX = 32-bit address of Ekey,
// ECX = the character to be encrypted (in the low 8-bit field, CL).
// Output: register EAX = the encrypted value of the source character (in the low 8-bit field, AL).


encrypt5: push eax
mov al, byte ptr[eax]
push ecx
and eax, 0x7C
ror eax, 1
ror eax, 1
inc eax
mov edx, eax
pop ecx
pop eax
mov byte ptr[eax], dl
xor edx, ecx
mov eax, edx
rol al, 1
ret



encrypt :
mov eax, ecx // get character
inc eax // simply add 1 to character! EKey value not used in this simple version.
ret
}

//--- End of Assembly code
}
// end of encrypt_chars function
//---------------------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------------------
//----------------- DECRYPTION ROUTINES -------------------------------------------------------------------------
//
void decrypt_chars(int length, char EKey)
{ /*** to be written ***/


return;

}


// end of decrypt_chars function
//---------------------------------------------------------------------------------------------------------------


int main(void)
{
int char_count; // The number of actual characters entered (upto MAXCHARS limit).
char EKey; // Encryption key.

cout << "\nPlease enter your Encryption Key (EKey) letter: "; get_char(EKey);

cout << "\nNow enter upto " << MAXCHARS << " alphanumeric characters:\n";
get_original_chars(char_count);
cout << "\n\nOriginal source string = " << OChars << "\tHex = ";
for (int i = 0; i<char_count;>
encrypt_chars(char_count, EKey);
cout << "\n\nEncrypted string = " << EChars << "\tHex = ";
for (int i = 0; i<char_count;>
decrypt_chars(char_count, EKey);
cout << "\n\nDecrypted string = " << DChars << "\tHex = ";
for (int i = 0; i<char_count;>
cout << "\n\nPress a key to end...";
while (!_kbhit()); //hold the screen until a key is pressed
return (0);


} // end of whole encryption/decryption program --------------------------------------------------------------------


I answered this in your repost of this question.


这篇关于任何人都可以在汇编时告诉我这个加密程序的解密代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆