assembly language using visual studio 2010
This program demonstrates simple Symmetric-key Encryption using the XOR instruction with a multi-byte key entered by the user. Use this key to encrypt and decrypt the plain text as shown below (try ch06_08.exe):
C:zdsitefullcollfc241files>ch06_11_x000D_ Enter the plain text: This is a string._x000D_ Enter the encryption key: 12345_x000D_ Cipher text: eZZG§XA‼U§BFA][V∟_x000D_ Decrypted: This is a string._x000D_ _x000D_ C:zdsitefullcollfc241files>ch06_11_x000D_ Enter the plain text: This is a string._x000D_ Enter the encryption key: 1_x000D_ Cipher text: eYXB◄XB◄P◄BECX_V▼_x000D_ Decrypted: This is a string._x000D_ |
You can use the sample Encrypt.asm as a start point. With a multi-byte key, you have to modify the procedure TranslateBuffer. Also, modify InputTheString without directly reference to the buffer variable, to make it reusable and you can call it twice to receive the plain text and the multi-byte key like this:
.data_x000D_ prompt1 BYTE "Enter the plain text: ",0_x000D_ prompt2 BYTE "Enter the encryption key: ",0_x000D_ sEncrypt BYTE "Cipher text: ",0_x000D_ sDecrypt BYTE "Decrypted: ",0_x000D_ _x000D_ keyStr BYTE BUFMAX+1 DUP(0)_x000D_ keySize DWORD ?_x000D_ buffer BYTE BUFMAX+1 DUP(0)_x000D_ bufSize DWORD ?_x000D_ _x000D_ .code_x000D_ main11 PROC_x000D_ mov edx,OFFSET prompt1 ; display buffer prompt_x000D_ mov ebx,OFFSET buffer ; point to the buffer_x000D_ call InputTheString_x000D_ mov bufSize,eax ; save the buffer length_x000D_ _x000D_ mov edx,OFFSET prompt2 ; display key prompt_x000D_ mov ebx,OFFSET keyStr ; point to the key_x000D_ call InputTheString_x000D_ mov keySize,eax ; save the key length_x000D_ _x000D_ ... ..._x000D_ |
A better alternative to using keySize is to keep checking the zero terminator in TranslateBuffer, since ReadString automatically adds a terminator to the end of keyStr.
As for TranslateBuffer PROC, the new logic could be similar to this:
Advanced discussion: A possible issue is display of the Cipher text that might result in some control chars, like zero, ODh, OAh, etc. One choice is to show an encoded char’s ASCII code if it below or equal to a space (20h):
Enter plain text: LvAKabc_x000D_ Enter your key: AAAAA22222_x000D_ Cipher text: [0D]7[00][0A][20]PQ_x000D_ Decrypted text: LvAKabc_x000D_ Press any key to continue..._x000D_
|
WhatsApp us