In: Computer Science
. Write a program which encodes any string using the XOR instruction. Test it using your <first name last name> in the data segment to produce cipher text and then decode using the program to get plain text. Use the last two digits of your student id as the key. Print plane text from the data segment, print the cipher text, and then print the plain text upon execution. Submit the asm/list file and screenshots that shows the output of your code.
What are the strengths and weaknesses of this encryption method (25% of points, Typewritten answer required)?
The program for the above problem with the output window screenshot with two different string is given below-
encryptDecrypt(char*):
push rbp
mov rbp, rsp
sub rsp, 32
mov QWORD PTR [rbp-24], rdi
mov BYTE PTR [rbp-5], 82
mov rax, QWORD PTR [rbp-24]
mov rdi, rax
call strlen
mov DWORD PTR [rbp-12], eax
mov DWORD PTR [rbp-4], 0
.L3:
mov eax, DWORD PTR [rbp-4]
cmp eax, DWORD PTR [rbp-12]
jge .L4
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, QWORD PTR [rbp-24]
add rax, rdx
movzx eax, BYTE PTR [rax]
mov edx, DWORD PTR [rbp-4]
movsx rcx, edx
mov rdx, QWORD PTR [rbp-24]
add rdx, rcx
xor al, BYTE PTR [rbp-5]
mov BYTE PTR [rdx], al
mov eax, DWORD PTR [rbp-4]
movsx rdx, eax
mov rax, QWORD PTR [rbp-24]
add rax, rdx
movzx eax, BYTE PTR [rax]
movsx eax, al
mov edi, eax
call putchar
add DWORD PTR [rbp-4], 1
jmp .L3
.L4:
nop
leave
ret
.LC0:
.string "Encrypted String: "
.LC1:
.string "Decrypted String: "
main:
push rbp
mov rbp, rsp
sub rsp, 32
movabs rax, 2334393380863435085
movabs rdx, 7306916077306274156
mov QWORD PTR [rbp-32], rax
mov QWORD PTR [rbp-24], rdx
mov BYTE PTR [rbp-16], 0
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-32]
mov rdi, rax
call encryptDecrypt(char*)
mov edi, 10
call putchar
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call printf
lea rax, [rbp-32]
mov rdi, rax
call encryptDecrypt(char*)
mov eax, 0
leave
ret
__static_initialization_and_destruction_0(int, int):
push rbp
mov rbp, rsp
sub rsp, 16
mov DWORD PTR [rbp-4], edi
mov DWORD PTR [rbp-8], esi
cmp DWORD PTR [rbp-4], 1
jne .L9
cmp DWORD PTR [rbp-8], 65535
jne .L9
mov edi, OFFSET FLAT:_ZStL8__ioinit
call std::ios_base::Init::Init() [complete object constructor]
mov edx, OFFSET FLAT:__dso_handle
mov esi, OFFSET FLAT:_ZStL8__ioinit
mov edi, OFFSET FLAT:_ZNSt8ios_base4InitD1Ev
call __cxa_atexit
.L9:
nop
leave
ret
_GLOBAL__sub_I_encryptDecrypt(char*):
push rbp
mov rbp, rsp
mov esi, 65535
mov edi, 1
call __static_initialization_and_destruction_0(int, int)
pop rbp
ret
The strength is that it can encrypt the string which is impossible for brute force method and it is done with XOR instruction. The weakness is that by using the same key repeatedly the XOR cipher can be broken.