首页
社区
课程
招聘
[求助]发一个密码函数,大家分析下!
发表于: 2010-4-8 15:50 5509

[求助]发一个密码函数,大家分析下!

2010-4-8 15:50
5509
-------------------------------------------
function jm(str)
if str="" then
str="123456"
end if
zf=len(str)
for i=1 to zf/2
zh=mid(str,(i*2-1),2)&"$"
jsq=jsq&zh
next
jm=jsq
jm=replace(jm,"aa$","z")
jm=replace(jm,"ag$","y")
jm=replace(jm,"34$","x")
jm=replace(jm,"33$","w")
jm=replace(jm,"32$","v")
jm=replace(jm,"31$","u")
jm=replace(jm,"30$","t")
jm=replace(jm,"29$","s")
jm=replace(jm,"28$","r")
jm=replace(jm,"27$","q")
jm=replace(jm,"26$","p")
jm=replace(jm,"25$","o")
jm=replace(jm,"24$","n")
jm=replace(jm,"23$","m")
jm=replace(jm,"22$","l")
jm=replace(jm,"21$","k")
jm=replace(jm,"20$","j")
jm=replace(jm,"19$","i")
jm=replace(jm,"18$","h")
jm=replace(jm,"17$","g")
jm=replace(jm,"j6$","f")
jm=replace(jm,"g5$","e")
jm=replace(jm,"3e$","d")
jm=replace(jm,"cv$","c")
jm=replace(jm,"ni$","b")
jm=replace(jm,"df$","a")
jm=replace(jm,"p8$",".")
jm=replace(jm,"o7$","_")
jm=replace(jm,"h9$","9")
jm=replace(jm,"r8$","8")
jm=replace(jm,"w2$","7")
jm=replace(jm,"er$","6")
jm=replace(jm,"ki$","5")
jm=replace(jm,"ba$","4")
jm=replace(jm,"mi$","3")
jm=replace(jm,"eh$","2")
jm=replace(jm,"zm$","1")
jm=replace(jm,"lx$","0")
end function
-------------------------------------------------------------------

看看解密如何?
解密函数
-------------------------------------------------------
function jmr(str)
if str="" then
response.Write("解密数据不能为空")
end if
zf=len(str)'取字符长度
for i=1 to zf
sun=mid(str,i,1)&"¥"
jsq=jsq&sun
next
jmr=jsq

jmr=replace(jmr,"z¥","aa")
jmr=replace(jmr,"y¥","ag")
jmr=replace(jmr,"x¥","34")
jmr=replace(jmr,"w¥","33")
jmr=replace(jmr,"v¥","32")
jmr=replace(jmr,"u¥","31")
jmr=replace(jmr,"t¥","30")
jmr=replace(jmr,"s¥","29")
jmr=replace(jmr,"r¥","28")
jmr=replace(jmr,"q¥","27")
jmr=replace(jmr,"p¥","26")
jmr=replace(jmr,"o¥","25")
jmr=replace(jmr,"n¥","24")
jmr=replace(jmr,"m¥","23")
jmr=replace(jmr,"l¥","22")
jmr=replace(jmr,"k¥","21")
jmr=replace(jmr,"j¥","20")
jmr=replace(jmr,"i¥","19")
jmr=replace(jmr,"h¥","18")
jmr=replace(jmr,"g¥","17")
jmr=replace(jmr,"f¥","j6")
jmr=replace(jmr,"e¥","g5")
jmr=replace(jmr,"d¥","3e")
jmr=replace(jmr,"c¥","cv")
jmr=replace(jmr,"b¥","ni")
jmr=replace(jmr,"a¥","df")
jmr=replace(jmr,".¥","p8")
jmr=replace(jmr,"_¥","o7")
jmr=replace(jmr,"9¥","h9")
jmr=replace(jmr,"8¥","r8")
jmr=replace(jmr,"7¥","w2")
jmr=replace(jmr,"6¥","er")
jmr=replace(jmr,"5¥","ki")
jmr=replace(jmr,"4¥","ba")
jmr=replace(jmr,"3¥","mi")
jmr=replace(jmr,"2¥","eh")
jmr=replace(jmr,"1¥","zm")
jmr=replace(jmr,"0¥","lx")
end function
---------------------------------------------------

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 993
活跃值: (442)
能力值: ( LV12,RANK:403 )
在线值:
发帖
回帖
粉丝
2
怪异的加密,要求str的长度必须为偶数。
解密只须对字符串S中的S(i)逐一扫描,S(i+2)为$的,保留S(i)及S(i+1),去掉S(i+2),不是的则按相反的替代法则还原就行。
2010-4-8 16:41
0
雪    币: 423
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
jm(x)=md5(y,16)  已知y ;求x
2010-4-8 16:48
0
雪    币: 67
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
参考二楼的吧。根据replace得到一个对照表,然后直接去掉$符号就可以了。
就等价于求jm(x)=y的逆函数。
2010-4-8 18:32
0
雪    币: 622
活跃值: (294)
能力值: ( LV13,RANK:410 )
在线值:
发帖
回帖
粉丝
5
jm的规则其实就是把传递进来的字符串按2:1的模式来查表替换。
所以按你说的jm(x)=md5(y,16)  已知y ;求x

