专栏文章
新的加密方法——62进制加密法
科技·工程参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @miosj0es
- 此快照首次捕获于
- 2025/12/03 00:26 3 个月前
- 此快照最后确认于
- 2025/12/03 00:26 3 个月前
加密规则
-
小写英文字母用~ 代替,大写英文字母用 ~ 代替。(全部都是62进制)。
-
将62进制的数字转换我2进制。
-
遇到空格或符号时,后面的是新的数字。
-
并且空格或符号要原封不动的输出出来。
很简单,对吧!
优点
这种方法通过非传统的加密方式,无法通过一一对应的方式破解。
并且两个相似的字符串加密完都会有极大的差别
例:qwert和qnert:
- qwert密文:10111010110110110100101111111。
- qnert密文:10111001110101010111011000111。
这两个字符串只改变了第二个字符,却导致从密文第七个开始有了区别,并且后面再也没有大面积的重复了。
测试与实操
测试:
- 经测试,经过加密的字符(有意义)无法被Deep Seek破解,后进行对应的原文与密文提示,也无法破解。
实操:
加密:
以十进制为跳板进行加密。
例:
解密:
同样以十进制为跳板进行解密。
例:
代码:
但是如果加密特别长的文字很容易 把我们累死 导致加密的不正确,所以我设计了下面的两个代码:
加密部分:
CPP#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int t(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
else if (c >= 'a' && c <= 'z') {
return 10 + (c - 'a');
}
else if (c >= 'A' && c <= 'Z') {
return 36 + (c - 'A');
}
return -1;
}
char r(int d) {
if (d >= 0 && d <= 9) {
return '0' + d;
}
else if (d >= 10 && d <= 35) {
return 'a' + (d - 10);
}
else if (d >= 36 && d <= 61) {
return 'A' + (d - 36);
}
return '?';
}
string os(string s) {
int i = 0;
while (i < s.length() && s[i] == '0') {
i++;
}
if (i == s.length()) {
return "0";
}
return s.substr(i);
}
string y(string s) {
s = os(s);
if (s == "0") {
return "0";
}
string bin = "";
while (s != "0") {
string quotient = "";
int rem = 0;
bool leadingZero = true;
for (int i = 0; i < s.length(); i++) {
int digit = t(s[i]);
if (digit == -1) {
digit = 0;
}
int current = digit + rem * 62;
int q = current / 2;
rem = current % 2;
if (q != 0 || !leadingZero) {
quotient += r(q);
leadingZero = false;
}
}
if (quotient.empty()) {
quotient = "0";
}
bin = string(1, '0' + rem) + bin;
s = quotient;
}
return bin;
}
int main() {
string input;
getline(cin, input);
string num_str = "";
string result = "";
for (char c : input) {
if ((c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z')) {
num_str += c;
}
else {
if (!num_str.empty()) {
result += y(num_str);
num_str.clear();
}
result += c;
}
}
if (!num_str.empty()) {
result += y(num_str);
}
cout << result << endl;
return 0;
}
解密部分:
CPP#include <iostream>
#include <string>
#include <cctype>
#include <utility>
#include <algorithm>
using namespace std;
char d(int d) {
if (d >= 0 && d <= 9) {
return '0' + d;
}
else if (d >= 10 && d <= 35) {
return 'a' + (d - 10);
}
else if (d >= 36 && d <= 61) {
return 'A' + (d - 36);
}
return '?';
}
string mul(string num) {
string result = "";
int carry = 0;
for (int i = num.size() - 1; i >= 0; i--) {
int digit = num[i] - '0';
int temp = digit * 2 + carry;
carry = temp / 10;
char c = (temp % 10) + '0';
result = c + result;
}
if (carry) {
result = char(carry + '0') + result;
}
return result;
}
string add(string num) {
string result = num;
int carry = 1;
for (int i = result.size() - 1; i >= 0 && carry; i--) {
int digit = result[i] - '0';
int sum = digit + carry;
carry = sum / 10;
result[i] = (sum % 10) + '0';
}
if (carry) {
result = "1" + result;
}
return result;
}
pair<string, int> divide(string num, int divisor) {
string quotient = "";
int remainder = 0;
for (int i = 0; i < num.size(); i++) {
int digit = num[i] - '0';
int current = remainder * 10 + digit;
if (current < divisor) {
if (!quotient.empty()) {
quotient += '0';
}
remainder = current;
continue;
}
int q = current / divisor;
remainder = current % divisor;
quotient += (q + '0');
}
if (quotient.empty()) {
quotient = "0";
}
return make_pair(quotient, remainder);
}
string de(string dec) {
if (dec == "0") {
return "0";
}
string base62 = "";
string current = dec;
while (current != "0") {
pair<string, int> p = divide(current, 62);
base62 = d(p.second) + base62;
current = p.first;
}
return base62;
}
string bi(string bin) {
if (bin.empty()) {
return "0";
}
string dec = "0";
for (int i = 0; i < bin.length(); i++) {
dec = mul(dec);
if (bin[i] == '1') {
dec = add(dec);
}
}
return dec;
}
int main() {
string input;
getline(cin, input);
string bin_str = "";
string result = "";
for (char c : input) {
if (c == '0' || c == '1') {
bin_str += c;
}
else {
if (!bin_str.empty()) {
string dec = bi(bin_str);
string base62 = de(dec);
result += base62;
bin_str.clear();
}
result += c;
}
}
if (!bin_str.empty()) {
string dec = bi(bin_str);
string base62 = de(dec);
result += base62;
}
cout << result << endl;
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...