Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <vector>
- char encode(char c, int key) {
- std::vector<char> alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
- 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
- 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
- return alphabet[((c - 65) + key) % (alphabet.size())];
- }
- char decode(char c, int key) { return encode(c, 26 - key); }
- std::string full_decode(std::string s, int key) {
- for (int i = 0; i < s.length(); i++) {
- if (s[i] != ' ')
- s[i] = decode(s.at(i), key);
- }
- return s;
- }
- std::string full_encode(std::string s, int key) {
- for (int i = 0; i < s.length(); i++) {
- if (s[i] != ' ')
- s[i] = encode(s.at(i), key);
- }
- return s;
- }
- // (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
- // (0 1 2 3 4 25)
- int main(int argc, char **args) {
- using namespace std;
- if(argc != 2) {
- cout << "Utilizzo del programma: crypta.exe nomefile.txt" << endl;
- return -1;
- }
- ofstream fout;
- ifstream fin;
- fin.open(args[1]);
- fout.open("output.txt");
- string file_input = "";
- while (!fin.eof()) {
- string temp;
- fin >> temp;
- file_input += temp + " ";
- }
- string s = full_encode(file_input, 7);
- // cout << endl << s << endl;
- // s = full_decode(s, 7);
- // cout << endl << s << endl;
- fout << s;
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement