#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void initKeyTab(unsigned char *keyTab)
{
memset(keyTab, 0x80, 0x100);
int j;
int i;
j = 0x41;
for(i = 0x0; i < 0x1A; ++i)
{
keyTab[j + 1] = i;
++j;
}
j = 0x62;
for(i = 0x1A; i < 0x34; ++i)
{
keyTab[j] = i;
i = i << 0x18;
i = i >> 0x18;
++j;
}
j = 0x31;
for(i = 0x34; i < 0x3e; ++i)
{
keyTab[j] = i;
i = i << 0x18;
i = i >> 0x18;
++j;
}
keyTab[0x2C] = 0x3E;
keyTab[0x30] = 0x3F;
keyTab[0x3E] = 0x0;
keyTab[0x0] = 0x1;
for(i = 0; i < 0x100; ++i)
{
printf("%02x ", keyTab[i]);
if((i+1) % 16 == 0)
{
printf("\n");
}
}
printf("\n");
}
void getPasswd(unsigned char *name, int name_length, unsigned char *keyTab, unsigned char *passwd)
{
int i;
int k = 0;
char mid[4];
for(i = 0; i < name_length; i += 3)
{
int j;
mid[0] = name[i] >> 0x2;
mid[1] = ((name[i] << 0x4) & 0x3F) ^ (name[i + 1] >> 0x4);
mid[2] = ((name[i + 1] & 0x0F) << 0x2) ^ (name[i + 2] >> 0x6);
mid[3] = name[i + 2] & 0x3F;
for(j = 0; j <= 0x100; ++j)
{
if(keyTab[j] == mid[0])
{
passwd[k] = j - 1;
}
if(keyTab[j] == mid[1])
{
passwd[k + 1] = j - 1;
}
if(keyTab[j] == mid[2])
{
passwd[k + 2] = j - 1;
}
if(keyTab[j] == mid[3])
{
passwd[k + 3] = j - 1;
}
}
k += 4;
}
printf("passwd: %s\n", passwd);
}
void main()
{
unsigned char name[] = "123456789";
int name_length = strlen(name);
unsigned char passwd[12];
unsigned char keyTab[0x100];
initKeyTab(keyTab);
getPasswd(name, name_length, keyTab, passwd);
}