曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 4514|回复: 0
打印 上一主题 下一主题

[字符串] memfrob() -- 简单加密内存区内容

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2011-12-21 15:38:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
memfrob() 函数原型如下:
[C++] 纯文本查看 复制代码
#include <string.h>
void *memfrob(void *s, size_t n);

该函数将 s 指向的内存空间的前 n 个字符逐一与 42 做 XOR 运算,用途是可以隐藏一个特定字符串的内容,如果需要还原,那么就再对 42 做一次 XOR 运算即可。该函数为 GNU C 所独有。

测试代码
[C++] 纯文本查看 复制代码
#include <stdio.h>
#include <string.h>

int main()
{
        char my[] = "This is my secret^_^";

        printf ("you can see it: %s\n", my);

        memfrob(my, strlen(my));

        printf ("is it my secret? : %s\n", my);

        printf ("restore it.......\n");

        memfrob(my, strlen(my));

        printf ("you can see it again: %s\n", my);

        return 0;
}

运行输出:
./memfrob
you can see it: This is my secret^_^
is it my secret? : ~BCY
CY
GS
YOIXO^tut
restore it.......
you can see it again: This is my secret^_^
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-6 12:57 , Processed in 0.082012 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表