// File: Tarstingo[P]rarcrack/main.cpp
// Function: main
int main()
{
    int fd=open("rar.rar",O_RDONLY);
    if(fd<=0)
    {
        perror("can not open file");
        return 1;
    }
    getPara(fd,salt,iv,s);
    close(fd);
    printf("salt\033[31m\n");
    prtvector(salt);
    printf("\033[miv\033[31m\n");
    prtvector(iv);
    printf("\033[ms\033[31m\n");
    prtvector(s);
    printf("\033[m");


    printf("Now We start cracking...\n");

    muchar key[20];

    struct timespec startime,nowtime,tmptime;
    clock_gettime(CLOCK_REALTIME,&startime);
    nowtime.tv_nsec=startime.tv_nsec;
    nowtime.tv_sec=startime.tv_sec;
    cout<<"time "<<startime.tv_sec<<":"<<startime.tv_nsec<<endl;
    unsigned int long numkeys=0;
    ifstream fkey;
    fkey.open("keyfile");
    while(1)
    {
        numkeys++;
        if(numkeys%5==0)
        {
            tmptime.tv_nsec=nowtime.tv_nsec;
            tmptime.tv_sec=nowtime.tv_sec;
            clock_gettime(CLOCK_REALTIME,&nowtime);
            if(tmptime.tv_nsec>nowtime.tv_nsec)
            {
                cout<<"test 5 keys,costs "<<nowtime.tv_sec-tmptime.tv_sec-1<<"seconds and "<<1000000000-tmptime.tv_nsec+nowtime.tv_nsec<<"nanoseconds"<<endl;
            }
            else
            {
                cout<<"test 5 keys,costs "<<nowtime.tv_sec-tmptime.tv_sec<<"seconds and "<<nowtime.tv_nsec-tmptime.tv_nsec<<"nanoseconds"<<endl;
            }
        }
        fkey>>key;
        if(fkey.fail())
        {
            cout<<"The key is not in the file"<<endl;
            break;
        }
        else if(testKey(salt,s,iv,key)==1)
        {
            cout<<"Key founded;"<<endl;
            cout<<"We have tested "<<numkeys<<" keys"<<endl;
            cout<<key<<endl;
            break;
        }
    }
    fkey.close();

    clock_gettime(CLOCK_REALTIME,&nowtime);
    if(startime.tv_nsec>nowtime.tv_nsec)
    {
        cout<<"it costs "<<nowtime.tv_sec-startime.tv_sec-1<<"seconds and "<<1000000000-startime.tv_nsec+nowtime.tv_nsec<<"nanoseconds"<<endl;
    }
    else
    {
        cout<<"it costs "<<nowtime.tv_sec-startime.tv_sec<<"seconds and "<<nowtime.tv_nsec-startime.tv_nsec<<"nanoseconds"<<endl;
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x420, %rsp            # imm = 0x420
movl $0x0, -0x4(%rbp)
leaq 0xc20(%rip), %rdi       # 0x6079
xorl %esi, %esi
movb $0x0, %al
callq 0x2100
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jg 0x5483
leaq 0xc0f(%rip), %rdi       # 0x6081
callq 0x2130
movl $0x1, -0x4(%rbp)
jmp 0x5c8b
movl -0x8(%rbp), %edi
leaq 0x3cd3(%rip), %rsi      # 0x9160
movq %rsi, -0x318(%rbp)
leaq 0x3cdd(%rip), %rdx      # 0x9178
leaq 0x3cee(%rip), %rcx      # 0x9190
callq 0x27f0
movl -0x8(%rbp), %edi
callq 0x2260
leaq 0xbdd(%rip), %rdi       # 0x6093
xorl %eax, %eax
callq 0x2040
movq -0x318(%rbp), %rsi
leaq -0x20(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x3160
movq -0x310(%rbp), %rdi
callq 0x30f0
jmp 0x54e2
leaq -0x20(%rbp), %rdi
callq 0x33d0
leaq 0xbac(%rip), %rdi       # 0x609e
xorl %eax, %eax
callq 0x2040
leaq 0x3c78(%rip), %rsi      # 0x9178
leaq -0x48(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x3160
movq -0x320(%rbp), %rdi
callq 0x30f0
jmp 0x551e
leaq -0x48(%rbp), %rdi
callq 0x33d0
leaq 0xb7c(%rip), %rdi       # 0x60aa
xorl %eax, %eax
callq 0x2040
leaq 0x3c54(%rip), %rsi      # 0x9190
leaq -0x60(%rbp), %rdi
movq %rdi, -0x328(%rbp)
callq 0x3160
movq -0x328(%rbp), %rdi
callq 0x30f0
jmp 0x555a
leaq -0x60(%rbp), %rdi
callq 0x33d0
leaq 0xb4b(%rip), %rdi       # 0x60b5
xorl %eax, %eax
movl %eax, -0x334(%rbp)
movb %al, -0x335(%rbp)
callq 0x2040
movb -0x335(%rbp), %al
leaq 0xb2f(%rip), %rdi       # 0x60b9
callq 0x2040
movl -0x334(%rbp), %edi
leaq -0x90(%rbp), %rsi
callq 0x2150
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq 0x3a14(%rip), %rdi      # 0x8fd8
leaq 0xb08(%rip), %rsi       # 0x60d3
callq 0x2160
movq %rax, %rdi
movq -0x90(%rbp), %rsi
callq 0x2250
movq %rax, %rdi
leaq 0xaf0(%rip), %rsi       # 0x60d9
callq 0x2160
movq %rax, %rdi
movq -0x88(%rbp), %rsi
callq 0x2250
movq %rax, %rdi
movq 0x39c1(%rip), %rsi      # 0x8fc8
callq 0x21a0
movq $0x0, -0xb8(%rbp)
leaq -0x2c0(%rbp), %rdi
movq %rdi, -0x330(%rbp)
callq 0x21b0
movq -0x330(%rbp), %rdi
leaq 0xaa3(%rip), %rsi       # 0x60db
movl $0x8, %edx
callq 0x20f0
jmp 0x5644
jmp 0x5646
jmp 0x5648
movq -0xb8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movl $0x5, %ecx
xorl %edx, %edx
divq %rcx
cmpq $0x0, %rdx
jne 0x588f
movq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
xorl %edi, %edi
leaq -0xa0(%rbp), %rsi
callq 0x2150
movq -0xa8(%rbp), %rax
cmpq -0x98(%rbp), %rax
jle 0x57d6
movq 0x391e(%rip), %rdi      # 0x8fd8
leaq 0xa22(%rip), %rsi       # 0x60e3
callq 0x2160
movq %rax, -0x340(%rbp)
jmp 0x56cf
movq -0x340(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq -0xb0(%rbp), %rsi
notq %rsi
addq %rax, %rsi
callq 0x2250
movq %rax, -0x348(%rbp)
jmp 0x56f8
movq -0x348(%rbp), %rdi
leaq 0x9f0(%rip), %rsi       # 0x60f6
callq 0x2160
movq %rax, -0x350(%rbp)
jmp 0x5714
movq -0x350(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rsi
subq %rax, %rsi
addq $0x3b9aca00, %rsi       # imm = 0x3B9ACA00
callq 0x2250
movq %rax, -0x358(%rbp)
jmp 0x5741
movq -0x358(%rbp), %rdi
leaq 0x9b4(%rip), %rsi       # 0x6103
callq 0x2160
movq %rax, -0x360(%rbp)
jmp 0x575d
movq -0x360(%rbp), %rdi
movq 0x385d(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x5772
jmp 0x588d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x33d0
jmp 0x5c97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x33d0
jmp 0x5c97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x33d0
jmp 0x5c97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5c7d
movq 0x37fb(%rip), %rdi      # 0x8fd8
leaq 0x8ff(%rip), %rsi       # 0x60e3
callq 0x2160
movq %rax, -0x368(%rbp)
jmp 0x57f2
movq -0x368(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0xb0(%rbp), %rax
subq %rax, %rsi
callq 0x2250
movq %rax, -0x370(%rbp)
jmp 0x5818
movq -0x370(%rbp), %rdi
leaq 0x8d0(%rip), %rsi       # 0x60f6
callq 0x2160
movq %rax, -0x378(%rbp)
jmp 0x5834
movq -0x378(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0xa8(%rbp), %rax
subq %rax, %rsi
callq 0x2250
movq %rax, -0x380(%rbp)
jmp 0x585a
movq -0x380(%rbp), %rdi
leaq 0x89b(%rip), %rsi       # 0x6103
callq 0x2160
movq %rax, -0x388(%rbp)
jmp 0x5876
movq -0x388(%rbp), %rdi
movq 0x3744(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x588b
jmp 0x588d
jmp 0x588f
leaq -0x2c0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x5ca0
jmp 0x58a1
movq -0x2c0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x2c0(%rbp,%rax), %rdi
callq 0x2030
movb %al, -0x389(%rbp)
jmp 0x58c1
movb -0x389(%rbp), %al
testb $0x1, %al
jne 0x58cd
jmp 0x5903
movq 0x3704(%rip), %rdi      # 0x8fd8
leaq 0x834(%rip), %rsi       # 0x610f
callq 0x2160
movq %rax, -0x398(%rbp)
jmp 0x58e9
movq -0x398(%rbp), %rdi
movq 0x36d1(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x58fe
jmp 0x5abd
leaq 0x3856(%rip), %rsi      # 0x9160
leaq -0x2d8(%rbp), %rdi
callq 0x3160
jmp 0x5918
leaq 0x3871(%rip), %rsi      # 0x9190
leaq -0x2f0(%rbp), %rdi
callq 0x3160
jmp 0x592d
leaq 0x3844(%rip), %rsi      # 0x9178
leaq -0x308(%rbp), %rdi
callq 0x3160
jmp 0x5942
leaq -0x2d8(%rbp), %rdi
leaq -0x2f0(%rbp), %rsi
leaq -0x308(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0x2e20
movl %eax, -0x39c(%rbp)
jmp 0x5968
leaq -0x308(%rbp), %rdi
callq 0x33d0
leaq -0x2f0(%rbp), %rdi
callq 0x33d0
leaq -0x2d8(%rbp), %rdi
callq 0x33d0
movl -0x39c(%rbp), %eax
cmpl $0x1, %eax
jne 0x5ab6
movq 0x3636(%rip), %rdi      # 0x8fd8
leaq 0x781(%rip), %rsi       # 0x612a
callq 0x2160
movq %rax, -0x3a8(%rbp)
jmp 0x59b7
movq -0x3a8(%rbp), %rdi
movq 0x3603(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x59cc
movq 0x3605(%rip), %rdi      # 0x8fd8
leaq 0x75d(%rip), %rsi       # 0x6137
callq 0x2160
movq %rax, -0x3b0(%rbp)
jmp 0x59e8
movq -0x3b0(%rbp), %rdi
movq -0xb8(%rbp), %rsi
callq 0x2060
movq %rax, -0x3b8(%rbp)
jmp 0x5a04
movq -0x3b8(%rbp), %rdi
leaq 0x735(%rip), %rsi       # 0x6147
callq 0x2160
movq %rax, -0x3c0(%rbp)
jmp 0x5a20
movq -0x3c0(%rbp), %rdi
movq 0x359a(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x5a35
movq 0x359c(%rip), %rdi      # 0x8fd8
leaq -0x80(%rbp), %rsi
callq 0x2190
movq %rax, -0x3c8(%rbp)
jmp 0x5a4e
movq -0x3c8(%rbp), %rdi
movq 0x356c(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x5a63
jmp 0x5abd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5aa5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x5a99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x308(%rbp), %rdi
callq 0x33d0
leaq -0x2f0(%rbp), %rdi
callq 0x33d0
leaq -0x2d8(%rbp), %rdi
callq 0x33d0
jmp 0x5c7d
jmp 0x5ab8
jmp 0x5646
leaq -0x2c0(%rbp), %rdi
callq 0x2050
jmp 0x5acb
xorl %edi, %edi
leaq -0xa0(%rbp), %rsi
callq 0x2150
movq -0x88(%rbp), %rax
cmpq -0x98(%rbp), %rax
jle 0x5bb1
movq 0x34e4(%rip), %rdi      # 0x8fd8
leaq 0x652(%rip), %rsi       # 0x614d
callq 0x2160
movq %rax, -0x3d0(%rbp)
jmp 0x5b09
movq -0x3d0(%rbp), %rdi
movq -0xa0(%rbp), %rax
movq -0x90(%rbp), %rsi
notq %rsi
addq %rax, %rsi
callq 0x2250
movq %rax, -0x3d8(%rbp)
jmp 0x5b32
movq -0x3d8(%rbp), %rdi
leaq 0x5b6(%rip), %rsi       # 0x60f6
callq 0x2160
movq %rax, -0x3e0(%rbp)
jmp 0x5b4e
movq -0x3e0(%rbp), %rdi
movq -0x88(%rbp), %rax
movq -0x98(%rbp), %rsi
subq %rax, %rsi
addq $0x3b9aca00, %rsi       # imm = 0x3B9ACA00
callq 0x2250
movq %rax, -0x3e8(%rbp)
jmp 0x5b7b
movq -0x3e8(%rbp), %rdi
leaq 0x57a(%rip), %rsi       # 0x6103
callq 0x2160
movq %rax, -0x3f0(%rbp)
jmp 0x5b97
movq -0x3f0(%rbp), %rdi
movq 0x3423(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x5bac
jmp 0x5c68
movq 0x3420(%rip), %rdi      # 0x8fd8
leaq 0x58e(%rip), %rsi       # 0x614d
callq 0x2160
movq %rax, -0x3f8(%rbp)
jmp 0x5bcd
movq -0x3f8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x90(%rbp), %rax
subq %rax, %rsi
callq 0x2250
movq %rax, -0x400(%rbp)
jmp 0x5bf3
movq -0x400(%rbp), %rdi
leaq 0x4f5(%rip), %rsi       # 0x60f6
callq 0x2160
movq %rax, -0x408(%rbp)
jmp 0x5c0f
movq -0x408(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x88(%rbp), %rax
subq %rax, %rsi
callq 0x2250
movq %rax, -0x410(%rbp)
jmp 0x5c35
movq -0x410(%rbp), %rdi
leaq 0x4c0(%rip), %rsi       # 0x6103
callq 0x2160
movq %rax, -0x418(%rbp)
jmp 0x5c51
movq -0x418(%rbp), %rdi
movq 0x3369(%rip), %rsi      # 0x8fc8
callq 0x21a0
jmp 0x5c66
jmp 0x5c68
movl $0x0, -0x4(%rbp)
leaq -0x2c0(%rbp), %rdi
callq 0x2070
jmp 0x5c8b
leaq -0x2c0(%rbp), %rdi
callq 0x2070
jmp 0x5c97
movl -0x4(%rbp), %eax
addq $0x420, %rsp            # imm = 0x420
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x2240