(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++中运行通 |