C语言实现RSA算法加解密

使用c语言实现了RSA加解密算法,可以加解密文件和字符串。

rsa算法原理
  • 选择两个大素数p和q;
  • 计算n = p * q;
  • 计算φ(n)=(p-1)(q-1);
  • 选择与φ(n)互素的整数d;
  • 由de=1 mod φ(n)计算得到e;
  • 公钥是(e, n), 私钥是(d, n);
  • 假设明文是M(一个整数),则密文C =  mod n,此为加密过程;
  • 解密过程为M =  mod n;
rsa.h
#pragma once
#include <iostream>
#include <fstream>
#include <tommath.h>
#include <time.h>
#include <Windows.h>
#include <string>#define SUBKEY_LENGTH 78  //  >512 bit#define FILE_NAME_LENGTH 99#define PLAINTEXT_LENGTH 64#define BINARY_LENGTH 512using namespace std;void initial();int Get_char_bit(char c, int pos);void Create_prime_number(mp_int *number);void Generate_key(char *key_name);void Write_key_2_File(char *file_name, mp_int *key, mp_int *n);void ADD_0(char *binary, int mode);void rsa_decrypt(char *src, char *dst, char *key_name, int mode);void rsa_encrypt(char *src, char *dst, char *key_name, int mode);void mp_print(mp_int *number);void Get_key_from_file(mp_int *key, mp_int *n, char *key_name, int mode);void Create_number(mp_int *number, int mode);int Miller_rabin(mp_int *number);void Char_2_binary(char *text, char *binary, int len);void Binary_2_char(char *binary, char *text, int binary_len);void quick_pow(mp_int *a, mp_int *b, mp_int *c, mp_int *d);int Get_file_length(char *filename);
rsa.cpp
#include "rsa.h"mp_int two;
mp_int five;
mp_int zero;
mp_int one;int Get_char_bit(char c, int pos)
{return ((c >> (7 - pos)) & 1);
}// mode 0: number of n digits
// mode 1: 2 <= number <= n - 2  for miller rabin test
void Create_number(mp_int *number, int mode)
{int i;srand((unsigned)time(NULL));char temp_number[SUBKEY_LENGTH + 1];temp_number[0] = rand() % 9 + 1 + 48;if (0 == mode){int temp;for (i = 1; i <= SUBKEY_LENGTH - 2; i++)temp_number[i] = rand() % 10 + 48;temp = rand() % 10;if (0 == temp % 2)temp++;if (5 == temp)temp = 7;temp_number[SUBKEY_LENGTH - 1] = temp + 48;temp_number[SUBKEY_LENGTH] = '\0';}else if (1 == mode){int digit = rand() % (SUBKEY_LENGTH - 2) + 2;for (i = 1; i <= digit - 1; i++)temp_number[i] = rand() % 10 + 48;temp_number[digit] = '\0';}mp_read_radix(number, temp_number, 10);
}int Miller_rabin(mp_int *number)
{int result;mp_int base;mp_init_size(&base, SUBKEY_LENGTH);Create_number(&base, 1);mp_prime_miller_rabin(number, &base, &result);mp_clear(&base);return result;
}void Create_prime_number(mp_int *number)
{mp_int r;mp_init(&r);int time = 100;int result;int i;Create_number(number, 0);while (1){mp_prime_is_divisible(number, &result);if (0 != result){do{mp_add(number, &two, number);mp_mod(number, &five, &r);} while (MP_EQ == mp_cmp_mag(&zero, &r));continue;}for (i = 0; i < time; i++){if (!Miller_rabin(number))break;}if (i == time)return;else{do{mp_add(number, &two, number);mp_mod(number, &five, &r);} while (MP_EQ == mp_cmp_mag(&zero, &r));}}
}void Generate_key(char *key_name)
{mp_int p, q, n, f, e, d;mp_init_size(&p, SUBKEY_LENGTH);mp_init_size(&q, SUBKEY_LENGTH);mp_init_size(&n, SUBKEY_LENGTH * 2);mp_init_size(&f, SUBKEY_LENGTH * 2);mp_init_size(&d, SUBKEY_LENGTH * 2);mp_init_size(&e, SUBKEY_LENGTH * 2);Create_prime_number(&p);Sleep(1000);Create_prime_number(&q);mp_mul(&p, &q, &n);mp_sub(&p, &one, &p);mp_sub(&q, &one, &q);mp_mul(&p, &q, &f);mp_set_int(&d, 127);mp_int gcd;mp_init_size(&gcd, SUBKEY_LENGTH * 2);do{mp_add(&d, &two, &d);mp_gcd(&d, &f, &gcd);} while (MP_EQ != mp_cmp_mag(&gcd, &one));mp_invmod(&d, &f, &e);char PUBLIC_KEY[FILE_NAME_LENGTH] = "d:\\public_key_";char PRIVATE_KEY[FILE_NAME_LENGTH] = "d:\\private_key_";strcat(PUBLIC_KEY, key_name);strcat(PRIVATE_KEY, key_name);Write_key_2_File(PUBLIC_KEY, &d, &n);Write_key_2_File(PRIVATE_KEY, &e, &n);mp_clear_multi(&p, &q, &e, &d, &f, &n, &gcd, NULL);
}void initial()
{mp_init_set_int(&two, 2);mp_init_set_int(&five, 5);mp_init_set_int(&zero, 0);mp_init_set_int(&one, 1);
}void Write_key_2_File(char *file_name, mp_int *key, mp_int *n)
{remove(file_name);FILE *fp = fopen(file_name, "w+");if (NULL == fp){cout << "open file error!" << endl;return;}char key_str[SUBKEY_LENGTH * 2 + 1];char n_str[SUBKEY_LENGTH * 2 + 1];mp_toradix(key, key_str, 10);mp_toradix(n, n_str, 10);fprintf(fp, "%s\n", n_str);fprintf(fp, "%s", key_str);fclose(fp);
}void mp_print(mp_int *number)
{char str[SUBKEY_LENGTH * 2 + 1];mp_toradix(number, str, 10);cout << str << endl;
}// mode 0: get public key
// mode 1: get private keyvoid Get_key_from_file(mp_int *key, mp_int *n, char *key_name, int mode)
{FILE *fp = NULL;char PUBLIC_KEY[FILE_NAME_LENGTH] = "";char PRIVATE_KEY[FILE_NAME_LENGTH] = "";if (0 == mode){strcat(PUBLIC_KEY, key_name);fp = fopen(PUBLIC_KEY, "r+");}else if (1 == mode){strcat(PRIVATE_KEY, key_name);fp = fopen(PRIVATE_KEY, "r+");}if (NULL == fp){cout << "open file error!" << endl;return;}char key_str[SUBKEY_LENGTH * 2 + 1];char n_str[SUBKEY_LENGTH * 2 + 1];fscanf(fp, "%s\n", n_str);fscanf(fp, "%s", key_str);mp_read_radix(n, n_str, 10);mp_read_radix(key, key_str, 10);fclose(fp);
}void Char_2_binary(char *text, char *binary, int len)
{int i;int j;int k = 0;for (i = 0; i <= len - 1; i++){for (j = 0; j <= 7; j++)binary[k++] = Get_char_bit(text[i], j) + '0';}binary[k] = '\0';
}void Binary_2_char(char *binary, char *text, int binary_len)
{int i;int j = 0;int k = 0;int sum = 0;for (i = 0; i <= binary_len - 1; i++){sum = sum + pow(2, 7 - j)*(int)((binary[i]) - '0');j++;if (8 == j){text[k++] = sum;sum = 0;j = 0;}}
}// mode 0: encrypt char*
// mode 1: encrypt file
void rsa_encrypt(char *src, char *dst, char *key_name, int mode)
{mp_int n;mp_int public_key;mp_int plain_number;mp_int cipher_number;mp_init_size(&n, SUBKEY_LENGTH * 2);mp_init_size(&public_key, SUBKEY_LENGTH * 2);mp_init_size(&plain_number, SUBKEY_LENGTH * 2);mp_init_size(&cipher_number, SUBKEY_LENGTH * 2);Get_key_from_file(&public_key, &n, key_name, 0);char plain_text[PLAINTEXT_LENGTH + 1];char cipher_text[PLAINTEXT_LENGTH + 2];char plain_binary[BINARY_LENGTH + 1];char cipher_binary[BINARY_LENGTH + 9];int i;int j;int k;int l;if (0 == mode){int round = ceil(strlen(src) / 64.0);for (i = 0; i < round; i++){for (l = 0; l <= BINARY_LENGTH; l++)plain_binary[l] = '\0';for (l = 0; l <= BINARY_LENGTH + 8; l++)cipher_binary[l] = '\0';for (l = 0; l <= PLAINTEXT_LENGTH; l++)plain_text[l] = '\0';for (l = 0; l <= PLAINTEXT_LENGTH + 1; l++)cipher_text[l] = '\0';for (j = 0; j <= PLAINTEXT_LENGTH - 1; j++){plain_text[j] = src[i * PLAINTEXT_LENGTH + j];if ('\0' == plain_text[j]){for (k = j + 1; k <= PLAINTEXT_LENGTH - 1; k++)plain_text[k] = '\0';break;}}plain_text[PLAINTEXT_LENGTH] = '\0';Char_2_binary(plain_text, plain_binary, PLAINTEXT_LENGTH);mp_zero(&plain_number);mp_read_radix(&plain_number, plain_binary, 2);mp_zero(&cipher_number);// ----------------------------------------------------------------mp_exptmod(&plain_number, &public_key, &n, &cipher_number);//quick_pow(&plain_number, &public_key, &n, &cipher_number);// ----------------------------------------------------------------mp_toradix(&cipher_number, cipher_binary, 2);ADD_0(cipher_binary, 0);Binary_2_char(cipher_binary, cipher_text, BINARY_LENGTH + 8);for (l = 0; l <= PLAINTEXT_LENGTH; l++)dst[i*(PLAINTEXT_LENGTH + 1) + l] = cipher_text[l];}dst[round * (PLAINTEXT_LENGTH + 1)] = '\0';mp_clear_multi(&n, &public_key, &plain_number, &cipher_number, NULL);}else if (1 == mode){ifstream fin;ofstream fout;fin.open(src, ios::binary);fout.open(dst, ios::binary);char ch;int i = 0;int len = Get_file_length(src) % 64;fout << len << endl;while (1){fin.get(ch);plain_text[i++] = ch;if (i == PLAINTEXT_LENGTH || fin.eof()){if (i == PLAINTEXT_LENGTH)plain_text[i] = '\0';else{for (k = i - 1; k <= PLAINTEXT_LENGTH; k++)plain_text[k] = '\0';}for (l = 0; l <= BINARY_LENGTH; l++)plain_binary[l] = '\0';for (l = 0; l <= BINARY_LENGTH + 8; l++)cipher_binary[l] = '\0';for (l = 0; l <= PLAINTEXT_LENGTH + 1; l++)cipher_text[l] = '\0';Char_2_binary(plain_text, plain_binary, PLAINTEXT_LENGTH);mp_zero(&plain_number);mp_read_radix(&plain_number, plain_binary, 2);mp_zero(&cipher_number);// ----------------------------------------------------------------mp_exptmod(&plain_number, &public_key, &n, &cipher_number);//quick_pow(&plain_number, &public_key, &n, &cipher_number);// ----------------------------------------------------------------mp_toradix(&cipher_number, cipher_binary, 2);ADD_0(cipher_binary, 0);Binary_2_char(cipher_binary, cipher_text, BINARY_LENGTH + 8);for (l = 0; l <= PLAINTEXT_LENGTH; l++)fout << cipher_text[l];for (l = 0; l <= PLAINTEXT_LENGTH; l++)plain_text[l] = '\0';i = 0;}if (fin.eof())break;}fin.close();fout.close();mp_clear_multi(&n, &public_key, &plain_number, &cipher_number, NULL);}
}// mode 0: for encrypt
// mode 1: for decrypt
void ADD_0(char *binary, int mode)
{int i;int difference;if (0 == mode)difference = BINARY_LENGTH + 8 - strlen(binary);else if(1 == mode)difference = BINARY_LENGTH - strlen(binary);;for (i = strlen(binary); i >= 0; i--)binary[i + difference] = binary[i];for (i = 0; i < difference; i++)binary[i] = '0';
}// mode 0: decrypt char*
// mode 1: decrypt file
void rsa_decrypt(char *src, char *dst, char *key_name, int mode)
{mp_int n;mp_int private_key;mp_int plain_number;mp_int cipher_number;mp_init_size(&n, SUBKEY_LENGTH * 2);mp_init_size(&private_key, SUBKEY_LENGTH * 2);mp_init_size(&plain_number, SUBKEY_LENGTH * 2);mp_init_size(&cipher_number, SUBKEY_LENGTH * 2);Get_key_from_file(&private_key, &n, key_name, 1);char plain_text[PLAINTEXT_LENGTH + 1];char cipher_text[PLAINTEXT_LENGTH + 2];char plain_binary[BINARY_LENGTH + 1];char cipher_binary[BINARY_LENGTH + 9];int j;int k;int l;if (0 == mode){k = -1;do{k++;for (l = 0; l <= PLAINTEXT_LENGTH; l++)plain_text[l] = '\0';for (l = 0; l <= BINARY_LENGTH; l++)plain_binary[l] = '\0';for (l = 0; l <= BINARY_LENGTH + 8; l++)cipher_binary[l] = '\0';for (j = 0; j <= PLAINTEXT_LENGTH; j++)cipher_text[j] = src[k * (PLAINTEXT_LENGTH + 1) + j];cipher_text[PLAINTEXT_LENGTH + 1] = '\0';Char_2_binary(cipher_text, cipher_binary, PLAINTEXT_LENGTH + 1);mp_zero(&cipher_number);mp_read_radix(&cipher_number, cipher_binary, 2);mp_zero(&plain_number);// ----------------------------------------------------------------mp_exptmod(&cipher_number, &private_key, &n, &plain_number);//quick_pow(&cipher_number, &private_key, &n, &plain_number);// ----------------------------------------------------------------mp_toradix(&plain_number, plain_binary, 2);ADD_0(plain_binary, 1);Binary_2_char(plain_binary, plain_text, BINARY_LENGTH);for (l = 0; l <= PLAINTEXT_LENGTH - 1; l++) dst[k*PLAINTEXT_LENGTH + l] = plain_text[l];} while ('\0' != src[(k + 1)*(PLAINTEXT_LENGTH + 1)]);dst[(k + 1) * PLAINTEXT_LENGTH] = '\0';}else if (1 == mode){ifstream fin;ofstream fout;fin.open(src, ios::binary);fout.open(dst, ios::binary);int i = 0;int limit = PLAINTEXT_LENGTH;char ch;string temp = "";while (1){fin.get(ch);if ('\n' == ch)break;temp += ch;}int len = atoi(temp.c_str());while (1){fin.get(ch);cipher_text[i++] = ch;if (i == PLAINTEXT_LENGTH + 1){if (i == PLAINTEXT_LENGTH + 1) cipher_text[i] = '\0';elsecipher_text[i - 1] = '\0';for (l = 0; l <= BINARY_LENGTH + 8; l++)cipher_binary[l] = '\0';for (l = 0; l <= PLAINTEXT_LENGTH; l++)plain_text[l] = '\0';for (l = 0; l <= BINARY_LENGTH; l++)plain_binary[l] = '\0';Char_2_binary(cipher_text, cipher_binary, PLAINTEXT_LENGTH + 1);mp_zero(&cipher_number);mp_read_radix(&cipher_number, cipher_binary, 2);mp_zero(&plain_number);// ----------------------------------------------------------------mp_exptmod(&cipher_number, &private_key, &n, &plain_number);//quick_pow(&cipher_number, &private_key, &n, &plain_number);// ----------------------------------------------------------------mp_toradix(&plain_number, plain_binary, 2);ADD_0(plain_binary, 1);Binary_2_char(plain_binary, plain_text, BINARY_LENGTH);if (fin.peek() == EOF)limit = len;for (l = 0; l < limit; l++)fout << plain_text[l];for (l = 0; l <= PLAINTEXT_LENGTH + 1; l++)cipher_text[l] = '\0';i = 0;}if (fin.eof())break;}fin.close();fout.close();}mp_clear_multi(&n, &private_key, &plain_number, &cipher_number, NULL);
}// compute d = a ^ b (mod c)
void quick_pow(mp_int *a, mp_int *b, mp_int *c, mp_int *d)
{mp_int temp;mp_int temp_a;mp_int temp_b;mp_init_size(&temp, SUBKEY_LENGTH * 2);mp_init_size(&temp_a, SUBKEY_LENGTH * 2);mp_init_size(&temp_b, SUBKEY_LENGTH * 2);mp_copy(a, &temp_a);mp_copy(b, &temp_b);mp_set_int(d, 1);mp_mod(&temp_a, c, &temp_a);while (MP_GT == mp_cmp(&temp_b, &zero)){mp_mod(&temp_b, &two, &temp);if (MP_EQ == mp_cmp(&one, &temp)){mp_mul(d, &temp_a, d);mp_mod(d, c, d);}mp_div_2(&temp_b, &temp_b);mp_mul(&temp_a, &temp_a, &temp_a);mp_mod(&temp_a, c, &temp_a);}mp_clear_multi(&temp, &temp_a, &temp_b, NULL);
}int Get_file_length(char *filename) 
{FILE *fp = fopen(filename, "rb");if (NULL == fp)return -1;fseek(fp, 0, SEEK_END);int temp = ftell(fp);fclose(fp);return temp;
}
main.h
#pragma once
#include "rsa.h"
 main.cpp
#include "main.h"// example
void main()
{initial();// generate key belong to arg " "Generate_key("hello_world");// ----------------------example: encrypt char* ---------------------------char a[200] = "to_be_or_not_to_be_it_is_a_question";char b[400];char c[200];//rsa_encrypt(a, b, "hello_world", 0);//rsa_decrypt(b, c, "hello_world", 0);cout << "c: " << c << endl;// ------------------------------------------------------------------------// ----------------------example: encrypt file ----------------------------rsa_encrypt("d:\\a.gif", "d:\\m", "d:\\public_key_hello_world", 1);rsa_decrypt("d:\\m", "D:\\b.gif", "d:\\private_key_hello_world", 1);// ------------------------------------------------------------------------}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/228486.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

设计模式(4)--对象行为(11)--访问者

1. 意图 表示一个作用于某对象结构中的各元素的操作。 使你可以在不改变各元素的类的前提下定义于作用于这些元素的新操作。 2. 五种角色 抽象访问者(Visitor)、具体访问者(Concrete Visitor)、抽象元素(Element)、 具体元素(Concrete Element)、对象结构(ObjectStructure) 3…

12 HAL库的硬件SPI驱动数码管

引言&#xff1a; 本文将为大家介绍一下SPI&#xff0c; 数码管的知识&#xff0c; 以及HAL库驱动SPI接口的数码的代码示例。 一、SPI的基础知识 1. SPI简介 01 SPI是串行外设接口&#xff08;Serial Peripheral Interface&#xff09;的缩写 02 是美国摩托罗拉公司&#xff08…

【ARMv8M Cortex-M33 系列 2 -- Cortex-M33 JLink 连接 及 JFlash 烧写介绍】

请阅读【嵌入式开发学习必备专栏 之Cortex-M33 专栏】 文章目录 Jlink 工具JLink 命令行示例JFlash 烧写问题Jlink 工具 J-Link 是 SEGGER 提供的一款流行的 JTAG 调试器,它支持多个平台和处理器。JLink.exe 是 J-Link 调试器的命令行接口,它允许用户通过命令行执行一系列操…

微信小程序开发系列-11组件间通信02

微信小程序开发系列目录 《微信小程序开发系列-01创建一个最小的小程序项目》 《微信小程序开发系列-02注册小程序》 《微信小程序开发系列-03全局配置中的“window”和“tabBar”》 《微信小程序开发系列-04获取用户图像和昵称》 《微信小程序开发系列-05登录小程序》 《…

打破数据孤岛:ChatGPT如何打通金融大数据的任督二脉?

文章目录 一、引言二、ChatGPT与金融大数据分析的融合三、实践应用&#xff1a;ChatGPT在金融大数据分析中的优势与挑战四、案例分析&#xff1a;ChatGPT在金融大数据分析中的应用案例五、前景展望&#xff1a;ChatGPT在金融大数据分析领域的未来发展《AI时代Python金融大数据分…

[新版Hi3531DV200 性能强悍]

新版Hi3531DV200 性能强悍 Hi3531DV200是针对多路高清/超高清&#xff08;1080p/4M/5M/4K&#xff09;DVR产品应用开发的新一代专业SoC芯片。Hi3531DV200集成了ARM A53四核处理器和性能强大的神经网络推理引擎&#xff0c;支持多种智能算法应用。同时&#xff0c;Hi3531DV200还…

maven工具的搭建以及使用

文章目录 &#x1f412;个人主页&#x1f3c5;JavaEE系列专栏&#x1f4d6;前言&#xff1a;&#x1f380;首先进行maven工具的搭建&#x1f993;1.[打开下载 maven 服务器官网](http://maven.apache.org)&#x1fa85;2.解压之后&#xff0c;配置环境变量&#x1f3e8;3.打开设…

【SpringBoot开发】之商城项目案例(实现登陆版)

&#x1f389;&#x1f389;欢迎来到我的CSDN主页&#xff01;&#x1f389;&#x1f389; &#x1f3c5;我是君易--鑨&#xff0c;一个在CSDN分享笔记的博主。&#x1f4da;&#x1f4da; &#x1f31f;推荐给大家我的博客专栏《SpringBoot开发之商城项目系列》。&#x1f3af…

【Android Gradle 插件】Android Plugin DSL Reference 离线文档下载 ( GitHub 下载文档 | 查看文档 )

一、Android Plugin DSL Reference 文档下载 二、Android Plugin DSL Reference 文档查看 一、Android Plugin DSL Reference 文档下载 在之前的博客 【Android Gradle 插件】Android Plugin DSL Reference 文档介绍 ( 1.2 ~ 3.4 版本文档地址 | 4.1 ~ 7.1 版本文档地址 ) 中…

ffmpeg两种windows版本区别说明

版本一 必须拷贝exe和dll文件才能使用&#xff0c;如果缺少dll则exe不正正常执行 如果缺少dll &#xff0c;执行 exe会报错如下 版本2 直接拷贝exe就能使用&#xff0c;没有依赖的环境

uniapp实现前端银行卡隐藏中间的数字,及隐藏姓名后两位

Vue 实现前端银行卡隐藏中间的数字 主要应用了 filters过滤器 来实现效果 实现效果&#xff0c;如图&#xff1a; <template><div><div style"background-color: #f4f4f4;margin:50px 0 0 460px;width:900px;height:300px;"><p>原来&#…

Android 13 动态启用或禁用IPV6

介绍 客户想要通过APK来控制IPV6的启用和禁用&#xff0c;这里我们通过广播的方式来让客户控制IPV6。 效果展示 adb shell ifconfig 这里我们用debug软件&#xff0c;将下面节点置为1 如图ipv6已被禁用了 echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 修改 接下来…

老虎目标检测数据集VOC格式900张

老虎是地球上最为壮丽而令人敬畏的野生动物之一&#xff0c;是大型猫科动物中的一员。老虎通常具有强壮的体格和敏捷的身体机能&#xff0c;是世界上最顶级的掠食者之一。 老虎的外貌特征鲜明&#xff0c;身体长约2至3米&#xff0c;体重可达200至300公斤。它们的体型庞大&…

Kubernetes 学习总结(41)—— 云原生容器网络详解

背景 随着网络技术的发展&#xff0c;网络的虚拟化程度越来越高&#xff0c;特别是云原生网络&#xff0c;叠加了物理网络、虚机网络和容器网络&#xff0c;数据包在网络 OSI 七层网络模型、TCP/IP 五层网络模型的不同网络层进行封包、转发和解包。网络数据包跨主机网络、容器…

2023下半年的总结

我从八月下旬开始写的&#xff0c;到现在差不多有半年了&#xff0c;总结一下吧&#xff01; 1.计算机视觉 在计算机视觉方面&#xff0c;想必两个有名的深度学习框架&#xff08;TensorFlow和PyTorch&#xff09;大家都很清楚吧&#xff0c;以及OpenCV库。对于人脸识别&…

2024年【黑龙江省安全员C证】考试及黑龙江省安全员C证找解析

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 2024年黑龙江省安全员C证考试为正在备考黑龙江省安全员C证操作证的学员准备的理论考试专题&#xff0c;每个月更新的黑龙江省安全员C证找解析祝您顺利通过黑龙江省安全员C证考试。 1、【多选题】下列属于编制安全检查…

【力扣题解】P530-二叉搜索树的最小绝对差-Java题解

&#x1f468;‍&#x1f4bb;博客主页&#xff1a;花无缺 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! 本文由 花无缺 原创 收录于专栏 【力扣题解】 文章目录 【力扣题解】P530-二叉搜索树的最小绝对差-Java题解&#x1f30f;题目描述&#x1f4a1;题解&…

解密C++中的forward<int>(a)和forward<int >(a):你真的了解它们之间的区别吗?

一文看尽C中的forward完美转发 一、前言二、深入理解forward和完美转发三、对forward<int>(a)的解析四、对forward<int &&>(a)的解析五、forward<int>(a)和forward<int &&>(a)的区别总结 一、前言 完美转发在C中具有重要性&#xff0…

数据结构期末复习(2)链表

链表 链表&#xff08;Linked List&#xff09;是一种常见的数据结构&#xff0c;用于存储一系列具有相同类型的元素。链表由节点&#xff08;Node&#xff09;组成&#xff0c;每个节点包含两部分&#xff1a;数据域&#xff08;存储元素值&#xff09;和指针域&#xff08;指…

Python学习笔记之(一)搭建Python 环境

搭建Python 环境 1. 使用工具准备1.1 Python 安装1.1.1 下载Python 安装包1.1.2 安装Python 1.2 VScode 安装1.2.1 下载VScode安装包1.2.2 给VScode安装Python 扩展 2. 第一次编写Python 程序 本篇文章以Windows 系统为例。 1. 使用工具准备 1.1 Python 安装 1.1.1 下载Pytho…