第一步、求出md5(y,16),设结果为字符串A。
第二步、取A中的每一位按jm里面的表反查表替换。比如A是:“16eqg”
第一位是"1",按照jm=replace(jm,"zm$","1"),那么"1"对应的就是"zm"
如此继续,对应A= “16eqg”的时候,x="zmerg52717"
2010-4-8 18:50
0
雪    币: 67
活跃值: (30)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
参考一下。jmr为jm的逆函数。
输入:m=123456
输出:
jm(m)=12x56
jmr(jm(m))=zmeh34kier
jm(jmr(m))=123456
输入:m=zmeh34kier
输出:
jm(m)=12x56
jmr(jm(m))=zmeh34kier
jm(jmr(m))=zmeh34kier

简单分析的结论:
1.jm不是一个单射函数
2.jm限制在一个子空间上就是个双射。这个子空间应该是由table(见下面的代码)的key生成。
3.根据jm(x)=y计算x是容易的。

#include <stdio.h>
#include <string.h>


struct node{
    char key[3];
    char value[2];
};

struct node table[] = {
    {"aa", "z"},
    {"ag", "y"},

    {"34", "x"},
    {"33", "w"},
    {"32", "v"},
    {"31", "u"},
    {"30", "t"},
    {"29", "s"},
    {"28", "r"},
    {"27", "q"},
    {"26", "p"},
    {"25", "o"},
    {"24", "n"},
    {"23", "m"},
    {"22", "l"},
    {"21", "k"},
    {"20", "j"},
    {"19", "i"},
    {"18", "h"},
    {"17", "g"},

    {"j6", "f"},
    {"g5", "e"},
    {"3e", "d"},
    {"cv", "c"},
    {"ni", "b"},
    {"df", "a"},
    {"p8", "."},
    {"o7", "_"},
    {"h9", "9"},
    {"r8", "8"},
    {"w2", "7"},
    {"er", "6"},
    {"ki", "5"},
    {"ba", "4"},
    {"mi", "3"},
    {"eh", "2"},
    {"zm", "1"},
    {"lx", "0"},
};

char *jm(char *m)
{
    static char *buffer = NULL;
    static int num = sizeof(table) / sizeof(table[0]);

    char *def = "123456";
    char *str;    
    char one[3];

    if(m == NULL || strlen(m) == 0)
    {
        str = def;
    } else {
        str = m;
    }
    int zf = strlen(str);
    int p = 0;
    if(buffer != NULL) delete buffer;
    buffer = new char[zf + zf / 2 + 1];
    
    int i, j;
    for(i = 1; i <= zf/2; i++)
    {
        one[0] = str[2 * i - 2];
        one[1] = str[2 * i - 1];
        one[2] = 0;
        for(j = 0; j < num; j++)
        {
            if(strcmp(one, table[j].key) == 0)
            {
                buffer[p++] = table[j].value[0];
                break;
            }
        }    
        if(j >= num)
        {
            buffer[p++] = one[0];
            buffer[p++] = one[1];
        }
    }
    buffer[p] = 0;
    return buffer;
}

char *jmr(char *m)
{
    static char *buffer = NULL;
    static int num = sizeof(table) / sizeof(table[0]);
    int i, j;
    int zf = strlen(m);    
    if(buffer != NULL) delete buffer;
    buffer = new char[zf * 2 + 1];
    memset(buffer, 0, zf * 2 + 1);
    for(i = 0; i < zf; i++)
    {
        for(j = 0; j < num; j++)
        {
            if(m[i] == table[j].value[0])
            {
                strcat(buffer, table[j].key);
            }
        }
    }

    return buffer;
}

int main()
{
    char m[1024];    
    while(scanf("%s", m) != EOF)
    {
        printf("%s\n", jm(m));
        printf("%s\n", jmr(jm(m)));
        printf("%s\n", jm(jmr(m)));
    }
    return 0;
}
2010-4-8 19:44
0
雪    币: 423
活跃值: (20)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
谢谢大家的帮助哦!已经写好注册机了!呵呵!
上传的附件:
2010-4-8 21:15
0
游客
登录 | 注册 方可回帖
返回
//