曲径通幽论坛

标题: memfrob() -- 简单加密内存区内容 [打印本页]

作者: beyes    时间: 2011-12-21 15:38
标题: memfrob() -- 简单加密内存区内容
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^_^





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2