home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Quantico / km / crypto.asm.txt < prev    next >
Encoding:
Text File  |  2000-05-25  |  6.0 KB  |  182 lines

  1. .model  tiny
  2. .386
  3. Org 100h
  4. .data
  5.  
  6. INTRONAME     db 13,10,'Crypto v3.1 - Key Generator by Quantico [mEX/c4N]',13,10
  7.               db 13,10,'Enter your name : ','$',13,10
  8.  
  9. COMPANY       db 13,10,'Enter your company : ','$',13,10
  10.  
  11. DUMBO         db 13,10,'You must enter something...',13,10,'$'
  12.  
  13.  
  14. STORENAME     db 18h, 19h dup(0)
  15. STORECOMP     db 18h, 19h dup(0)
  16.  
  17. THEIRCODE     db 13,10,'Your code is : '
  18. STORECODE     db 10 dup(0),13,10,'$'
  19.  
  20. DATATABLE1    db '#serB&nz|mfM1/5(!sd$Mq.{s]+sFjtKpzSdtzoXqmb^Al@dv:s?x/'
  21. DATATABLE2    db '|b!pz*ls;rn|lf$vi^Axpe)rx5aic&9/2m5lsi4@0dmZw94cmqpfhw'
  22.  
  23. Convert_Digs  db '0123456789ABCDEF'
  24.  
  25. .code
  26. .startup
  27.  
  28. MAIN PROC    NEAR
  29.  
  30.      MOV     AH, 09h
  31.      MOV     DX, OFFSET INTRONAME
  32.      INT     21h                        ; show the lovely intro and
  33.                                         ; ask for our name
  34.      MOV     AH, 0Ah
  35.      MOV     DX, OFFSET STORENAME
  36.      INT     21h                        ; get what they typed
  37.      CMP     BYTE PTR [STORENAME+1], 0  ; did they enter nothing ?
  38.      JE      DUMB                       ; then tell them
  39.  
  40.      MOV     AH, 09h  
  41.      MOV     DX, OFFSET COMPANY       ; ask for company
  42.      INT     21h
  43.  
  44.      MOV     AH, 0Ah
  45.      MOV     DX, OFFSET STORECOMP
  46.      INT     21h                        ; get input
  47.      CMP     BYTE PTR [STORECOMP+1], 0  ; enter nothing ?
  48.      JE      DUMB                       ; tell them
  49.  
  50.      CALL    MAKEKEY                    ; the main procedure
  51.  
  52.      MOV     AH, 09h
  53.      MOV     DX, OFFSET THEIRCODE       ; show them the code
  54.      INT     21h
  55.      JMP     FINISH                     ; go to quit
  56.  
  57. DUMB:
  58.      MOV    AH, 09h
  59.      MOV    DX, OFFSET DUMBO            ; tell them to enter something
  60.      INT    21h
  61.  
  62. FINISH:
  63.      MOV    AH, 4Ch
  64.      INT    21h                         ; quit program
  65.  
  66. MAIN ENDP
  67.  
  68. MAKEKEY  PROC   NEAR
  69.  
  70.      MOV     ESI, 0C69AA96Ch            ; esi = C69AA96C
  71.      OR      ESI, 000000378h            ; 
  72.      PUSH    ESI                        ; save result for use later
  73.      LEA     ESI, STORENAME+2           ; esi = name
  74.      MOVSX   EAX, BYTE PTR [ESI-1]      ; eax = namelength
  75.      CALL    NEXTSTAGE                  ; make first calculations
  76.      POP     ESI                        ; restore esi
  77.      ADD     ESI, EAX                   ; then add the call result
  78.      PUSH    ESI                        ; save it again
  79.      LEA     ESI, STORECOMP+2           ; esi = company
  80.      MOVSX   EAX, BYTE PTR [ESI-1]      ; eax = companylength
  81.      CALL    NEXTSTAGE                  ; make second calculations
  82.      POP     ESI                        ; restore esi
  83.      ADD     EAX, ESI                   ; add both parts
  84.  
  85.      XOR     EBX, EBX                   ; clear ebx
  86.      XOR     EDX, EDX                   ; clear edx
  87.      MOV     EDI, OFFSET STORECODE      ; place to put the string of the code
  88.      MOV     ECX, 10d                   ; number base 10
  89.      CALL    convert_num                ; number2string so we can print it
  90.      RET                                ; return
  91. MAKEKEY ENDP
  92.  
  93. NEXTSTAGE  PROC   NEAR
  94.      XOR     EDI, EDI
  95.      XOR     ECX, ECX
  96. GETMORE:
  97.      MOVSX   EBX, BYTE PTR [EAX+ECX+DATATABLE1]
  98.      MOVSX   EBP, BYTE PTR [ECX+ESI]
  99.      LEA     EDX, DWORD PTR [ECX+01]
  100.      IMUL    EBX, EBP
  101.      MOVSX   ECX, BYTE PTR [ECX+DATATABLE2]
  102.      IMUL    EBX, ECX
  103.      IMUL    EBX, EDX
  104.      ADD     EDI, EBX
  105.      MOV     ECX, EDX
  106.      CMP     EDX, EAX                  ; end of input ?
  107.      JL      GETMORE                   ; if not, go for more
  108.      MOV     EAX, EDI                  ; eax = call result
  109.      RET
  110. NEXTSTAGE  ENDP
  111.  
  112. Convert_Num proc near
  113.         pushf
  114.         pushAD
  115.  
  116.         sub     esp, 4
  117.         mov     ebp,esp
  118.  
  119.         cld
  120.         mov     esi, edi
  121.         push    esi
  122.  
  123. ;--- loop for each digit
  124.  
  125.         sub     bh, bh
  126.         mov     dword ptr [ebp], eax            ;save low word
  127.         mov     dword ptr [ebp+4], edx          ;save high word
  128.         sub     esi, esi                        ;count digits
  129.  
  130. Connum1:
  131.         inc     esi
  132.         mov     eax, dword ptr [ebp+4]          ;high word of value
  133.         sub     edx, edx                        ;clear for divide
  134.         div     ecx                             ;divide, DX gets remainder
  135.         mov     dword ptr [ebp+4],eax           ;save quotient (new high word)
  136.  
  137.         mov     eax, dword ptr [ebp]            ;low word of value
  138.         div     ecx                             ;divide, DX gets remainder
  139.                                                 ;  (the digit)
  140.         mov     dword ptr [ebp], eax            ;save quotient (new low word)
  141.  
  142.         mov     bl, dl
  143.         mov     al, byte ptr [Convert_Digs+ebx]  ;get the digit
  144.         stosb                                       ;store
  145.  
  146.         cmp     dword ptr [ebp], 0                  ;check if low word zero
  147.         jne     Connum1                             ;jump if not
  148.         cmp     dword ptr [ebp+4], 0                ;check if high word zero
  149.         jne     Connum1                             ;jump if not
  150.  
  151.         sub     al, al
  152.         stosb                                       ;store the terminator
  153.  
  154. ;--- reverse digits
  155.  
  156.         pop     ecx                          ;restore start of string
  157.         xchg    ecx, esi
  158.         shr     ecx, 1                       ;number of reverses
  159.         jz      Connum3                      ;jump if none
  160.  
  161.         xchg    edi, esi
  162.         sub     esi, 2                       ;point to last digit
  163.  
  164. Connum2 :
  165.         mov     al, byte ptr [edi]           ;load front character
  166.         xchg    al, byte ptr [esi]           ;swap with end character
  167.         stosb                                ;store new front character
  168.         dec     esi                          ;back up
  169.         loopd   Connum2                      ;loop back for each digit
  170.  
  171. ;--- finished
  172.  
  173. Connum3  :
  174.         add     esp, 4
  175.  
  176.         popad
  177.         popf
  178.         ret
  179.  endp           ;Convert_Num
  180.  
  181. END MAIN
  182.