用c语言写代码普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文


以下是使用 C 语言实现普莱费尔格密码加密的示例代码: ```c #include <stdio.h> #include <string.h> // 定义一个 5x5 的矩阵来表示密码表 char table[5][5]; // 初始化密码表 void initTable(char *key) { int used[26] = {0}; int i, j, k = 0; // 先填充密钥 for (i = 0; key[i]!= '\0'; i++) { if (key[i] == 'j') { key[i] = 'i'; } if (!used[key[i] - 'a']) { table[k / 5][k % 5] = key[i]; used[key[i] - 'a'] = 1; k++; } } // 填充剩余字母 for (i = 0; i < 26; i++) { if (i + 'a'!= 'j' &&!used[i]) { table[k / 5][k % 5] = i + 'a'; k++; } } } // 查找字符在密码表中的位置 void findPosition(char c, int *row, int *col) { if (c == 'j') { c = 'i'; } for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (table[i][j] == c) { *row = i; *col = j; return; } } } } // 加密函数 void encrypt(char *plaintext, char *key) { initTable(key); int len = strlen(plaintext); int i = 0; while (i < len) { char c1 = plaintext[i]; char c2 = (i + 1 < len)? plaintext[i + 1] : 'x'; int row1, col1, row2, col2; findPosition(c1, &row1, &col1); findPosition(c2, &row2, &col2); if (row1 == row2) { plaintext[i] = table[row1][(col1 + 1) % 5]; plaintext[i + 1] = table[row2][(col2 + 1) % 5]; } else if (col1 == col2) { plaintext[i] = table[(row1 + 1) % 5][col1]; plaintext[i + 1] = table[(row2 + 1) % 5][col2]; } else { plaintext[i] = table[row1][col2]; plaintext[i + 1] = table[row2][col1]; } i += 2; } } int main() { char plaintext[] = "we will have a meeting"; char key[] = "network"; encrypt(plaintext, key); printf("密文: %s\n", plaintext); return 0; } ``` 这段代码实现了普莱费尔格密码的加密过程,首先根据密钥初始化密码表,然后对明文进行分组加密。 [2024-09-24 18:38:13 | AI写代码神器 | 788点数解答]
- 普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文(276点数解答 | 2024-09-24 18:36:35)166
- 用c语言写代码普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文(788点数解答 | 2024-09-24 18:38:13)176
- 用python写代码普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文(513点数解答 | 2024-09-24 18:40:04)298
- 7-1 句子反转 分数 30 作者 陈宇璟 单位 浙江大学 给定一行句子,每个词之间用空格隔开,要么是全小写英文单词,要么是全大写英文单词,要么是自然数。 要求将这些单词倒序输出。而且对于每个单词,如果是小写词,应当转为大写;如果是大写词,应当转为小写;如果是自然数,应该倒转输出。 举一个例子: we choose to go 2 the 123 moon 程序应当输出: moon 321 the 2 go to choose we 输入格式 仅一行,即需要反转的句子。 输出格式 仅一行,表示程序对句子的处理结果。 说明/提示 样例解释 首先应当按单词逆序,即: moon 123 the 2 go to choose we 小写变大写、大写变小写、倒转自然数之后,得到最终结果: moon 321 the 2 go to choose we 数据规模与约定 对于 100% 的数据,句子中包含的单词数量不超过 1000,每个单词长度不超过 6。 输入样例: we choose to go 2 the 123 moon 输出样例: moon 321 the 2 go to(131点数解答 | 2024-11-11 16:44:49)325
- 使用c| 7-1 句子反转 分数 30 作者 陈宇璟 单位 浙江大学 给定一行句子,每个词之间用空格隔开,要么是全小写英文单词,要么是全大写英文单词,要么是自然数。 要求将这些单词倒序输出。而且对于每个单词,如果是小写词,应当转为大写;如果是大写词,应当转为小写;如果是自然数,应该倒转输出。 举一个例子: we choose to go 2 the 123 moon 程序应当输出: moon 321 the 2 go to choose we 输入格式 仅一行,即需要反转的句子。 输出格式 仅一行,表示程序对句子的处理结果。 说明/提示 样例解释 首先应当按单词逆序,即: moon 123 the 2 go to choose we 小写变大写、大写变小写、倒转自然数之后,得到最终结果: moon 321 the 2 go to choose we 数据规模与约定 对于 100% 的数据,句子中包含的单词数量不超过 1000,每个单词长度不超过 6。 输入样例: we choose to go 2 the 123 moon 输出样例: moon 321 the 2(393点数解答 | 2024-11-11 16:45:21)437
- 分析下面代码的每一行命令,并解释其过程:import geopandas as gpd import networkx as nx # 禁用 pygeos 加速 gpd.options.use_pygeos = false # 读取路网数据和地级市数据 roads_path = 'g:/fisheries_products/network.gdb' # 路网数据路径 cities_path = 'g:/fisheries_products/network.gdb' # 地级市数据路径 # 读取数据 roads_gdf = gpd.read_file(roads_path, layer='roadmerge') # 路网数据 cities_gdf = gpd.read_file(cities_path, layer='city') # 地级市数据 # 创建路网图 g = nx.graph() # 添加边到图中 for _, row in roads_gdf.iterrows(): geom = row['geometry'] if geom.type =(421点数解答 | 2024-10-28 21:34:54)135
- 分析一下这段代码: // __multiversion__ // this signals the loading code to prepend either #version 100 or #version 300 es as apropriate. // to use centroid sampling we need to have version 300 es shaders, which requires changing: // attribute to in // varying to out when in vertex shaders or in when in fragment shaders // defining an out vec4 fragcolor and replacing uses of gl_fragcolor with fragcolor // texture2d to texture #if __version__ >= 300 #define attribute in #define varying out #ifdef msaa_fr(260点数解答 | 2024-10-19 19:42:17)219
- 分析一下这段 opengl vertex的代码: // __multiversion__ // this signals the loading code to prepend either #version 100 or #version 300 es as apropriate. // to use centroid sampling we need to have version 300 es shaders, which requires changing: // attribute to in // varying to out when in vertex shaders or in when in fragment shaders // defining an out vec4 fragcolor and replacing uses of gl_fragcolor with fragcolor // texture2d to texture #if __version__ >= 300 #define attribute in #define varying out(191点数解答 | 2024-10-19 19:43:44)203
- 分析一下这段代码(vertex着色器): // __multiversion__ // this signals the loading code to prepend either #version 100 or #version 300 es as apropriate. // to use centroid sampling we need to have version 300 es shaders, which requires changing: // attribute to in // varying to out when in vertex shaders or in when in fragment shaders // defining an out vec4 fragcolor and replacing uses of gl_fragcolor with fragcolor // texture2d to texture #if __version__ >= 300 #define attribute in #define varying out #if(223点数解答 | 2024-10-19 19:50:37)274
- // __multiversion__ // this signals the loading code to prepend either #version 100 or #version 300 es as apropriate. // to use centroid sampling we need to have version 300 es shaders, which requires changing: // attribute to in // varying to out when in vertex shaders or in when in fragment shaders // defining an out vec4 fragcolor and replacing uses of gl_fragcolor with fragcolor // texture2d to texture #if __version__ >= 300 // version 300 code #define varying in #define texture2d texture(45点数解答 | 2024-12-14 17:33:30)145
- // __multiversion__ // this signals the loading code to prepend either #version 100 or #version 300 es as apropriate. // to use centroid sampling we need to have version 300 es shaders, which requires changing: // attribute to in // varying to out when in vertex shaders or in when in fragment shaders // defining an out vec4 fragcolor and replacing uses of gl_fragcolor with fragcolor // texture2d to texture #if __version__ >= 300 // version 300 code #define varying in #define texture2d texture(356点数解答 | 2024-12-14 17:34:20)179
- // __multiversion__ // this signals the loading code to prepend either #version 100 or #version 300 es as apropriate. // to use centroid sampling we need to have version 300 es shaders, which requires changing: // attribute to in // varying to out when in vertex shaders or in when in fragment shaders // defining an out vec4 fragcolor and replacing uses of gl_fragcolor with fragcolor // texture2d to texture #if __version__ >= 300 // version 300 code #define varying in #define texture2d texture(111点数解答 | 2024-12-14 17:34:20)197