| © 2008 W.Ehrhardt |
Last update June 27, 2008 |
Here you find a growing list of utility and standalone source codes other than CRC/Hash and Crypto:
Util, PRNG, MPArith, zlib, Delphi CRT.
The archive std_inc.zip
always contains the latest version of the standard include file std.inc.
Before downloading any software from this site please read this
legal notice.
Util
The archive util_2008-06-27.zip contains a collection of
small units; in the past some of the units were available separately.
Online help is available as Windows .hlp file or as a .tph for the BP7 IDE.
Last changes:
Compvers V0.18 supports FPC 2.2.2, code for TP5-7 in Sort V1.18
- Base2N V0.38:
General base 2**N conversion routines (N=1...6)
- Bitarray V0.17:
Bit array context with max. 524160 bits (spin off from mpint 16 bit prime sieve)
-
BTypes V0.12:
Common basic type definitions
- Compvers V0.18:
Compiler version as string or symbol
- Dates V0.33:
Implements compiler and OS independent routines for the current date
and time (including milliseconds since midnight) and functions for Julian day numbers.
- Fio V0.15:
File IO with $I- and Err variable (without try/finally),
simple wrapper calls for system routines.
- Hrtimer V0.23:
Contains a high resolution
timer for most Pascal/Delphi compilers using the comp data type. It uses
the RDTSC instruction, therefore it will stop on machines that do
not support RDTSC (this feature can be turned off via $ifdef). The timer
is used by several optimizing test programs.
- Mem_util V0.94:
Implements compiler independent routines for comparing memory blocks and
converting memory blocks to HEX and Base64 strings.
- Ministat V0.43:
Statistics unit with accurate "on the fly" statistics routines for one and two
variables.
- Sort V1.18:
General QuickSort, HeapSort (standard and bottom-up), CombSort routines using
swap/compare functions. Additional pointer versions have a typeless data
pointer that is carried through the functions and can be used to access
local data etc by the caller.
- Tsc V0.35:
This unit has a more low level access to the Time Stamp Counter
than hrtimer and additionally defines a system dependent low resolution counter
(GetTickCount, 18.2 Hz Systick, or milliseconds since midnight)
if RDTSC support is not available.
PRNG
Last changes:
Richard P. Brent's xor4096 generator
The archive prng_2007-04-25.zip
contains six fast pseudo random number generators
with period lengths much greater
than Pascal's random function: taus88 and taus113 (Pierre L'Ecuyer), tt800 and mt19937
(Makoto Matsumoto et al, mt19937 is the famous Mersenne Twister), kiss123 (George Marsaglia),
and xor4096 (Richard P. Brent).
All are implemented with context records, therefore several
independent generators can be used simultaneously, they are not cryptographically secure.
In addition there are three cryptographic generators:
-
Bob Jenkins' public domain ISAAC random number generator
(Indirection, Shift, Accumulate, Add, and Count).
The average cycle length of ISAAC is 2**8295, the minimum length is 2**40.
- salsar is based upon the Salsa20 stream cipher
and needs the salsa20 unit from salsa_2006-05-07.zip.
The core routine uses 128 bit keys and 8 rounds (this default value can be changed
to 12 or 20 rounds with salsar_set_rounds).
- aesr uses routines from aes_YYYY-MM-DD.zip
in CTR mode with 128 bit key.
The units and test programs can be compiled with all current Pascal
(TP5/5.5/6, BP7, VP 2.1, FPC 1.0/2.0) and Delphi (1..7/9/10) versions. Most test
programs need the ministat and/or the hrtimer unit. All generators interface
the following functions, a few special procedures are not listed here:
procedure generic_init(var ctx: generic_ctx; seed: longint);
{-Init context from seed}
procedure generic_init0(var ctx: generic_ctx);
{-Init context from randseed}
procedure generic_next(var ctx: generic_ctx);
{-Next step of PRNG}
procedure generic_read(var ctx: generic_ctx; dest: pointer; len: longint);
{-Read len bytes from the PRNG to dest}
function generic_long(var ctx: generic_ctx): longint;
{-Next random positive longint}
function generic_word(var ctx: generic_ctx): word;
{-Next random word}
function generic_double(var ctx: generic_ctx): double;
{-Next random double [0..1) with 32 bit precision}
function generic_double53(var ctx: generic_ctx): double;
{-Next random double in [0..1) with 53 bit precision}
function generic_selftest: boolean;
{-Simple self-test of PRNG}
Table of properties (C/B: CPU cycles per byte, MB/s: million bytes per second
on 1.8 GHz Pentium 4 / Windows 98, P7: Borland Pascal 7 real mode with 386 BASM;
isaac was compiled with {$define testing}):
| Generator | ctx size | cycle length | C/B P7 | MB/s P7 | C/B D6 | MB/s D6 |
| random | (4) | 2**32 | 79.0 | 22.7 | 7.5 | 239.0 |
| taus88 | 16 | 2**88 | 80.5 | 22.3 | 6.5 | 275.8 |
| taus113 | 20 | 2**113 | 83.0 | 21.6 | 8.3 | 217.3 |
| kiss123 | 20 | 2**123 | 96.0 | 18.7 | 11.8 | 152.6 |
| tt800 | 106 | 2**800 | 230.8 | 7.8 | 18.1 | 99.2 |
| xor4096 | 522 | 2**4096 | 82.5 | 21.7 | 5.8 | 311.8 |
| mt19937 | 2502 | 2**19937 | 220.3 | 8.1 | 8.3 | 216.2 |
| aesr | 290 | 2**128 | 236.0 | 7.6 | 28.4 | 63.2 |
| salsar | 202 | 2**70 | 109.3 | 16.4 | 14.4 | 124.8 |
| isaac | 2066 | 2**8295 | 109.5 | 16.3 | 9.1 | 197.8 |
MPArith
mpa_2008-06-12.zip: This archive
contains Pascal source for multi precision integer, rational, and floating point arithmetic;
The basic routines can be compiled with the usual Pascal versions
that allow const parameters (BP 7.0, VP 2.1, FPC 1.0/2.0/2.2,
and Delphi versions 1..7/9/10).
A separate introduction can be found on the mp_intro page;
Windows and Borland Pascal help files are in the archive.
Last changes:
Version 1.6.18 has the following new/changed functions; for a complete list with brief descriptions
see the mp_intro function list:
- New functions:
mp_ahex,
mp_cornacchia,
mp_cornacchia4,
mp_crt_setup,
mp_crt_setupf,
mp_crt_single,
mp_crt_solve,
mp_gcd1,
mp_hex,
mp_i2pchar,
mp_invmodf,
mp_is1a,
mp_not_init_multi,
RSA/CRT:
mp_pkcs1v15_decrypt2,
mp_rsadp2,
mp_rsa_calc_d,
mp_rsa_calc_npq,
mp_rsa_calc_private,
mp_rsa_clear_private,
mp_rsa_init_private,
mp_rsa_keygen2
- Changed functions:
Improved carry propagation in s_mp_add_d and s_mp_sub_d;
mp_is* routines return false if mp_error<>MP_OKAY.
- Other:
updated mp_calc, t_calc, t_rcalc sources
- Bugfixes:
mp_is_square2 (psqrt^ := a if a=0 or 1); mp_mod_d (for a < 0)
There are test programs that verify the functions and the compilation.
Demo programs are included for pi calculation, expression parsing and evaluation, factorization based
on Pollard's rho and p-1, Williams's p+1, and ECM methods etc.
My Pascal routines are based on many public resources (source code
libraries, books, articles), links are given in the
mp_intro references.
zlib
zlibw114_2005-08-03 is my Pascal port of the
zlib
general purpose compression library version 1.1.4. It is based on
PASZLIB 1.0
from Jacques Nomssi Nzali (corresponding to zlib 1.1.2). It includes official
patches/changes up to v1.1.4 and some results from e-mail communication with
Mark Adler.
Further changes are in gzio/minigzip, inffixed.inc, minizip, zdeflate (made
code for $ifdef FASTEST usable), zlibh (z_assign as a work around for a nasty
D6/7/9 bug), zutil, example (made test_sync code etc work).
Other features: 1) zlibex unit with custom deflate and inflate routines (incl. test program), it is
used in the FZCA demo program.
2) Pascal port of the zpipe sample program. 3) Code
improvements: make BUILDFIXED and assert work, bug fix in gzerror, etc.
Last changes: The Aug. 2005 archive contains FPC V2.0 fixes.
The library can be compiled with BP7 (DOS/Win/DPMI), Delphi 1-7/9, Virtual
Pascal V2.1 and Free Pascal 1.0/2.0.
The unit structure is slightly changed compared to PASZLIB:
zlib (functions),
zlibh (types/consts),
gzio (gz functions)
should be the only units used by applications of zlib.
Note: the zlib routines should only be applied to files with sizes
less that 2 GB (32 bit counters; Delphi eof bug and/or 32 bit filesize function).
Delphi CRT unit
During the development of the mpint expression parser a number of deviations
of Will de Witt's trusty Delphi CRT unit compared to BP7 were noticed and I decided to write a
more compatible CRT unit.
dcrt_2006-11-08.zip is a light version of Will DeWitt's code with several bug fixes
(especially readkey, extended key codes etc). Will's 'unit was based heavily
off of the Borland CBuilder 5 RTL'. Because of the unclear license status of Will's
unit, my CRT source is not under zlib license. It is published with this
disclaimer:
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from
the use of this software.
If you use this code, please credit me and keep the references to the other
authors and sources.
Anyway, in this unit the code from Will/Borland
is radically rewritten and rearranged. The guiding requirement was to make it
almost BP7 compatible.
The basic idea for separate hardware/software sound
support is from Rudy Velthuis' freeware console, but the implementation is
different.
The supported keys for line editing are from BP7 (^A, ^H, ^D, ^F,
^M, ^S, ^Z), the paradigm shift from readkey to keypressed for doing the
dirty work is from FP. The key codes / translations / functionalities were taken
from the Phoenix BIOS book and a test program compiled with BP7.
Here are links to the referenced software programs.
There is still work to be done for some rare special extended keys, but this
work is delayed to bugfixes or problem reports.