[新手入门] WeChall Training: Crypto - Caesar I

[复制链接]
查看6595 | 回复3 | 2020-3-6 13:45:43 | 显示全部楼层 |阅读模式
As on most challenge sites, there are some beginner cryptos, and often you get started with the good old caesar cipher.
I welcome you to the WeChall style of these training challenges
Enjoy!
Ciphertext
ESP BFTNV MCZHY QZI UFXAD ZGPC ESP WLKJ OZR ZQ NLPDLC LYO JZFC FYTBFP DZWFETZY TD ZTDPSSWNZNCN
题目:凯撒密码 解密文    http://www.wechall.net/challenge/training/crypto/caesar/index.php
解决:
#include<string.h>
#include<stdio.h>
#include<iostream>
using namespace std;

char *ciphertext = "RFC OSGAI ZPMUL DMV HSKNQ MTCP RFC JYXW BME MD AYCQYP YLB WMSP SLGOSC QMJSRGML GQ MGQCFFJAMAPA";
char plaintext[100];

int main()
{
        int len = strlen(ciphertext);
        for (int k = 0 ; k < 26 ; k++) {
                for (int i = 0 ; i < len ; i++) {
                        if (ciphertext != ' ') {
                                char ch = ciphertext;
                                int index = ch - 'A';
                                index = (index + k) % 26;
                                ch = 'A'+index;
                                plaintext = ch;
                        } else {
                                plaintext = ' ';
                        }
                }
                plaintext[len] = '\0';
                cout<<plaintext<<endl;
        }
        return 0;
}
运行结果可找到一段明文
THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG OF CAESAR AND YOUR UNIQUE SOLUTION IS OISEHHLCOCRC

回复

使用道具 举报

行书忱 | 2020-3-6 16:13:30 | 显示全部楼层
请问楼主能描述一下加密过程嘛?代码用vs运行不了
回复

使用道具 举报

xxgutao | 2020-3-7 11:06:47 | 显示全部楼层
行书忱 发表于 2020-3-6 16:13
请问楼主能描述一下加密过程嘛?代码用vs运行不了

就是列举0-25的偏移量啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

4

主题

6

帖子

65

积分

小有名气

Rank: 3Rank: 3

积分
65