免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4783 | 回复: 10
打印 上一主题 下一主题

[C] 形参不能传递值给实参,为何? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-10-19 10:15 |只看该作者 |倒序浏览
#define DECRYPT 0x00
#define ENCRYPT 0x01
#include <string.h>
#include "stdio.h"
/*****************************************************************************/
void qq_decipher(unsigned long *const v, const unsigned long *const k, unsigned long *const w)
{
        register unsigned long y = ntohl(v[0]), z = ntohl(v[1]), a = ntohl(k[0]), b = ntohl(k[1]), c = ntohl(k[2]), d = ntohl(k[3]), n = 0x10, sum = 0xE3779B90,        // why this ? must be related with n value
            delta = 0x9E3779B9;

        /* sum = delta<<5, in general sum = delta * n */
        while (n-- > 0) {
                z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
                y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);
                sum -= delta;
        }

        w[0] = htonl(y);
        w[1] = htonl(z);
}                                // qq_decipher

int qq_decrypt(unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr)
{
        unsigned char decrypted[8], m[8], *crypt_buff, *crypt_buff_pre_8, *outp;
        int count, context_start, pos_in_byte, padding;

        int decrypt_every_8_byte(void) {
                for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte++) {
                        if (context_start + pos_in_byte >= instrlen)
                                return 1;
                        decrypted[pos_in_byte] ^= crypt_buff[pos_in_byte];
                }
    这里      qq_decipher((unsigned long *) decrypted, (unsigned long *) key, (unsigned long *) decrypted);

                context_start += 8;
                crypt_buff += 8;
                pos_in_byte = 0;
                return 1;
        }                        // decrypt_every_8_byte

        // at least 16 bytes and %8 == 0
        if ((instrlen % || (instrlen < 16))
                return 0;
        // get information from header
        qq_decipher((unsigned long *) instr, (unsigned long *) key, (unsigned long *) decrypted);
        pos_in_byte = decrypted[0] & 0x7;
        count = instrlen - pos_in_byte - 10;        // this is the plaintext length
        // return if outstr buffer is not large enought or error plaintext length
        if (*outstrlen_ptr < count || count < 0)
                return 0;

        memset(m, 0, ;
        crypt_buff_pre_8 = m;
        *outstrlen_ptr = count;        // everything is ok! set return string length

        crypt_buff = instr + 8;        // address of real data start
        context_start = 8;        // context is at the second 8 byte
        pos_in_byte++;                // start of paddng stuff

        padding = 1;                // at least one in header
        while (padding <= 2) {        // there are 2 byte padding stuff in header
                if (pos_in_byte < {        // bypass the padding stuff, none sense data
                        pos_in_byte++;
                        padding++;
                }
                if (pos_in_byte == {
                        crypt_buff_pre_8 = instr;
                        if (!decrypt_every_8_byte())
                                return 0;
                }
        }                        // while

        outp = outstr;
        while (count != 0) {
                if (pos_in_byte < {
                        *outp = crypt_buff_pre_8[pos_in_byte] ^ decrypted[pos_in_byte];
                        outp++;
                        count--;
                        pos_in_byte++;
                }
                if (pos_in_byte == {
                        crypt_buff_pre_8 = crypt_buff - 8;
                        if (!decrypt_every_8_byte())
                                return 0;
                }
        }                        // while

        for (padding = 1; padding < 8; padding++) {
                if (pos_in_byte < {
                        if (crypt_buff_pre_8[pos_in_byte] ^ decrypted[pos_in_byte])
                                return 0;
                        pos_in_byte++;
                }
                if (pos_in_byte == {
                        crypt_buff_pre_8 = crypt_buff;
                        if (!decrypt_every_8_byte())
                                return 0;
                }
        }                        // for
        return 1;
}                                // qq_decrypt

int qq_crypt(unsigned char flag,
             unsigned char *instr, int instrlen, unsigned char *key, unsigned char *outstr, int *outstrlen_ptr)
{

        return qq_decrypt(instr, instrlen, key, outstr, outstrlen_ptr);

        return 1;                // flag must be DECRYPT or ENCRYPT
}                                // qq_crypt


int main(){
unsigned long v[4]={0x4fb5bfcc,0x959b2ad7,0x29dc3e6b,0xb7e3e3c7};

unsigned long k[4]={0xd7877ef4,0x2e9e2677,0x76941e42,0x3c0f81d6};

unsigned long out[4]={6};
int outstr_len_ptr=16;

printf("%d \n",qq_crypt(DECRYPT,(unsigned char *)v,16,(unsigned char *)k,(unsigned char *)out,&outstr_len_ptr));
printf("OUT=%lx%lx %lx%lx\n",out[0],out[1],out[2],out[3]);
return 0;
}



45行,decrypted数组以实参传递给qq_decipher函数,decrypted数组的值却没有改变!
        w[0] = htonl(y);
        w[1] = htonl(z);
这两句没有传回去?

[ 本帖最后由 daschina 于 2008-10-19 10:28 编辑 ]

论坛徽章:
1
CU十二周年纪念徽章
日期:2013-10-24 15:41:34
2 [报告]
发表于 2008-10-19 10:24 |只看该作者
没看到你qq_decipher函数有返回值啊????

论坛徽章:
0
3 [报告]
发表于 2008-10-19 15:10 |只看该作者
来人啦。。。。。。。

论坛徽章:
0
4 [报告]
发表于 2008-10-19 18:57 |只看该作者
unsigned long * 和 unsigned char * 之间转来转去的,为什么呀?

论坛徽章:
3
天蝎座
日期:2014-10-25 13:44:312015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:48:31
5 [报告]
发表于 2008-10-19 19:25 |只看该作者
你这个代码是写来玩的,还是靠这个代码混饭吃啊?

        int decrypt_every_8_byte(void) {
                for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte++) {
                        if (context_start + pos_in_byte >= instrlen)
                                return 1;
                        decrypted[pos_in_byte] ^= crypt_buff[pos_in_byte];
                }
    这里      qq_decipher((unsigned long *) decrypted, (unsigned long *) key, (unsigned long *) decrypted);

                context_start += 8;
                crypt_buff += 8;
                pos_in_byte = 0;
                return 1;
        }                        // decrypt_every_8_byte


——这个函数怎么在这个位置啊?不懂;


而且:
context_start都没初始化吧?

[ 本帖最后由 ilex 于 2008-10-19 19:26 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2008-10-19 20:10 |只看该作者
原帖由 ilex 于 2008-10-19 19:25 发表
你这个代码是写来玩的,还是靠这个代码混饭吃啊?

        int decrypt_every_8_byte(void) {
                for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte++) {
                        if (co ...



前面都是函数定义阿大哥!

从main里面调用,你先看main

论坛徽章:
3
天蝎座
日期:2014-10-25 13:44:312015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:48:31
7 [报告]
发表于 2008-10-19 20:59 |只看该作者
原帖由 daschina 于 2008-10-19 20:10 发表



前面都是函数定义阿大哥!

从main里面调用,你先看main



莫非C++可以把函数定义放在另一个函数里面(我几乎不会C++)

论坛徽章:
0
8 [报告]
发表于 2008-10-19 22:06 |只看该作者

回复 #7 ilex 的帖子

unsigned char decrypted[8], m[8], *crypt_buff, *crypt_buff_pre_8, *outp;
        int count, context_start, pos_in_byte, padding;

        int decrypt_every_8_byte(void) {
                for (pos_in_byte = 0; pos_in_byte < 8; pos_in_byte++) {
                        if (context_start + pos_in_byte >= instrlen)
                                return 1;
                        decrypted[pos_in_byte] ^= crypt_buff[pos_in_byte];
                }
    这里      qq_decipher((unsigned long *) decrypted, (unsigned long *) key, (unsigned long *) decrypted);

                context_start += 8;
                crypt_buff += 8;
                pos_in_byte = 0;
                return 1;
        }                        // decrypt_every_8_byte

        // at least 16 bytes and %8 == 0


函数实现里面还有另一个函数的实现,晕了。

论坛徽章:
0
9 [报告]
发表于 2008-10-19 22:15 |只看该作者
看完你的代码就够累的了!!!

论坛徽章:
0
10 [报告]
发表于 2008-10-19 22:16 |只看该作者
看得有点头晕了,函数定义里面居然还有函数定义。

这是啥语言啊

知道的给说说啊
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP