本帖最后由 蒟蒻 于 2023-4-19 19:06 编辑
【前言】
论坛坛友们大家好,我是练习时长
几个月的个人练习生蒟蒻
今天给大家带来凯撒密码的使用教程
(本来想做个软件的,结果老是卡bug,也懒得去修,就shift+delete了)
【什么是凯撒密码】
凯撒密码是一种简单,但是些许不安全的加密算法
一个密码学家,及时没有获取到密钥,也可以推算出原内容(因为原理简单)
【凯撒密码加密原理】
凯撒密码的加密原理如下:
例如,明文是
I'm a real ikun and a real homo
密钥是5
那么加密后的密文就是
N'r f wjfq npzs fsi f wjfq mtrt
原理就是把每个字母的ANSI码都加上5,就得到了密文
【新制作的凯撒密码加密器】
花五分钟写的答辩,将就着看吧
[C++] 纯文本查看 复制代码 /**
* JRCaeser Project
* Copyright (c) 2023 Storm Lab.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author Github JuRuoqwq
**/
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
char * EncryptData(char* Source, size_t StrSize, int key)
{
for (int i = 0; i < StrSize; i++) {
Source[i] = Source[i + key];
}
return Source;
}
char * DecryptData(char* Source, size_t StrSize, int key)
{
char dekey = key - (key * 2); //key的负数
for (int i = 0; i < StrSize; i++) {
Source[i] = Source[i + dekey];
}
return Source;
}
int main(void)
{
printf("Mode(1.Encrypt,2.Decrypt) $ ");
int mode;
int scan = scanf("%d", &mode);
printf("Key(> -128 && < 127) $ ");
int key;
int scan1 = scanf("%d", &key);
printf("Data(Use underline links in spaces) $ ");
char* data = new char[1000];
int scan2 = scanf("%s", data);
data = strcat(data, "\0");
if (mode == 1) {
printf("Data is %s\n", EncryptData(data, strlen(data), key));
delete[] data;
}
else if (mode == 2) {
printf("Data is %s\n", DecryptData(data, strlen(data), key));
delete[] data;
}
else {
printf("Error Mode!");
return -1;
}
return 0;
} |