//一个简单的字符串加密程序
#include <stdio.h>
#include <string.h>
#define LODWORD(_qw) ((unsigned long)(_qw))
#define HIDWORD(_qw) ((unsigned long)(((_qw) >> 32) & 0xffffffff))
char *pkey = "www.oschina.net";
char *keymap = "abcdefghijklmnopqrstuvwxyz";
void encrypt(char *username, char *key)
{
int i;
unsigned __int64 v6;
unsigned __int64 tmp;
int nameLen = strlen(username);
for ( i = 0; i != nameLen; ++i )
{
tmp = (keymap[i] * username[i] ^ 0x28FC) & 0xFFFFFFF;
v6 = LODWORD(tmp);
tmp = (unsigned int)keymap[i] * (unsigned __int64)(unsigned int)username[i] >> 32;
v6 += HIDWORD(tmp);
key[i] = pkey[v6 % 0xF];
key[i + 1] = 0;
}
}
int main(int argc, char* argv[])
{
char *name = "luobotou";
char key[64] = {0};
encrypt(name, key);
printf("name:%s\nkey:%s \n", name, key);
getchar();
return 0;
}
转载地址: http://www.oschina.net/code/snippet_583625_18718