Here is a small project in a Zip
file called
TestFormat.
The purpose is to help understand the power of formatting strings in Delphi. Once compiled, the programmer can test different strings and see the result. It works with the routines : - Format - FormatFloat - FormatDateTime It was written in Delphi 4 but should work or could be adapted
to previous
versions.
|
Uses ideas of basic cryptography that I've read from Cryptography Theory & Practice ISBN0-8493-8521-0
unit Cryptlib;
(* copyright 1996 sunil@magnetic.demon.co.uk.
This function is placed into the public domain by the author.
for each character in input string find position in CIPHERKEY
index of new character is
(position^2 + last_calculated_index) MOD length(CIPHERKEY);
budding shareware writers could use this sort of
simple encryption to create 2 keys
1) based on user supplied details
2) based on some other information (not divulged)
at the very minimum change the CIPHERKEY *)
interface
uses sysutils;
function shareware_encode(the_string:string):string;
implementation
const
CIPHERKEY = 'ABCDEFGHIJKL0123456789MNOPQRSTUVWXYZ';
CIPHERLEN = 16;
{**********************************************************
*********************************************************}
function shareware_encode(the_string:string):string;
var
upper_string,clean_string, encoded_string:string;
inchar, outchar:char;
index,pos1,pos2,last_pos:integer;
key_len,max_len,upper_len:integer;
key:string;
today:tdatetime;
begin
{----------------------init-----------------------------}
key := uppercase(CIPHERKEY);
encoded_string := '';
key_len := length(key);
upper_string := uppercase(the_string);
last_pos := 0;
{-------------remove invalid characters-------------------}
clean_string := '';
for index := 1 to length(upper_string) do
if pos(upper_string[index],key) >0 then
clean_string := clean_string + upper_string[index];
upper_string := clean_string;
{----------make sure input string is the right length-----}
upper_len := length(upper_string);
if upper_len < CIPHERLEN then
begin
for index := 1 to (CIPHERLEN - upper_len) do
upper_string := upper_string + key[index];
end;
upper_len := length(upper_string);
if upper_len > CIPHERLEN then
begin
upper_string := copy(upper_string,1,CIPHERLEN);
end;
{--------nothing too complex, just encrypt each
character------------}
for index:=1 to CIPHERLEN do
begin
inchar := upper_string[index];
pos1 := pos(inchar,key);
pos2 := ((pos1*pos1 + last_pos) MOD key_len);
inc(pos2);
last_pos:= pos2;
outchar := key[pos2];
encoded_string := encoded_string + outchar;
{- - - - - - - for ease of reading split every 4 characters - - - }
if (index mod 4 = 0) and (index < CIPHERLEN) then
encoded_string := encoded_string +'-';
end;
{---------------------all done ----------------}
shareware_encode := encoded_string;
end;
end.
{ THashTable unit - Delphi 1
version -
by kktos, May 1997.
This code is FREEWARE. *** Please, if you enhance it, mail me at kktos@sirius.fr ***} unit HashTabl; interface uses Classes; type
{ Class THashList, from Delphi 2 TList source
THashItem= record
PHashItemList = ^THashItemList;
THashList = class(TObject)
protected
public
function
Add(const
Item: THashItem): Integer;
property
DeleteType:
TDeleteType read FdeleteType write
{ Class THashTable
THashTable= class(TObject)
procedure Error; function getCount: integer;
public
procedure Add(const key: string; value: TObject);
property
DeleteType:
TDeleteType read getDeleteType write
function hash(key: Pointer; length: longint; level: longint): longint; implementation uses SysUtils, Consts; type
array12= packed array[0..11] of byte;
longPtr= ^longint;
{ --- Class THashList ---
{-----------------------------------------------------------------------------} constructor THashList.Create;
{-----------------------------------------------------------------------------} destructor THashList.Destroy;
{-----------------------------------------------------------------------------} function THashList.Add(const Item: THashItem): Integer;
{-----------------------------------------------------------------------------} procedure THashList.Clear(dt: TDeleteType);
{-----------------------------------------------------------------------------} { know BC++ ? remember TArray::Detach?
{-----------------------------------------------------------------------------} { know BC++ ? remember TArray::Destroy ? renames delete 'cause
{-----------------------------------------------------------------------------} procedure THashList.Error;
{-----------------------------------------------------------------------------} function THashList.Expand: THashList;
{-----------------------------------------------------------------------------} function THashList.Get(Index: Integer): THashItem;
{-----------------------------------------------------------------------------} procedure THashList.Grow;
{-----------------------------------------------------------------------------} function THashList.IndexOf(key: longint): Integer;
if Result = FCount then Result:= -1;
{-----------------------------------------------------------------------------} procedure THashList.Put(Index: Integer; const Item:
THashItem);
{-----------------------------------------------------------------------------} procedure THashList.Pack;
{-----------------------------------------------------------------------------} procedure THashList.SetCapacity(NewCapacity: Integer);
{-----------------------------------------------------------------------------} procedure THashList.SetCount(NewCount: Integer);
{ --- Class THashTable ---
{-----------------------------------------------------------------------------} constructor THashTable.Create;
{-----------------------------------------------------------------------------} destructor THashTable.Destroy;
{-----------------------------------------------------------------------------} procedure THashTable.Error;
{-----------------------------------------------------------------------------} {
{-----------------------------------------------------------------------------} {
{-----------------------------------------------------------------------------} {
{-----------------------------------------------------------------------------} {
{-----------------------------------------------------------------------------} {
{-----------------------------------------------------------------------------} procedure THashTable.Pack;
{-----------------------------------------------------------------------------} function THashTable.getCount: integer;
begin
result:= Ftable.Count;
{-----------------------------------------------------------------------------} procedure THashTable.setItem(index: integer; obj: TObject);
{-----------------------------------------------------------------------------} { original code from lookup2.c, by Bob Jenkins, December 1996
begin
if((longint(key) and 3) <> 0)
then begin
{mix(a,b,c);}
inc(longint(k),12);
else begin
{mix(a,b,c);}
inc(longint(k),12);
inc(c,length); if(len>=11) then inc(c, (longint(k^[10]) shl 24));
{mix(a,b,c);}
result:= longint(c);
end. |