How a serial works

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

How a serial works

Post by mrminecrafttnt »

This little code shows up how serials are working.

Code: Select all

#include "windows.bi"
dim as bool application_unlocked

sub demo
    print "THIS HERE IS THE DEMO"
end sub

sub fullversion
    print "THIS HERE IS THE FULLVERSION"
end sub


function gen_serial_code (s as string) as ulongint
    dim as ulongint a
    for i as integer = 0 to len(s) -1
        select case s[i]
        case ASC("A")
            a += 1000
        case ASC("B")
            a +=4321
        case ASC("C")
            a +=659483
        case ASC("D")
            a +=543893
        case ASC("E")
            a +=243294
        case ASC("F")
            a +=954930
        case ASC("G")
            a +=432932
        case ASC("H")
            a*=2
        case ASC("1")
            a*=3
        case ASC("2")
            a*=43
        case ASC("3")
            a*=123
        case else
            a = 0
        end select
    next
    print a
    return a
end function


DIM AS STRING SERIAL

INPUT "ENTER YOUR SERIAL :";SERIAL ' ONE OF THEM IS DDCDE221AGH

if  gen_serial_code (SERIAL) = 28118122728 then
    print "SERIAL CORRECT"
    application_unlocked =  true
else
    print "SERIAL BAD"
end if

color 15
if application_unlocked then
    fullversion
else
    demo
end if
color 7

print "PRESS A KEY TO EXIT"
getkey
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How a serial works

Post by MrSwiss »

Nope, sorry, but a Serial is of Type Double (not a U-/LongInt).

Read FB-doc!
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: How a serial works

Post by D.J.Peters »

@MrSwiss this way decoded number is a 64 bit integer and it's OK for me.

Why do you think it must be double ?

Joshy
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: How a serial works

Post by MrSwiss »

@Joshy,

because, FB-Doc says so, e.g. Date/Time Serial ...
A Serial holds 2 different (but related) sets of Data.

With a ULONGINT you'd have to use a Type within a Union, to achieve something similar:

Code: Select all

Union Serial
    As ULongInt Q_Word
    Type
        As ULong HDW  ' high double word
        As ULong LDW  ' low double word
    End Type
End Union
The advantage is still with the Double, because you can *see*, what's what:
left part of decimal separator / right part of ... (when printing to screen).
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: How a serial works

Post by integer »

mrminecrafttnt wrote:This little code shows up how serials are working.

Code: Select all

#include "windows.bi"
dim as bool application_unlocked
...
DIM AS STRING SERIAL
INPUT "ENTER YOUR SERIAL :";SERIAL ' ONE OF THEM IS DDCDE221AGH
...
if application_unlocked then
    fullversion
else
    demo
end if
...
Is this code dealing with Date/Time serial numbers or
someone's membership serial number identification string?
It appears (to me) to be the latter.

A detailed explanation (or slightly more information) would have been helpful.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: How a serial works

Post by D.J.Peters »

MrSwiss and integer the posted code isn't a serial time/date.
It's a serial key for example to ativate a downloaded demo version as full version.

Joshy
Post Reply