mikhailmasl (mikhailmasl) wrote,
mikhailmasl
mikhailmasl

Криптография и Свобода - 2

Исходник (Borland C++ 2007):

//---------------------------------------------------------------------------

bool __fastcall TForm1::CrackEncryptedPart(DATA_BLOB *bEncryptedPart)

{

unsigned char i,n;

RC2_INT *p0,*p1;

RC2_INT x0,x1,x2,x3,t;

RC2_INT x0_0,x1_0,x2_0,x3_0;

register WORD wx0,wx1,wx2,wx3,wt;

WORD wx0_0,wx1_0,wx2_0,wx3_0,wst0,wst1,wst2,wst3;

unsigned long l;

register unsigned char i1;

HCRYPTPROV hProv = NULL;

HCRYPTKEY hSessKey=NULL;

HCRYPTHASH hHash=NULL;

TRegistry * Reg;

bool ret = false;

unsigned char SessKey[5];

char res[8];

unsigned long d_res2[2];

unsigned long d1[2];

unsigned long d2[2];

unsigned long iv1,iv2;

unsigned long *sk;

unsigned long sk1;

DATA_BLOB bBlob;

char buff[256];

int j;

RC2_KEY key;

WORD key1[64];

DWORD dwFlags = (40<<16) | CRYPT_RECIPIENT;

DWORD st1,st2;

register d_1,d_2;

TDateTime *t1,*t2,*t3,*t4,*t5;

bool bTestTime = false;

Label1->Visible = false;

strcpy(buff,Edit2->Text.c_str());

Panel3->Caption = "";

for(i=0;i<5;i++){

sscanf(buff+i*3,"%02X ",&j);

SessKey[i] = (unsigned char)j;

}

bBlob.cbData = bEncryptedPart->cbData;

bBlob.pbData = bEncryptedPart->pbData;

res[0] = 0x06;

res[1] = 0x0B;

res[2] = 0x2A;

res[3] = 0x86;

res[4] = 0x48;

res[5] = 0x86;

res[6] = 0xF7;

res[7] = 0x0D;

memcpy(&d_res2[0],res,4);

memcpy(&d_res2[1],res+4,4);

memcpy(&d1[0],bBlob.pbData,4);

memcpy(&d1[1],bBlob.pbData+4,4);

iv1 = d1[0]^d_res2[0];

iv2 = d1[1]^d_res2[1];

memcpy(&d2[0],bBlob.pbData+8,4);

memcpy(&d2[1],bBlob.pbData+12,4);

(unsigned char *)sk = SessKey;

memcpy(&st1,bBlob.pbData+8,4);

memcpy(&st2,bBlob.pbData+12,4);

memcpy(&wst0,bBlob.pbData+8,2);

memcpy(&wst1,bBlob.pbData+10,2);

memcpy(&wst2,bBlob.pbData+12,2);

memcpy(&wst3,bBlob.pbData+14,2);

x0_0=0;

x1_0=0;

x2_0=0;

x3_0=0;

memcpy(&x0_0,&iv1,2);

memcpy(&x1_0,((char *)(&iv1))+2,2);

memcpy(&x2_0,&iv2,2);

memcpy(&x3_0,((char *)(&iv2))+2,2);

memcpy(&wx0_0,&iv1,2);

memcpy(&wx1_0,((char *)(&iv1))+2,2);

memcpy(&wx2_0,&iv2,2);

memcpy(&wx3_0,((char *)(&iv2))+2,2);

x0=0;

x1=0;

x2=0;

x3=0;

wx0=0;

wx1=0;

wx2=0;

wx3=0;

goto tryagain1;

tryagain:

(*sk)++;

if(!(*sk)){

UpdateInfo(SessKey,true);

SessKey[4]++;

}

tryagain1:

if(((WORD)(*sk))==0){

if((unsigned char)SessKey[2] == 0){

if(Panel3->Caption == "" && !bTestTime){

t1 = new TTime();

*t1=t1->CurrentTime();

}

if(Panel3->Caption == "" && bTestTime){

t5 = new TDateTime();

t2 = new TTime();

*t2=t2->CurrentTime();

t3 = new TDateTime(t2->Val - t1->Val);

Panel3->Caption = (AnsiString)"Crack item time: " + IntToStr(SecondsBetween(*t3,*t5)) + " sec.";

t4 = new TDateTime(t3->Val*256*256);

Panel4->Caption = (AnsiString)"Total crack time : " + IntToStr(DaysBetween(*t4,*t5)) + " days (" + IntToStr(HoursBetween(*t4,*t5)) + " hours)";

delete t1;

delete t2;

delete t3;

delete t4;

delete t5;

Update();

}

bTestTime = true;

UpdateInfo(SessKey,true);

}

else UpdateInfo(SessKey,false);

}

memcpy(key1,SessKey,5);

MyRC2_set_key((unsigned char *)key1);

// Very important Debug mode!!!

// Not worked without Debug mode!!!

asm{

xor ecx,ecx

mov cl,63

mov edi,ecx

mov cl,5

mov ch,3

mov ax,wst3

shl eax,16

mov ax,wst2

mov bx,wst1

shl ebx,16

mov bx,wst0

ckl1:

mov edx,eax

shr edx,16

mov si,dx

shl dx,11 //wx3<<11

shr si,5 //wx3>>5

or dx,si //wt

mov esi,ebx

shr esi,16

and si,ax

sub dx,si //wt=wt-(wx1&wx2)

mov si,ax

not si

and si,bx

sub dx,si //wt=wt-(wx0&~wx2)

sub dx,[ebp+edi*2-0x3e4]//wx3

dec di

shl edx,16

add dx,ax //dx=wx2

mov eax,edx

mov si,dx

shl dx,13

shr si,3

or dx,si

mov esi,ebx

shr esi,16

and si,bx

sub dx,si //wt=wt-(wx0&wx1)

mov esi,ebx

not esi

and esi,eax

shr esi,16

sub dx,si //wt=wt-(wx3&~wx1)

sub dx,[ebp+edi*2-0x3e4]//wx2

dec di

mov ax,dx

mov edx,ebx

shr edx,16

mov si,dx

shl dx,14 //wx1<<14

shr si,2 //wx1>>2

or dx,si //wt

mov esi,eax

shr esi,16

and si,bx

sub dx,si //wt=wt-(wx3&wx0)

mov si,bx

not si

and si,ax

sub dx,si //wt=wt-(wx2&~wx0)

sub dx,[ebp+edi*2-0x3e4]//wx1

dec di

shl edx,16

add dx,bx //dx=wx0

mov ebx,edx

mov si,dx

shl dx,15

shr si,1

or dx,si

mov esi,eax

shr esi,16

and si,ax

sub dx,si //wt=wt-(wx2&wx3)

mov esi,eax

not esi

and esi,ebx

shr esi,16

sub dx,si //wt=wt-(wx3&~wx1)

sub dx,[ebp+edi*2-0x3e4]//wx2

dec di

mov bx,dx

dec cl //i

jnz ckl1

dec ch //n

jz end

mov edx,eax

shr edx,16

xor esi,esi

mov si,ax

and si,0x3f

sub dx,[ebp+esi*2-0x3e4]

mov esi,ebx

shr esi,16

and si,0x3f

sub ax,[ebp+esi*2-0x3e4]

shl edx,16

add dx,ax

mov eax,edx

mov edx,ebx

shr edx,16

xor esi,esi

mov si,bx

and si,0x3f

sub dx,[ebp+esi*2-0x3e4]

mov esi,eax

shr esi,16

and si,0x3f

sub bx,[ebp+esi*2-0x3e4]

shl edx,16

add dx,bx

mov ebx,edx

cmp ch,2

jz n2

mov cl,5

jmp ckl1

n2:

mov cl,6

jmp ckl1

end:

cmp eax,iv2

jne tryagain;

cmp ebx,iv1

jne tryagain;

}


Назад                                Продолжение
В начало книги Криптография и Свобода - 2
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments