c - 将函数分配给 packetbuf_copyfrom

标签 c contiki

我想将函数分配给packetbuf_copyfrom()。我使用了 *& 但它在转换后没有给我正确的密码。

这是函数:

void caesar (char cipher[], int shift) {
    int i = 0;
    while (cipher[i] != '\0') {
        cipher[i] += (shift);
        i++;
    }
    printf("%s\n", cipher);
}

{
  char cipher[10]="Hello";
    int key = 5;
    caesar (cipher, key);   
    packetbuf_copyfrom((*caesar),8);

}

我想要 packet_copyfrom() 函数从函数 caesar 复制。

我应该做什么?

最佳答案

首先,凯撒密码公式为

enter image description here

所以你的代码可能是:

cipher[i] = (cipher[i] - 'a' + shift)%26 + 'a'; // for input is lower case and output is lower case.

其次,应用公式时应考虑字符大小写。您想要全部大写还是小写?只要确保您的编码和解码一致即可。

第三,将cipher传递给packetbuf_copyfrom

packetbuf_copyfrom(&cipher[0],8);

关于c - 将函数分配给 packetbuf_copyfrom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22028714/

相关文章:

c - setjmp/longjmp 失败

c - 如何在 Contiki 中启动多个进程来创建 CPU 负载

c - 如果在待发送期间有传入数据包,packetbuf 如何在 ContikiOS 中工作?

C-错误 : unknown type name ‘FILE’ on Zolertia z1 motes

c - 无法在 contiki 中导入 "time.h"

c - TFTP 客户端(基于 ENET)无法连接到远程 TFTP 服务器

c++ - ((int) 和 (int(a)) 之间有什么区别?

c++ - 绑定(bind)失败 : Bad file descriptor

c -/usr/include/linux 和/usr/include/x86_64-linux-gnu/有什么区别

Contiki 中的 CCM* 测试