;============================================================================== ; 復号処理sub ; input mstdt,mstad,orgdt,orgad ; output dstdt,dstad ;============================================================================== decrypt: call orgdst call shuffleready ; bitシャッフル / 下位から mov si,offset bitwrk+02fh mov ah,02fh bslp2: push ax mov al,[si] dec si call shufflesub pop ax sub ah,1 jnc bslp2 ; XOR処理×6 call xor1 mov eax,dword ptr [dstad-1] mov cx,[dstdt] shl cx,8 xor [dstad],eax xor [dstdt],cx call xor3 mov eax,[dstad] mov cx,word ptr [dstdt+1] shr eax,8 xor [dstad],eax xor [dstdt],cx call xor5 call xor6 ret ;============================================================================== ; 暗号処理sub ; input mstdt,mstad,orgdt,orgad ; output dstdt,dstad ;============================================================================== encrypt: call orgdst ; XOR処理×6 call xor6 call xor5 mov si,offset dstdt+5 mov cx,5 xlp1: mov al,[si] dec si xor [si],al loop xlp1 call xor3 mov si,offset dstdt mov cx,5 xlp2: lodsb xor [si],al loop xlp2 call xor1 call shuffleready ; bitシャッフル / 上位から mov si,offset bitwrk xor ah,ah bslp1: push ax lodsb call shufflesub pop ax inc ah cmp ah,030h jc bslp1 ret ;============================================================================== ; move org->dst ;============================================================================== orgdst: mov eax,[orgad] mov [dstad],eax mov ax,[orgdt] mov [dstdt],ax ret ;============================================================================== ; bit shuffle 準備 ;============================================================================== shuffleready: mov bx,offset bitwrk+02fh mov cx,02fh blp1: mov [bx],cl dec bx loop blp1 mov [bx],cl mov eax,01111h xor al,byte ptr [mstdt+0] mov [seed],eax mov cx,050h blp2: call random xor edx,edx mov ebx,030h idiv ebx mov si,dx call random xor edx,edx mov ebx,030h idiv ebx mov di,dx mov ah,[si+offset bitwrk] mov al,[di+offset bitwrk] mov [si+offset bitwrk],al mov [di+offset bitwrk],ah loop blp2 ret ;============================================================================== ; bit shuffle sub ;============================================================================== shufflesub: movzx dx,al and dl,07h shr al,3 neg al movsx bx,al add bx,offset dstdt+5 movzx bp,ah and bp,07h shr ah,3 neg ah movsx di,ah add di,offset dstdt+5 mov cl,[di] mov al,[bx] bt cx,bp jc bnx1 btr ax,dx jmp short bnx2 bnx1: bts ax,dx bnx2: mov ah,al mov al,[bx] mov [bx],ah mov cl,[di] bt ax,dx jc bnx3 btr cx,bp jmp short bnx4 bnx3: bts cx,bp bnx4: mov [di],cl ret ;============================================================================== ; XOR暗号 / act 1 ;============================================================================== xor1: mov eax,0f254h mov cl,byte ptr[mstdt+1] xor al,cl mov [seed],eax and cx,00ffh jz nos1 slp1: call random mov [seed],eax loop slp1 nos1: call random xor [dstad],eax call random xor [dstdt],ax ret ;============================================================================== ; XOR暗号 / act 3 ;============================================================================== xor3: mov al,byte ptr [mstad+1] mov ah,al xor word ptr [dstad],ax xor word ptr [dstad+2],ax xor [dstdt],ax ret ;============================================================================== ; XOR暗号 / act 5 ;============================================================================== xor5: mov al,byte ptr [mstad+0] mov ah,al xor word ptr [dstad],ax xor word ptr [dstad+2],ax xor [dstdt],ax ret ;============================================================================== ; XOR暗号 / act 6 ;============================================================================== xor6: mov [seed],4EFAD1C3h mov cl,byte ptr [mstad+3] and cx,000fh jz nos2 slp2: call random mov [seed],eax loop slp2 nos2: call random xor [dstad],eax call random xor [dstdt],ax ret ;============================================================================== ; 乱数生成 ;============================================================================== random: mov eax,[seed] mov ebp,03039h imul eax,041c64e6dh add eax,ebp imul ebx,eax,041c64e6dh add ebx,ebp imul edx,ebx,041c64e6dh add edx,ebp mov [seed],edx and eax,00030000h and ebx,7fff0000h and edx,7fff0000h shl eax,14 shr ebx,1 shr edx,16 or eax,ebx or eax,edx ret ;============================================================================== ; data ;============================================================================== mstdt dw ? ;マスターコード下位2byte mstad dd ? ;マスターコード上位4byte orgdt dw ? ;入力コード下位2byte orgad dd ? ;入力コード上位4byte dstdt dw ? ;結果下位2byte dstad dd ? ;結果上位4byte seed dd ? bitwrk db 48 dup(?)