嗨,我正试图在c++中编写一个反向密码.我正在努力开始,可以使用一些指导

Hi, I am trying to write a reverse cipher code in C++. I am struggling to get started and could use some guidance?

本文关键字:密码 努力 开始 可以使 c++ 一个      更新时间:2023-10-16

密码应该接受用户输入的字符串,然后吐出加密后的代码。

所以如果字符串是ABCD,那么加密是ZYXW。

但是我正在努力弄清楚如何开始编写函数。我想使用一个函数,然后在主函数中调用它,当我需要它!谢谢。

#include<iostream>
using namespace std;
int main() {
    char a[100];
    cout<<"Enter A String :";
    cin>>a;
    //Your Function Calling Should Be this
    //Supposing all characters are uppercase
    int st = 65 , et = 90;
    char b[100];
    for(int i=0;a[i]!='';i++){
        b[i] = et - (a[i] - 65);
    }
    cout<<"nYour Answer :"<<b;
    return 0;
}

这将为您工作

你可以使用这个函数:

char convert(char c) {
    return 'Z' - (c - 'A');
}

像这样使用:

std::transform(s.begin(), s.end(), s.begin(), convert);

s是要转换的字符串。

演示