项目结构:(Casear-Cipher.rar)
文件注释
介绍
与基本算法比较
配置环境
代码注释(Casear-Cipher.cpp)
README-En.md
README-Ch.md
Comment-With-$L^AT_EX$.md
Mark-Text.exe
New-Algorithms-to-Decode-the-Casear-Cipher.pptx
Code
Casear-Cipher.cpp
Casear-Cipher.exe
加粗的部分是文件名,其他的是注释。
README-En.md
英语版的README
README-Ch.md
中文版的README
Mark-Text.exe
Markdown 文件查看器
New-Algorithms-to-Decode-the-Casear-Cipher.pptx
这个项目的核心文件
包含了所有关于这两个算法的内容
Comment-With-$L^AT_EX$.md
使用$L^AT_EX$的注释
Code
代码文件夹
Casear-Cipher.cpp
基础算法
Casear-Cipher.exe
Casear-Cipher.cpp 的可执行文件
在这个项目中,我们提出了以下的两个新的算法来解码 凯撒密码。
在一段给定的文字中使用基础的计数器来统计每个字母的出现频率,并将其与被解码后的字母一一对应。
使用 权值更新 算法 来更新给定词库里的每一个单词的权值。
普通算法:
代码:(cpp)
string ceaser (string plain_text, int mode, int STEP)
{
if (STEP >= 26) STEP %= 26;
string cipher = "";
for (int i = 0; i < plain_text.size(); i++) {
if (plain_text[i] >= 48 && plain_text[i] <= 57) {
cipher.push_back (plain_text[i]);
} else if (plain_text[i] >= 65 && plain_text[i] <= 90) {
cipher.push_back ( (char) (65 + (plain_text[i] + mode * STEP - 65) % 26));
} else {
cipher.push_back ( (char) (97 + (plain_text[i] + mode * STEP - 97) % 26));
}
}
return cipher;
}
//这段代码在2022/6/10使用Win10和TDM-GCC 4.9.2 64-bit Release编译通过。
时间 | #1 | #2 | #3 | #4 | #5 | #6 | All |
---|---|---|---|---|---|---|---|
基础 | 5422.5 | 5282.5 | 7552.5 | 6185 | 5345 | 5795 | 35582.5 |
第一个 | 365 | 454 | 548 | 523 | 322 | 862 | 3074 |
第二个 | None | None | None | None | None | None | None |
编译器:TDM-GCC 4.9.2 64-bit Release
操作系统:Windows 10 企业版,版本17134.2026
处理器:Intel Core i5-7300U CPU @ 2.60GHZ 2.71GHZ
编辑器:Red-Panda-Cpp
#include<iostream>
#include<string>
using namespace std;
enum MODE
{
ENCODE = 1,
DECODE = -1
};
string ceaser (string plain_text, int mode, int STEP)
//plain_text:要解密/加密的字符串
//mode :区分解密/加密模式
//STEP :偏移量
{
if (STEP >= 26) STEP %= 26;
string cipher = "";
for (int i = 0; i < plain_text.size(); i++) {
if (plain_text[i] >= 48 && plain_text[i] <= 57) {
cipher.push_back (plain_text[i]);
} else if (plain_text[i] >= 65 && plain_text[i] <= 90) {
cipher.push_back ( (char) (65 + (plain_text[i] + mode * STEP - 65) % 26));
//(1)
} else {
cipher.push_back ( (char) (97 + (plain_text[i] + mode * STEP - 97) % 26));
//(2)
}
}
return cipher;
}
string ceaser_encoding (string plain, int STEP)
//加密
{
return ceaser (plain, ENCODE, STEP);
}
string ceaser_decoding (string plain, int STEP)
//解密
{
return ceaser (plain, DECODE, STEP);
}
int main()
{
string cipher;
int n=1;
//getline (cin, cipher);
cipher="helloworld";
string res = ceaser_encoding (cipher, n);
cout << "密文:" << res << endl;
cout << "明文:" << ceaser_decoding (res, n) << endl;
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。