Modify example 8-42 to encrypt the message using an algorithm of your own design
ID: 665855 • Letter: M
Question
Modify example 8-42 to encrypt the message using an algorithm of your own design.
Char EncryptionKey=0x45
Char Encrypt (char code)
{
_asm
{
Mov AL,CODE
XOR AL,EncryptionKey
MOV CODE,AL
INC AL
AND AL,7fh
MOV EncryptionKey,AL
}
RETURN CODE;
}
Private: System: :Void button1_Click(System: :Object^ sender,
System: :EventArgs^ e)
{
richTextBox1->Text = ;
for(int a=0; a<textBox1->Text->Length; a++)
{
richTextBox1->Text += Convert: :ToChar(Encrypt(textBox1->Text[a]));
}
}
Explanation / Answer
Encryption is changed by performing XNOR operation instead of XOR and NAND instead of AND. This will lead to a new encrypted value.
Char EncryptionKey=0x45
Char Encrypt (char code)
{
_asm
{
Mov AL,CODE
XNOR AL,EncryptionKey
MOV CODE,AL
INC AL
NAND AL,7fh
MOV EncryptionKey,AL
}
RETURN CODE;
}
Private: System: :Void button1_Click(System: :Object^ sender,
System: :EventArgs^ e)
{
richTextBox1->Text = ;
for(int a=0; a<textBox1->Text->Length; a++)
{
richTextBox1->Text += Convert: :ToChar(Encrypt(textBox1->Text[a]));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.