Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Julian ( 13 years ago )
/* 
 * File:   Decryption.cpp
 * Author: Julian
 * 
 * Created on 10. Januar 2013, 12:15
 */

#include "Decryption.h"

Decryption::Decryption() {
}

Decryption::Decryption(const Decryption& orig) {
}

Decryption::~Decryption() {
}



bool cmp(test::value_type const & a, test::value_type const & b) {
    return a.second < b.second;
}

void increment(int &i) {
    ++i;
}

bool Decryption::decrypt() {

    fstream inputFile&#40;"GeheimeBotschaft.txt", ios::in&#41;;
    if (!inputFile) {
        cout << "Fehler! Überprüfen sie ihren Pfad\n";
        throw invalid_argument("inputFile nicht gefunden");
    }

    ofstream outputFile&#40;"Entschlüsselt.txt", ios::out&#41;;
    char text;
    test mymap;

    while (inputFile.get(text)) {
        inputFile.get(text);
        increment(mymap[text]);
    }
    inputFile.clear();
    inputFile.seekg(0);

    //char ch = max_element(mymap.begin(), mymap.end(), cmp)->first;
    char ch = max_element(mymap.begin(), mymap.end(), cmp())->first;

    int key;
    int ascii = 32; // 32 ist das ASCII Leerzeichen, das in großen Texten das häuftigste Zeichen ist.
    key = (unsigned char) ch;

    if (key > ascii) {

        key = key - ascii;

        while (!inputFile.eof()) { // TODO inputFile.eof fehlerhaft

            inputFile.get(text);
            text = text - key;
            outputFile.put(text);
        }

    }
    else {
        
        key = ascii - key;

        while (!inputFile.eof()) { // TODO inputFile.eof fehlerhaft

            inputFile.get(text);
            text = text + key;
            outputFile.put(text);
        }


    }


    return 0;
}

 

Revise this Paste

Your Name: Code Language: