吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1544|回复: 18
收起左侧

[其他原创] 文本加密解密,自定义加密后密文内容

[复制链接]
我很忙! 发表于 2024-9-7 22:58
本帖最后由 我很忙! 于 2024-9-8 00:02 编辑

说明


根据自定义密文内容,进行加密,

效果图


2.png


[JavaScript] 纯文本查看 复制代码
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[i]);
            let k = this.sounds.findIndex(item => item === beastStr[i + 1]);
            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[i], 16) + i % 16) % 16;
            // 计算对应的字符索引
            buffer += this.sounds[Math.floor(k / 4)] + this.sounds[k % 4];
            // 根据索引从字符映射表中获取字符并添加到缓冲区中
        }
        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[0] = beastStr[2];
        // 设置字符映射表的第一个字符
        this.sounds[1] = beastStr[1];
        this.sounds[2] = beastStr[beastStr.length - 1];
        this.sounds[3] = beastStr[0];
    }

    setSounds(str) {
        this.sounds[0] = str[0];
        this.sounds[1] = str[1];
        this.sounds[2] = str[2];
        this.sounds[3] = str[str.length - 1];
    }

    getSoundsStr() {
        return this.sounds.join("");
        // 返回字符映射表的字符串表示
    }

    getSounds() {
        return this.sounds;
        // 返回字符映射表
    }

    getSoundsForBeast() {
        return [this.sounds[3], this.sounds[1], this.sounds[0], this.sounds[2]];
        // 返回用于特定处理的字符映射表顺序
    }

    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[0], soundMapForBeast[1], soundMapForBeast[2], beastSound, soundMapForBeast[3]].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();


免费评分

参与人数 6吾爱币 +12 热心值 +6 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
a5436539 + 1 + 1 我很赞同!
1783780690 + 1 + 1 谢谢@Thanks!
Bob5230 + 1 + 1 热心回复!
hwf411 + 1 + 1 谢谢@Thanks!
surepj + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

error3 发表于 2024-9-8 07:29
这想法不错,只是效率有点低,密文相对于明文的长度增长了数倍,但解密难度并不高。
涛之雨 发表于 2024-9-8 11:52
本帖最后由 涛之雨 于 2024-9-8 11:54 编辑

提供一组相近混淆

["\\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"]
["I","l","|","ı","Ɩ","ǀ","ˡ","І","׀","ו","ן","ߊ","ࡆ","।","৷","୲","౹","།","၊","᰻","᱾","ₗ","⃒","⃓","Ⅰ","ⅼ","⎟","⎢","⎥","⎪","⎸","⎹","⏐","│","┃","╵","╷","╹","╻","▏","▕","ⵏ","⼁","〡","ㄧ","ㅣ","㇑","丨","꒐","꘡","ꞁ","ꟾ","꠰","꣎","꤯","꫰","|","ᅵ","│"]
wangxd 发表于 2024-9-7 23:57
wangsheng518 发表于 2024-9-8 00:09
请问这个怎么用的 大佬  txt 可以加密吗
 楼主| 我很忙! 发表于 2024-9-8 00:17
wangsheng518 发表于 2024-9-8 00:09
请问这个怎么用的 大佬  txt 可以加密吗

可以,只要以字符串传入都能转换
meder 发表于 2024-9-8 00:29
感谢分享,自定义加密的好东西
surepj 发表于 2024-9-8 08:38
还能这么玩,有意思啊
wocuo2 发表于 2024-9-8 09:03
感谢分享
myFreefly 发表于 2024-9-8 10:24
感谢分享!!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 11:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表