카이사르 암호로 .txt 파일을 암호화하고 암호 해독하는 프로그램을 만들고 있습니다. (키보드 입력은 선택 사항입니다.) 노력했지만 어려움을 겪었습니다.카이사르 암호/파일 입력이 작동하지 않습니다.
내가 지금 가지고있는 것은 기본이거나 다소 정교한 메뉴 구조입니다. 나는 파일에서 정보를 호출해야하는 곳으로 가버 리거나 가비지를 호출하거나 가비지를 한 방향으로 보냅니다.
입력 부분까지 실행 된 다음 입력이 끝나는 코드입니다.
옵션 1 옵션 1과 임의의 숫자를 입력 한 다음 파일 입력을 실행 한 다음 종료합니다.
미리 감사드립니다. 나는 꽤 많이 도처에 보았고, 3 ~ 4 가지의 다른 방법을 모두 쓸데없이 시도했다.
그래서 내가 알고 싶은 것은 파일 입력을 수정하고 그 배열 또는 문자열을 가져와 어떻게 시프트 값으로 각 문자의 ascii 값을 제안하고 변경하는지 제안하는 방법입니다.
미리 감사드립니다.
#include <iostream>
#include <fstream>
#include <cmath>
#include <cctype>
#include <cstring>
#include <string>
#include <sstream>
#include <dos.h>
#include <stdio.h>
#include <windows.h>
#include <cstdlib>
using namespace std;
int decryptce();
int encryptcefile();
int encryptce();
int outputce();
int encmenu();
int decmenu();
int main()
{
int t;
//main menu
cout << "-----------------------------------------------------"<<endl;
cout << "This is a Caesar Cipher, please select [1] or [2]" << endl;
cout << "-----------------------------------------------------"<<endl;
cout << "[1] Encrypt"<<endl;
cout << "[2] Decrypt"<<endl;
cout << "What is your choice:\t";
cin >> t;
cout << "\n-----------------------------------------------------"<<endl;
// menu switch statement
switch (t)
{
case 1:
{
cout << "\n running encryption:\n\n";
encmenu();
break;
}
case 2:
{
cout << "\n running decryption:\n\n";
decmenu();
break;
}
default:
{
cout<< "Thats not a 1 or 2"<<endl;
cout<< "Relaunch the program"<<endl;
system ("pause");
return 0;
}
}
return 0;
}
int encmenu()
{
int t;
cout << "-----------------------------------------------------"<<endl;
cout << "You selected: Encrypt with Caesar Cypher"<<endl;
cout << "-----------------------------------------------------"<<endl;
cout <<"Do you want to enter from a file or the keyboard?"<<endl;
cout <<"Enter [1] From file, or [2] From Keyboard"<<endl;
cout <<"Run option:\t";
cin >> t;
cout << "\n-----------------------------------------------------"<<endl;
// encrypt menu switch
switch (t)
{
case 1:
{
encryptcefile();
break;
}
case 2:
{
encryptce();
break;
}
default:
{
cout<< "Thats not a 1 or 2"<<endl;
cout<< "Relaunch the Program"<<endl;
system ("pause");
return 0;
}
}
return 0;
}
// decrypt main menu
int decmenu()
{
int h;
cout << "-----------------------------------------------------"<<endl;
cout << "You selected: Decrypt with Caesar Cypher"<<endl;
cout << "-----------------------------------------------------"<<endl;
cout << "Reading from Data.txt in main file directory:";
cout << "\n"<<endl;
cout << "Ofset is:\t";
cin >> h;
cout << "\n-----------------------------------------------------"<<endl;
return h;
}
int decryptce()
{
return 0;
}
int encryptcefile()
{
// for figuring out what to do with negatives
/*
letter = x;
letter = (letter + shift + 26) % 26;
// add 26 in case the shift is negative
letter += x; // back to ascii code
*/
char c,i;
int num=0;
int shift;
ofstream ofile;
ifstream ifile;
ifile.open("data.txt");
ofile.open("Encrypted.txt");
if(!ifile)
{
cout << "Error Opening File" << endl;
return 0;
}
if(!ofile)
{
cout << "Error Opening File" << endl;
return 0;
}
while (ifile.good())
{
c = ifile.get();
if (c=='\n')num++;
{
cout << "Is: " << num << " Long. \r";
Sleep(1);
fflush (stdin);
}
}
cout << "File is: " << num << " characters Long.\n"<<endl;
cout << "\n-----------------------------------------------------"<<endl;
cout << "What is the shift for the encryption:\t";
// ---------------------working here-------------------
cin >> shift;
const int xx = num+1;
char *arraye;
char *arrayce;
int j;
arraye = new char [xx];
arrayce = new char [xx];
arrayce[xx];
ifile.read(arrayce,xx);
for(j=0;j<xx;j++)
{
arraye[j]=arrayce[j];
cout << arrayce[j]<< endl;
}
return 0;
}
int encryptce()
{
return 0;
}
int outputce()
{
return 0;
}
전체 코드를 구문 분석하지 마십시오 만 관련 섹션과 * 최소한의 작업에 대한 유감 * 예. 게시 한 코드의 대부분은 질문과 전혀 관련이 없으며 혼란 스럽습니다. –