unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,shellapi;
type
TForm1 = class(TForm)
Button1: TButton;
KeyEdit: TEdit;
PasswordEdit: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function GetKeyString(Name: string): string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
PasswordEdit.text:=GetKeyString(KeyEdit.Text);
end;
//获得注册码
function Tform1.GetKeyString(Name: string): string;
var
S, Tmp: string;
I, N, PN: LongInt;
{*******Prime Number Function********}
function Prime(n: byte): boolean;
//
var
i, ndiv: byte;
begin
ndiv:=2;
//初始化ndiv变量
Result:=true;
//默认返回结果true
for i:=2 to n-1 do
begin
if (n mod i) = 0 then
inc(ndiv);
if ndiv > 2 then
begin
result:=false;
break;
end
end;
end;
{************************************}
begin
N:=0;
S:=Name;
//注册用户提供的注册名字
for i:=1 to length(S) do
begin
if Prime(ord(S)) then
Tmp:=Tmp + UpperCase(S);
//ord函数返回S字母在序数类型中的位置值
if i <> 1 then
Pn:=ord(S[i-1]) else
Pn:=ord(S[1]);
N:=Pn shl 2 + N+8;
//N:=Pn shl 3 + N;这一行代码时生成序列号的关键代码,通过将数字“3”修改成其它数字或者再加上任意一个数字等形式,可以生成不同的注册码
end;
S:=Tmp + IntToStr(N);
Result:=S;
end;
end.