; Tiny Encryption Algorithm
; A public domain block cipher by David Wheeler and Roger Needham
; TEA uses a 128 bit key and operates on 64 bit data blocks
;
; Hi, that dec-rol-xor thing looks very weak, but TEA seems to be okay
; and has a nice license. Can you add an user interface to it? Something
; like "tea 2e962c52c007fd0f inf.txt out.tea" will do :-)
;

code            segment byte public
                assume  cs:code, ds:code
		org	100h
tea             proc    far

start:          jmp     initialize
include         \nxdos\src\toolbox.asm
include         \nxdos\src\kernel\tea\tealib.inc
initialize:
        call cs:main
        .286c
exitptr:
        call dosexit
        int 20h      
tea             endp

testtea proc far
     _Debugd Key, 64
     _newline

     mov  si, offset Key
     mov  di, offset TEAData
     call tea_encrypt
     _Debugd Key, 64
     _newline

     mov  si, offset Key
     mov  di, offset TEAData
     call tea_decrypt
     _Debugd Key, 64
     ret
testtea endp


main proc far

     cparam '/', 0, 0
     call debugregisters
     _newline
     cmp  cx, 0
     je   nocmds
     mov  cx, bx
showparams:
          push cx
          mov  ax, cx
          mov  bh, '/'
          mov  bl, 0
          call scancmdline
          mov  cx, dx
showbuffer:
          mov  al, byte ptr es:[di]
          inc  di
          call teletype
          loop showbuffer
          pop  cx
     loop showparams
nocmds:
     ret




     xor  ax, ax
     xor  bx, bx
     xor  cx, cx
     mov  cl, byte ptr cs:[0080h]
          mov  al, cl
          call put_hex
     test cx, cx
     jz   scancmd_d
          push cs
          pop  es
          xor  bx, bx
          mov  di, 0081h
          mov  al, es:[di]
          call put_hex
scancmdl:
          mov  al, byte ptr es:[di]
          call teletype

          cmp  al, 0
          je   scancmd_d
          cmp  al, 0ah
          je   scancmd_d
          cmp  al, 0dh
          je   scancmd_d
          cmp  al, 20h
          jne  not_a_space
               ; count parameters
               inc bx
not_a_space:
          loop scancmdl
scancmd_d:
     mov  ax, bx
     call putnum
     ret



     mov  si, 0080h
     call parameters
     mov  ax, cx
     call putnum



;     input  = param1
;     output = "$$$$$$$$.$$$"
;     open input
;     create output 
;     process:
;            fill buffer, 8, NUL
;            read input, 8
;            encrypt 8
;            write 8, output
;            if not eof goto process
;     close output
;     close input
;     delete input
;     rename output, input
     ret
main endp

code            ends

ProgramEnd      EQU $-01h
		end	start
