文本加密解密,自定义加密后密文内容
本帖最后由 我很忙! 于 2024-9-8 00:02 编辑# 说明
根据自定义密文内容,进行加密,
# 效果图
class BeastTranslator {
constructor() {
// 构造函数,初始化时设置字符映射表,自定义密文内容,可随意调整,建议三个字符加一个符号
this.sounds = ['我', '很', '忙', '!'];
}
beastToHex(beastStr) {
let hexStr = "";
for (let i = 0; i < beastStr.length; i += 2) {
// 遍历输入字符串,每次处理两个字符
let j = this.sounds.findIndex(item => item === beastStr);
let k = this.sounds.findIndex(item => item === beastStr);
k = (j * 4 + k - i / 2 % 16 + 16) % 16;
// 计算对应的十六进制值
hexStr += k.toString(16).toUpperCase();
// 将十六进制值转换为大写字符串并添加到结果中
}
return hexStr;
}
hexToBeast(hexStr) {
let buffer = "";
for (let i = 0; i < hexStr.length; i++) {
let k = (parseInt(hexStr, 16) + i % 16) % 16;
// 计算对应的字符索引
buffer += this.sounds + this.sounds;
// 根据索引从字符映射表中获取字符并添加到缓冲区中
}
return buffer;
}
hexToText(hexStr) {
let buffer = "";
for (let i = 0; i < hexStr.length; i += 4) {
// 每四个字符一组进行处理
buffer += String.fromCharCode(parseInt(hexStr.substr(i, 4), 16));
// 根据十六进制代码获取对应的字符并添加到缓冲区中
}
return buffer;
}
textToHex(str) {
let hexStr = "";
for (let i = 0; i < str.length; i++) {
// 遍历输入字符串
hexStr += ("0000" + str.charCodeAt(i).toString(16)).substr(-4).toUpperCase();
// 将字符的 ASCII 码转换为十六进制字符串并格式化为四位,添加到结果中
}
return hexStr;
}
setSoundsFromBeast(beastStr) {
this.sounds = beastStr;
// 设置字符映射表的第一个字符
this.sounds = beastStr;
this.sounds = beastStr;
this.sounds = beastStr;
}
setSounds(str) {
this.sounds = str;
this.sounds = str;
this.sounds = str;
this.sounds = str;
}
getSoundsStr() {
return this.sounds.join("");
// 返回字符映射表的字符串表示
}
getSounds() {
return this.sounds;
// 返回字符映射表
}
getSoundsForBeast() {
return , this.sounds, this.sounds, this.sounds];
// 返回用于特定处理的字符映射表顺序
}
parseToNormal(beastStr) {
this.setSoundsFromBeast(beastStr);
// 根据输入字符串设置字符映射表
let hexCode = this.beastToHex(beastStr.substr(3, beastStr.length - 4));
// 将输入字符串的一部分转换为十六进制
return this.hexToText(hexCode);
// 将十六进制转换为普通文本字符串并返回
}
parseToBeast(normalStr, soundMap = null) {
if (soundMap) {
this.setSounds(soundMap);
// 如果有提供自定义字符映射表,则设置字符映射表
}
let hexCode = this.textToHex(normalStr);
// 将普通文本字符串转换为十六进制
let beastSound = this.hexToBeast(hexCode);
// 将十六进制转换为特定形式的字符串
let soundMapForBeast = this.getSoundsForBeast();
// 获取用于特定处理的字符映射表顺序
return , soundMapForBeast, soundMapForBeast, beastSound, soundMapForBeast].join("");
// 返回处理后的字符串
}
}
function testTranslator() {
let translator = new BeastTranslator();
// 待加密文本
let strToEncode = "吾爱破解";
console.log('-----------------------------------------');
let encodedStr = translator.parseToBeast(strToEncode);
console.log("加密后:", encodedStr,'\n');
let decodedStr = translator.parseToNormal(encodedStr);
console.log("解密后:", decodedStr);
console.log('-----------------------------------------');
}
testTranslator();
这想法不错,只是效率有点低,密文相对于明文的长度增长了数倍,但解密难度并不高。 本帖最后由 涛之雨 于 2024-9-8 11:54 编辑
提供一组相近混淆
{:301_1001:}
```json
["\\u0049","\\u006C","\\u007C","\\u0131","\\u0196","\\u01C0","\\u02E1","\\u0406","\\u05C0","\\u05D5","\\u05DF","\\u07CA","\\u0846","\\u0964","\\u09F7","\\u0B72","\\u0C79","\\u0F0D","\\u104A","\\u1C3B","\\u1C7E","\\u2097","\\u20D2","\\u20D3","\\u2160","\\u217C","\\u239F","\\u23A2","\\u23A5","\\u23AA","\\u23B8","\\u23B9","\\u23D0","\\u2502","\\u2503","\\u2575","\\u2577","\\u2579","\\u257B","\\u258F","\\u2595","\\u2D4F","\\u2F01","\\u3021","\\u3127","\\u3163","\\u31D1","\\u4E28","\\uA490","\\uA621","\\uA781","\\uA7FE","\\uA830","\\uA8CE","\\uA92F","\\uAAF0","\\uFF5C","\\uFFDC","\\uFFE8"]
```
```json
["I","l","|","ı","Ɩ","ǀ","ˡ","І","׀","ו","ן","ߊ","ࡆ","।","৷","୲","౹","།","၊","᰻","᱾","ₗ","⃒","⃓","Ⅰ","ⅼ","⎟","⎢","⎥","⎪","⎸","⎹","⏐","│","┃","╵","╷","╹","╻","▏","▕","ⵏ","⼁","〡","ㄧ","ㅣ","㇑","丨","꒐","꘡","ꞁ","ꟾ","꠰","꣎","꤯","꫰","|","ᅵ","│"]
```
吾爱破解"吾爱破解" 请问这个怎么用的 大佬txt 可以加密吗 wangsheng518 发表于 2024-9-8 00:09
请问这个怎么用的 大佬txt 可以加密吗
可以,只要以字符串传入都能转换 感谢分享,自定义加密的好东西 还能这么玩,有意思啊{:1_921:} 感谢分享 感谢分享!!
页:
[1]
2