The following demonstrates how to use Delphi language to download data from an AlphaRNG device
when used with the AlphaRNG Entropy Server for Windows.
The following code will only work when running AlphaRNG Entropy Server.
Before using the following examples, make sure your Delphi project is targeted for Windows 32 bit platform and
the AlphaRNG device is plugged into one of USB ports available.
Both AlphaRNG-32.dll and AlphaRNG-64.dll are included in the AlphaRNG software kit and can be downloaded from this location.
A sample source code for retrieving data from AlphaRNG device when using AlphaRNG Entropy Server for Windows and AlphaRNG-32.dll
//
//
// A sample Delphi program that demonstrates how to retrieve data from
// AlphaRNG device using AlphaRNG Entropy Server for Windows and AlphaRNG-32.dll
// when using 32-bit Windows as a target platform.
//
// For 64-bit applications use AlphaRNG-64.dll
//
//
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
const
randomNumberCount = 10; // How many random bytes to retrieve
type
RandomBuffer = array [0 .. (randomNumberCount - 1)] of byte;
xbuffer = ^RandomBuffer;
IdentifierBuffer = array [0 .. 14] of byte;
ibuffer = ^IdentifierBuffer;
ModelBuffer = array [0 .. 14] of byte;
mbuffer = ^ModelBuffer;
var
i, status: integer;
zbuffer: randombuffer;
serialnumber: identifierbuffer;
model: modelbuffer;
Function getEntropy(x: xbuffer; y: longword): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getEntropyAsByte(): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getDeviceIdentifier(p: ibuffer): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getDeviceModel(p: mbuffer): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getDeviceMajorVersion(): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getDeviceMinorVersion(): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getServerMajorVersion(): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getServerMinorVersion(): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
Function getNoise(x: xbuffer; y: longword; z: integer): integer; stdcall; external 'C:\tools\alrng-windows-binaries\windows-x86-vs-2019\AlphaRNG-32.dll';
begin
try
status := getDeviceModel(@model);
if status = 0 then
begin
writeln('Device model: ', TEncoding.ANSI.GetString(model));
status := getDeviceIdentifier(@serialnumber);
if status = 0 then
begin
writeln('Device identifier: ', TEncoding.ANSI.GetString(serialnumber));
end
else
writeln('Could not retrieve device identifier');
writeln('Device version: ', getDeviceMajorVersion(), '.', getDeviceMinorVersion());
writeln('Entropy server version version: ', getServerMajorVersion(), '.', getServerMinorVersion());
writeln('Entropy sample byte: ', getEntropyAsByte);
status := getEntropy(@zbuffer, randomNumberCount);
if status = 0 then
begin
for i:=0 to randomNumberCount-1 do
writeln('entropy byte[',i,'] = ', zbuffer[i]);
end
else
writeln('Could not retrieve entropy');
status := getNoise(@zbuffer, randomNumberCount, 1);
if status = 0 then
begin
for i:=0 to randomNumberCount-1 do
writeln('source noise 1 byte[',i,'] = ', zbuffer[i]);
end
else
writeln('Could not retrieve bytes from noise source 1');
status := getNoise(@zbuffer, randomNumberCount, 2);
if status = 0 then
begin
for i:=0 to randomNumberCount-1 do
writeln('source noise 2 byte[',i,'] = ', zbuffer[i]);
end
else
writeln('Could not retrieve bytes from noise source 2');
end
else
writeln('Could not retrieve device model, is entropy server running?');
except
on E: Exception do
writeln(E.ClassName, ': ', E.Message);
end;
end.