// File: LandonSwartz[P]TheGreatEncryptor/./EncryptionClass.cpp
// Function: encryption_base::encryption_algorithm(void*)
static void * encryption_algorithm(void * params_void) {
        // Encryption algorithm, basic code necessary for other implementations of this function
        algorithm_parameters * params = static_cast<algorithm_parameters *>(params_void);

        // Calculate the cipher offset.
        //cout << "hash key is " << params->hash_key;
        int cipher_offset = params->hash_key % 255;

        // Traverse through each string this thread is responsible for.
        for (int i = params->start_index; i <= params->end_index; i++) {
            //cout << "encrypting string" << endl;
            // The syntax below explained:
                // params is a reference to a struct
                // use -> notation because params is a reference to retrieve data member of struct
                // data member of struct is reference to a vector object of strings, so dereference it
                // use [] notation to access index of given string from dereferenced vector object
                // after the string is indexed, get its address so the string can be modified
            //cout << "cipher_offset is " << cipher_offset << endl;
            string * current_string = &((*(params->data))[i]);
            //cout << "working on string " << *current_string << endl; 
            // At this point, we have a reference to the string that should be encrypted.
            for (int c = 0; c < current_string->length(); c++) {
                // Iterate through every character in the string, apply the cipher.
                //cout << "applying cipher to character" << endl;
                int current_char = ((int)((*current_string)[c]));
                //cout << "character before cipher: " << current_char << endl;
                current_char += cipher_offset;
                //cout << "character after cipher: " << current_char << endl;
                if (current_char > 255)
                    current_char -= 255;
                //cout << "character after correction: " << current_char << endl;
                (*current_string)[c] = (char)current_char;
            }
        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl $0xff, %ecx
cltd
idivl %ecx
movl %edx, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jg 0x422b
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x18(%rbp), %rsi
callq 0x4dc0
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movslq -0x24(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x2260
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jae 0x421b
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x2340
movsbl (%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0xff, -0x28(%rbp)
jle 0x41f8
movl -0x28(%rbp), %eax
subl $0xff, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movb %al, -0x31(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x2340
movb -0x31(%rbp), %cl
movb %cl, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x41ab
jmp 0x421d
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4180
ud2
nopl (%rax)