#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define LEN 126
#define MINLIMIT 37
#define MAXLIMIT 126
#define GAP 89
#define SEM 61
int key[LEN] = {35, 51, 25, 10, 0, 38, 43, 51, 22, 17, 20, 50, 38, 32, 50, 41, 50, 39, 41, 31, 40, 50, 8, 44, 22, 50, 49, 2, 15, 2, 43, 51, 41, 17, 21, 19, 22, 49, 39, 42, 36, 16, 46, 49, 36, 11, 4, 51, 22, 39, 16, 16, 28, 6, 17, 10, 9, 32, 17, 50, 22, 5, 45, 15, 9, 52, 48, 21, 9, 47, 20, 17, 5, 36, 19, 0, 1, 29, 48, 23, 2, 37, 11, 31, 43, 39, 30, 52, 4, 3, 10, 12, 40, 25, 5, 51, 3, 17, 1, 8, 11, 39, 34, 36, 4, 16, 10, 3, 35, 32, 7, 37, 9, 50, 31, 0, 42, 42, 49, 27, 52, 28, 26, 30, 45, 17};
char* tTo(char **cookie)
{
int i = 0, j = 0;
char *c = (char *)malloc(sizeof(char) * 2 * LEN);
while(j < LEN)
{
c[i++] = cookie[j][0];
c[i++] = cookie[j++][1];
}
return c;
}
char** oTt(char *cookie)
{
int i = 0, j = 0;
char **c = (char **)malloc(sizeof(char *) * LEN);
while(i < LEN)
{
c[i] = (char *)malloc(sizeof(char) * 2);
c[i][0] = cookie[j++];
c[i++][1] = cookie[j++];
}
return c;
}
int jiemi2(char *c, int b)
{
if(c[0] < SEM)
c[0] += 4;
if(c[1] < SEM)
c[1] += 4;
if(c[1] % 2 == 1)
return c[0] - MINLIMIT + GAP + 1 - b;
else
return c[0] - MINLIMIT - b;
}
char** jiemi(char *c)
{
char **cookie = oTt(c);
int i, index = 0;
int nameLen = jiemi2(cookie[index], key[index]);
index ++;
int pwdLen = jiemi2(cookie[index], key[index]);
index ++;
char *name = (char *)malloc(sizeof(char) * nameLen);
char *pwd = (char *)malloc(sizeof(char) * pwdLen);
index = 26;
for(i = 0;i < nameLen;i ++,index ++)
name[i] = (char)jiemi2(cookie[index], key[index]);
index = 76;
for(i = 0;i < pwdLen;i ++,index ++)
pwd[i] = (char)jiemi2(cookie[index], key[index]);
char **result = (char **)malloc(sizeof(char *) * 2);
result[0] = name;
result[1] = pwd;
return result;
}
char* jiami2(int a, int b)
{
int flag, rem, d;
char *c = (char *)malloc(sizeof(char) * 2);
d = (char)((a + b) % (GAP + 1) + MINLIMIT);
if(d <= SEM)
d -= 4;
c[0] = (char)d;
flag = ((a + b) >= (GAP + 1));
rem = rand() % GAP + MINLIMIT;
if(rem % 2 != flag)
rem++;
if(rem <= SEM)
rem -= 4;
c[1] = (char)rem;
return c;
}
char* jiami(char *name, char *pwd, char *t)
{
char **cookie = (char **)malloc(sizeof(char *) * LEN);
int nameLen = strlen(name);
int pwdLen = strlen(pwd);
int i, index = 0;
srand((unsigned)time(NULL));
cookie[index] = jiami2(nameLen, key[index]);
index++;
cookie[index] = jiami2(pwdLen, key[index]);
index++;
for(i = 0;i < 24;i++,index ++)
cookie[index] = jiami2((int)t[0], key[index]);
for(i = 0;i < nameLen;i ++,index ++)
cookie[index] = jiami2((int)name[i], key[index]);
for(i = 0;i < 50 - nameLen;i ++,index ++)
cookie[index] = jiami2(rand() % 100, key[index]);
for(i = 0;i < pwdLen;i ++,index ++)
cookie[index] = jiami2((int)pwd[i], key[index]);
for(i = 0;i < 50 - pwdLen;i ++,index ++)
cookie[index] = jiami2(rand() % 100, key[index]);
return tTo(cookie);
}
int main()
{
char *name = "Test";
char *pwd = "Test123";
char *t = "Sat Dec 12 23:02:35 2015";
char *cookie = jiami(name, pwd, t);
printf("cookie = %s\n", cookie);
char **result = jiemi(cookie);
printf("name = %s, pwd = %s\n",result[0], result[1]);
}
评论1
最新资源