c++ - 基本加密程序无法正确读取文件

标签 c++ encryption dylan

我试图让一个程序在一个实例中获取输入来为用户加密,在另一个实例中(无论何时用户想要)从加密运行中创建的同一文件派生并反转加密,而是,它只是给我看起来像错误代码的东西。每次大约 6 个数字/字母,但与它应该做的事情完全无关。

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <cstdio>
#include <string>

using namespace std;
//ENCRYPTION AND DECRYPTION
string Decode(string text)
{
    int a;
    for(a=0; a<text.length(); a++){
        text[a]--;
    }
    return text;
}


string Encode (string text)
{
    int a;
    for(a=0; a<text.length(); a++){
        text[a]++;
    }
    return text;
}

//PROMPTS AND MAIN PROGRAM
int main(){
char input;
cout<<"+-+-+-+-+-+-+-+\n";
cout<<"|C|r|y|p|t|e|r|\n";
cout<<"+-+-+-+-+-+-+-+\n\n";
cout<<"Version 1.01 - Revision 2013\n";
cout<<"Created by Dylan Moore\n";
cout<<"____________________\n\n";
cout<<"Hello, would you like to decode or encode an encryption key?\nType 'd' for decode or 'e' for encode.\n\n";
cin>>input;
cin.get();
    switch(input){
        //DECODE
        case 'd':
        {
            string Message;
            ifstream myfile;
            myfile.open ("Key.txt");
                if (myfile.fail())
            {            
                    cout<<"Key.txt not found! Please make sure it is in the same directory as Crypter!\n\n";            
                    cin.get();            
                    return 0;            
                }    
            getline(myfile, Message);
            myfile.close();
            cout<<"Decoded Data:\n"<<Decode;(Message); 
            break;
        }
        //ENCODE
        case 'e':
        {
            string Message;
            ofstream myfile;
                    cout<<"Type the key you wish to be encrypted. When finished, press 'enter' 2 times to confirm.\n\n";
            getline (cin, Message);
            cin.get();
            myfile.open ("Key.txt");
            myfile<<Encode(Message);
            myfile.close();
                    cout<<"Thank you, your message has been saved to 'Key.txt' in this directory.\n";
            break;
        }

    }
    return _getch();
}

最佳答案

cout<<"Decoded Data:\n"<<Decode;(Message);
//                             ^ wrong

应该是

cout<<"Decoded Data:\n"<<Decode(Message); 

您当前的代码打印 Decode 函数的地址,然后执行第二条语句 (Message);,但没有任何效果。

关于c++ - 基本加密程序无法正确读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20203688/

相关文章:

c++ - 释放在不同同步上下文中使用的类成员

java - 在 PHP 中使用 DES 解密由 Java 加密的字符串

python - 是什么让(开放的)Dylan 不同于其他编程语言?

c++ - 在Days.obj中已经定义了奇怪的错误 “float percentOfOres”(?percentOfOres @@ 3MA)

c++ - 调用构造函数时出错

objective-c - iOS 13 中的 AES 加密 CryptLib 不起作用

php - Mysql加密/存储敏感数据,

linux - 在 ARM 架构上安装 Open Dylan

clojure - 如果像 Dylan、Julia 和 Seph 那样放弃前导括号,Clojure 会失去什么?

c++ - 我不断收到错误 "no match for call ' (std::vector<int>) (int)”