Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92502323
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-04-15 20:47:23

     来源:赛迪论坛    作者:kool

(2)将a、a²按照一定规则变换之后成为注册字符串。
实现程序如下:

// reg.cpp : Demo program for Keygen
// By Jason Li, 2001. Written for FrontFree techonology network

#include <string>
#include <iostream>

using namespace std;

typedef int BOOL;

const BOOL TRUE=(1==1);
const BOOL FALSE=!TRUE;

// Define the magic string
const string sMagic="L5WXTUYJH7VMB4GA8SFKQN9E36RPDC";

string GetRegstr(string &sName){
string sResult="FFTN-";
long lSum=0;
long lSum1;
long lChksum;

register unsigned int i;

// Calculate the registration string
for(i=0;i<sName.length();i++){
lSum += sName.at(i) * (i+1);
}
// The checksum prevents accident input
lChksum=sMagic.at(lSum%30);
sResult+=sMagic.at(lSum%30);
lSum1=lSum;
for(i=0;i<4;i++){
sResult+=(char)((lSum%10)+’0’);
lChksum+=((lSum%10)+’0’);
lSum/=10;
}
sResult+=(sMagic.at(lChksum%30));
sResult+="-";

lChksum=0;
lSum=lSum1*lSum1/3;
for(i=0;i<5;i++){
sResult+=sMagic.at(lSum%30);
lChksum+=sMagic.at(lSum%30)*((i%2)+1); // Sum even bytes twice
lSum/=7;
}
sResult+=(sMagic.at(lChksum%36));
sResult+="-";

lChksum=0;
lSum=lSum1*lSum1/5;
for(i=0;i<5;i++){
sResult+=sMagic.at(lSum%30);
lChksum+=sMagic.at(lSum%30)*((i%2)+1); // Sum even bytes twice
lSum/=11;
}
sResult+=(sMagic.at(lChksum%36));
sResult+="-";

lChksum=0;
lSum=lSum1*lSum1/7;
for(i=0;i<5;i++){
sResult+=sMagic.at(lSum%30);
lChksum+=sMagic.at(lSum%30)*((i%2)+1); // Sum even bytes twice
lSum/=17;
}
sResult+=(sMagic.at(lChksum%30));

return sResult;
}

int main(void){
string sName;
string sRegstr;

// Output the prompt for user
cout << "Registration Code Generator DEMO program version 1.00" << endl;
cout << "By Jason Li, 2001. For test purpose only." << endl;
cout << endl;

// Loop until the user name is legal to the algorithm
do{
// Get the user name
cout << "Enter the user’s name (5 chars min), followed by comma(,): ";
getline(cin, sName, ’,’);
}while(sName.length()<=5);

cout<<"User "<<sName;

sRegstr=GetRegstr(sName);

cout<<" has the registration string of "<<sRegstr;
cout<<endl;

return 0;
}

程序按ANSI C++标准编写,在Visual C++ 6和GNU C++中运行通过。

阅读(228) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~