大帝的密码武器(buuctf)

 下载题目后无法打开  需要添加.zip的后缀才能打开

题目:

公元前一百年,在罗马出生了一位对世界影响巨大的人物,他生前是罗马三巨头之一。他率先使用了一种简单的加密函,因此这种加密方法以他的名字命名。
以下密文被解开后可以获得一个有意义的单词:FRPHEVGL
你可以用这个相同的加密向量加密附件中的密文,作为答案进行提交。

密文:

ComeChina

不知道凯撒密码的偏移量,可以尝试使用暴力破解方法,也就是尝试所有可能的偏移量,逐个进行解密,然后手动判断哪一个解密结果是可读的文本。以下是一个使用C++编写的凯撒解码代码,通过暴力穷举所有偏移量进行解码:

#include <iostream>
#include <string>

using namespace std;

// 凯撒解密函数
string caesarDecrypt(string encryptedText, int shift) {
    string decryptedText = "";
    int length = encryptedText.length();

    // 对每个字符进行解密操作
    for (int i = 0; i < length; ++i) {
        // 解密大写字母
        if (isupper(encryptedText[i])) {
            char decryptedChar = (encryptedText[i] - shift - 65 + 26) % 26 + 65;
            decryptedText += decryptedChar;
        }
        // 解密小写字母
        else if (islower(encryptedText[i])) {
            char decryptedChar = (encryptedText[i] - shift - 97 + 26) % 26 + 97;
            decryptedText += decryptedChar;
        }
        // 其他字符保持不变
        else {
            decryptedText += encryptedText[i];
        }
    }

    return decryptedText;
}

// 凯撒暴力破解函数
void caesarBruteForce(string encryptedText) {
    cout << "开始暴力破解..." << endl;

    // 尝试所有可能的偏移量
    for (int shift = 1; shift <= 25; ++shift) {
        cout << "偏移量: " << shift << endl;
        cout << "解密结果: " << caesarDecrypt(encryptedText, shift) << endl;
        cout << "-------------------" << endl;
    }

    cout << "暴力破解完成!" << endl;
}

int main() {
    string encryptedText;

    // 输入要解密的文本
    cout << "请输入要解密的文本:";
    getline(cin, encryptedText);

    // 调用凯撒暴力破解函数进行解密
    caesarBruteForce(encryptedText);

    return 0;
}

 

 

可以得出偏移量为13

对密文加密可得出结果flag{PbzrPuvan}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值