delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
490 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (2)


Base36 conversionGo to Magnus Flysjö's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Howto convert a number into a short A..Z, 0..9 Base36 string
Product:
Delphi all versions
Category:
Algorithm
Skill Level:
Scoring:
Last Update:
07/27/2004
Search Keys:
delphi delphi3000 article borland vcl code-snippet Base36 Hash Base serial_number license protection
Times Scored:
2
Visits:
1414
Uploader: Magnus Flysjö
Company: Hypode Sweden
Reference: N/A
 
Question/Problem/Abstract:
I need to convert a series of DWords into a hashed string that can be used as a serial number.
Answer:



I had to write a license control for an application and needed to present a hashed string for the user that could be read over phone to a call-center support in able to pass importent license data from the application.
One way to do this is was to create a 20 byte long hardware profile that included CPU information - 2 bytes, MacID - 5 bytes, CRC32 checksum of windows username and company name - 8 bytes and the harddrive serial number. All this information was then needed to be passed to the support and checked for a valid license. One way to pass these 20 bytes was to convert them into five base36 values containing [A..Z] and [0..9] characters as represantation.
The resulting string would look something as:
"DFD3LQ-FSDE3Y-WXHU89-34KLAS-WELPWE"

Below you can find functions to convert numbers into base36 strings and back again.

------------

function NumToBase36(Value : DWord) : string;
const BaseType = 36;
      Base36Table = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Var BaseIdx : Word;
begin
result := '';
repeat
  BaseIdx := Value mod BaseType;
  Value := Value div BaseType;
  result := Base36Table[BaseIdx+1] + result;
until value = 0;
end;


function Base36ToNum(Base36 : string) : Dword;
const BaseType = 36;
      Base36Table = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Var lp0,BaseIdx,Mult : integer;
begin
result := 0;
Mult := 1;
for lp0 := Length(Base36) downto 1 do begin
  BaseIdx := pos(Upcase(Base36[lp0]),Base36Table)-1;
  if BaseIdx < 0 then BaseIdx := 0;
  inc(result,(BaseIdx*Mult));
  Mult := Mult * BaseType;
end;
end;






Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
re:
    Gaetano Pellegrino (Dec 3 2006 3:38AM)

can i have an example?
Respond

RE: re:
Magnus Flysjö (Dec 3 2006 4:42AM)

Well, the article is pretty basic..

NumToBase36(Number)  -> returns a base3 string of that number.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
M. Shkolnik
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)