// File: ethanmick[P]Blowfish482/Tester.cpp
// Function: main
int main( int argc, char* argv[] ){
    Blowfish b;

    if( (unsigned int) argc != b.blockSize() + b.keySize() + 1 ){
        cout << "usage: Blowfish key[ 0th byte ] key[ 1st byte ] " \
                "etc... ptext[ 0th byte ] ptext[ 1st byte ] etc..." << endl;
        exit( 0 );
    }
    
    for( int i = 1; i < argc; i++ ){
        if( strlen( argv[ i ] ) != 2 ){
            cout << "This arg isn't 2 characters long." << endl;
            exit( 0 );
        }
    }
        
    uint8_t* key = new uint8_t[ b.keySize() ];
    
    for( unsigned int i = 0; i < b.keySize(); i++ ){
        char * p;
        key[ i ] = (uint8_t) strtol( argv[ 1 + i ], &p, 16 );
        if( *p != 0 ){
            cout << "Problem parsing string." << endl;
        }
    }
    
    print_uint8_hex(key, b.keySize(), "Key: ");
    b.setKey( key );
    

    uint8_t* text = new uint8_t[ b.blockSize() ];

    
    
    for( unsigned int i = 0; i < b.blockSize(); i++ ){
        char * p;
        text[ i ] = (uint8_t) strtol( argv[ b.keySize() + 1 + i ], &p, 16 );
        if( *p != 0 ){
            cout << "Problem parsing string." << endl;
        }
    }
    print_uint8_hex(text, b.blockSize(), "Plaintext: ");
    b.encrypt( text );
    print_uint8_hex(text, b.blockSize(), "Ciphertext: ");
    
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10e0, %rsp           # imm = 0x10E0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x1290
movl -0x8(%rbp), %eax
movl %eax, -0x10a4(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12d0
movl %eax, -0x10a8(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12e0
movl -0x10a8(%rbp), %ecx
movl %eax, %edx
movl -0x10a4(%rbp), %eax
addl %edx, %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x1e6c
movq 0x318e(%rip), %rdi      # 0x4fd8
leaq 0x11ef(%rip), %rsi      # 0x3040
callq 0x1070
movq %rax, %rdi
movq 0x3168(%rip), %rsi      # 0x4fc8
callq 0x1080
xorl %edi, %edi
callq 0x1090
movl $0x1, -0x106c(%rbp)
movl -0x106c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x1ed7
movq -0x10(%rbp), %rax
movslq -0x106c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1050
cmpq $0x2, %rax
je 0x1ec4
movq 0x3136(%rip), %rdi      # 0x4fd8
leaq 0x11f9(%rip), %rsi      # 0x30a2
callq 0x1070
movq %rax, %rdi
movq 0x3110(%rip), %rsi      # 0x4fc8
callq 0x1080
xorl %edi, %edi
callq 0x1090
jmp 0x1ec6
movl -0x106c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x106c(%rbp)
jmp 0x1e76
leaq -0x1068(%rbp), %rdi
callq 0x12e0
movl %eax, %eax
movl %eax, %edi
callq 0x1030
movq %rax, -0x1078(%rbp)
movl $0x0, -0x107c(%rbp)
movl -0x107c(%rbp), %eax
movl %eax, -0x10ac(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12e0
movl %eax, %ecx
movl -0x10ac(%rbp), %eax
cmpl %ecx, %eax
jae 0x1f9e
movq -0x10(%rbp), %rax
movl -0x107c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq -0x1088(%rbp), %rsi
movl $0x10, %edx
callq 0x10c0
movb %al, %dl
movq -0x1078(%rbp), %rax
movl -0x107c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x1088(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1f88
movq 0x306b(%rip), %rdi      # 0x4fd8
leaq 0x1150(%rip), %rsi      # 0x30c4
callq 0x1070
movq %rax, %rdi
movq 0x3045(%rip), %rsi      # 0x4fc8
callq 0x1080
jmp 0x1f8a
movl -0x107c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x107c(%rbp)
jmp 0x1efd
movq -0x1078(%rbp), %rax
movq %rax, -0x10b8(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12e0
movq -0x10b8(%rbp), %rdi
movl %eax, %esi
leaq 0x1114(%rip), %rdx      # 0x30dc
callq 0x1d40
movq -0x1078(%rbp), %rsi
leaq -0x1068(%rbp), %rdi
callq 0x12f0
leaq -0x1068(%rbp), %rdi
callq 0x12d0
movl %eax, %eax
movl %eax, %edi
callq 0x1030
movq %rax, -0x1090(%rbp)
movl $0x0, -0x1094(%rbp)
movl -0x1094(%rbp), %eax
movl %eax, -0x10bc(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12d0
movl %eax, %ecx
movl -0x10bc(%rbp), %eax
cmpl %ecx, %eax
jae 0x20c7
movq -0x10(%rbp), %rax
movq %rax, -0x10c8(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12e0
movl %eax, %ecx
movq -0x10c8(%rbp), %rax
addl $0x1, %ecx
addl -0x1094(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdi
leaq -0x10a0(%rbp), %rsi
movl $0x10, %edx
callq 0x10c0
movb %al, %dl
movq -0x1090(%rbp), %rax
movl -0x1094(%rbp), %ecx
movb %dl, (%rax,%rcx)
movq -0x10a0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x20b1
movq 0x2f42(%rip), %rdi      # 0x4fd8
leaq 0x1027(%rip), %rsi      # 0x30c4
callq 0x1070
movq %rax, %rdi
movq 0x2f1c(%rip), %rsi      # 0x4fc8
callq 0x1080
jmp 0x20b3
movl -0x1094(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1094(%rbp)
jmp 0x2006
movq -0x1090(%rbp), %rax
movq %rax, -0x10d8(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12d0
movq -0x10d8(%rbp), %rdi
movl %eax, %esi
leaq 0xff1(%rip), %rdx       # 0x30e2
callq 0x1d40
movq -0x1090(%rbp), %rsi
leaq -0x1068(%rbp), %rdi
callq 0x18c0
movq -0x1090(%rbp), %rax
movq %rax, -0x10d0(%rbp)
leaq -0x1068(%rbp), %rdi
callq 0x12d0
movq -0x10d0(%rbp), %rdi
movl %eax, %esi
leaq 0xfbb(%rip), %rdx       # 0x30ee
callq 0x1d40
movl -0x4(%rbp), %eax
addq $0x10e0, %rsp           # imm = 0x10E0
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop