Character Frequency Counter
Algorithm creator(s)
n/a
PB author(s)
Steve Hutchesson
Description
A tool to assist with cryptanalytical frequency distribution analysis attacks.
Note
Source
https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/6393-inline-asm-byte-frequency-counter
See also
n/a
Source Code
Download source code file frequency.bas (Right-click -> "Save as ...")
' GLOBAL array declaration, could be local within the scope of the calling function
GLOBAL cnt&()
' array must be 256 LONG or DWORD members
redim cnt&(0 to 255)
' calling code for frequency counter
bfcounter a$, VarPtr(cnt&(0))
' Parameters are,
' 1. string to have the byte frequency counted
' 2. address of the 256 member array
' Result is stored in the 256 member array which is the count of each
' character in the array.
'##########################################################################
SUB bfcounter(a$,ByVal lpArr as DWORD)
#REGISTER NONE
' -----------------------------
' fill array members with zero
' -----------------------------
! mov ecx, 256
! xor eax, eax
! mov edi, lpArr
! rep stosd
' ------------------------------------------------
' put string length in ECX and its address in ESI
' ------------------------------------------------
! mov ecx, a$
! mov ecx, [ecx] ; dereference string address
! mov esi, ecx ; copy address to ESI
! sub ecx, 4 ; get string length
! mov ecx, [ecx] ; put it in ECX
! add esi, ecx ; add length to ESI
! neg ecx ; reverse sign
! mov ebx, lpArr ; base address in EBX
! xor eax, eax ; prevent stall
fcStart:
! mov al, [esi+ecx] ; get byte
! inc DWORD PTR [ebx+eax*4] ; increment value at memory location
! inc ecx
! jnz fcStart
END SUB