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


以下是一个使用 Python 实现普莱费尔格密码加密的示例代码: ```python import string def generate_matrix(key): # 去除重复字母并将字母转换为大写 key = ''.join(dict.fromkeys(key.upper())) alphabet = string.ascii_uppercase matrix = [] for char in key: if char not in matrix: matrix.append(char) for char in alphabet: if char not in matrix: matrix.append(char) return [matrix[i:i + 5] for i in range(0, 25, 5)] def find_pos(matrix, char): for i in range(5): for j in range(5): if matrix[i][j] == char: return i, j def encrypt(plaintext, key): matrix = generate_matrix(key) plaintext = plaintext.replace(" ", "").upper() ciphertext = "" i = 0 while i < len(plaintext): char1 = plaintext[i] if i + 1 == len(plaintext): char2 = 'X' else: char2 = plaintext[i + 1] if char1 == char2: char2 = 'X' i += 1 row1, col1 = find_pos(matrix, char1) row2, col2 = find_pos(matrix, char2) if row1 == row2: ciphertext += matrix[row1][(col1 + 1) % 5] ciphertext += matrix[row2][(col2 + 1) % 5] elif col1 == col2: ciphertext += matrix[(row1 + 1) % 5][col1] ciphertext += matrix[(row2 + 1) % 5][col2] else: ciphertext += matrix[row1][col2] ciphertext += matrix[row2][col1] i += 2 return ciphertext key = "NETWORK" plaintext = "we will have a meeting" ciphertext = encrypt(plaintext, key) print("密文:", ciphertext) ``` [2024-09-24 18:40:04 | AI写代码神器 | 513点数解答]
- 普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文(276点数解答 | 2024-09-24 18:36:35)148
- 用c语言写代码普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文(788点数解答 | 2024-09-24 18:38:13)159
- 用python写代码普莱费尔格密码,密钥(network),明文(we will have a meeting),计算密文(513点数解答 | 2024-09-24 18:40:04)281
- 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)292
- 使用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)341
- 分析下面代码的每一行命令,并解释其过程: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)115
- c:\python\venv\zzz\scripts\python.exe c:\python\main.py traceback (most recent call last): file "c:\users\意\appdata\local\programs\python\python311\lib\site-packages\urllib3\connection.py", line 199, in _new_conn sock = connection.create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ file "c:\users\意\appdata\local\programs\python\python311\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection raise err file "c:\users\意\appdata\local\programs\python\pyt(161点数解答 | 2024-10-31 00:39:36)240
- 分析一下这段代码: // __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)199
- 分析一下这段 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)180
- 分析一下这段代码(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)252
- // __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)125
- // __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)159