home *** CD-ROM | disk | FTP | other *** search
-
- function PackedUp(Original: string): string;
- { Take a string of characters and compress it down at a ratio
- of 5:8 by converting all characters into a 5 bit code. Only
- letters are unique, numbers are bunched together as are
- punctuation. }
- var I: word;
- J: word;
- BitMask: word;
- ShiftFactor: word;
- ResultStr: string;
- begin
- fillchar(ResultStr,sizeof(ResultStr),0); { Initialize
- result }
- J := 1;
- for I := 1 to length(Original) do { Pack each of the
- characters }
- begin
- ShiftFactor := (I+I+I) and 7;
- case Original[I] of
- '0'..'9': BitMask := 27;
- 'a'..'z','A'..'Z': BitMask := ord(Original[I]) and $1F
- else BitMask := 0
- end;
- BitMask := BitMask shl ShiftFactor;
- ResultStr[J] := chr(ord(ResultStr[J]) or lo(BitMask));
- ResultStr[pred(J)] := chr(ord(ResultStr[pred(J)]) or
- hi(BitMask));
- if ShiftFactor < 5 then
- inc(J)
- end;
- ResultStr[0] := chr((5*length(Original)+7) shr 3); { Set
- length }
- PackedUp := ResultStr
- end;