TRUE RANDOMNESS captured... (Keyboard-only)

New Message Reply About this list Date view Thread view Subject view Author view

Dutra de Lacerda (dulac@ip.pt)
Sat, 22 Aug 1998 01:34:19 +0100


TRUE RANDOM No-Hardware Routine (in Pseudocode)

This routine is based on Keyboard Input and Keyboard latency.
Can be modified so each KeyPressed creates one new 32bits word.
Idle Transforms have been influenced by TEA algorithm.

        function GetTickCount()
        Input None
        Call Mov ah, 00h
                Int 1Ah
        Output CX = High( TickCount )
                DX = Low ( TickCount )

        function GetKeybStatus()
        Input None
        Call Mov ah, 11h
                Int 16h
        Output Zero flag Set = ZF = No KeyPressed
                Zero Flag Clear = NZ = Key Waiting

        function GetKeyPressed()
        Input None
        Call Mov ah, 10h
                Int 16h
        Output AH = Keyboard Scan Code
                AL = ASCII Char

        
        function Random()
        Input None
        Call mov CODES, 0000
                mov RAND, 00000000
                mov SUM, 00000000
                mov DELTA, 9E3779B9
        Loop:
                add SUM, DELTA
                mov RAND, SUM
                rol RAND, 3
                call GetKeybStatus
                jz Tick
                jnz Key
        Tick:
                Call GetTickCount
                add RAND, Ticks in CX:DX
                jmp Next
        Key:
                Call GetKeyPressed
                Mov CODES, AX
                add Low(RAND), CODES
                jmp Next
        Next:
                XOR RAND, SUM
        Until:
                mov AL, Low(Codes)
                Test AL, 10h
                JZ Return
                Test AL, 13h
                JZ Return
                Test AL, 1Bh
                JZ Return
                JMP LOOP
        Return:
                MOV CX, High( RAND )
                MOV DX, Low ( RAND )
                
        Output RAND in CX:DX

Notes: This routines have an undetermined number of cycles while waiting
        for a keypressed. IMHO this is a TRUE random routine.
        I suspect that if pipes are used ( I suspect they can't ) even then
        a good degree of randomness would be achieved due to system chaotic
        events... Specially if a disk running at the same time AND/OR Mouse
        usage.

        This can be changed to use Disk or Mouse events instead of Keyboard.

        It seems an elegant procedure... But I still may do some changes...

Regards,
Dutra de Lacerda.

 - - -
Antonio Manuel Melo de Carvalho Dutra de Lacerda
Morada : Rua Rodrigues Cabrilho, 5 - 5 Esq.
                  1400 Lisboa, PORTUGAL
Telefone : +351-(1)-3013579
FAX & BBS : +351-(1)-3021098


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:11:00