Quantcast
Channel: Comunidad Underground Hispana
Viewing all articles
Browse latest Browse all 11602

[C++] File Crypter 1.5

$
0
0
File Crypter 1.5
Encripta y Desencripta Archivos


File Crypter es un simple programa, que es capaz de cifrar sus archivos y descifrarlos. Una versión de File Crypter se incluye como un ejemplo en la libreria xCrypter y es llamada "ncrypter", que es la abreviatura de "new Crypter".

Codigo Fuente

file_crypter.cpp

Código:

/* file_crypter.cpp -- The implementation of the GUI and the 4 simple
 * algorithms
 *
 * The main dialog which gives access to all the 5 different encryption
 * algorithms. The 4 simple ones are implemented here, with the 5th
 * "xcrypter" algorithm being accessed as appropriate for that algorithm.
 *
 * Written by René Kjellerup <katana_steel@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "file_crypter.h"
#include <QtGui>
#include <fstream>
#include <crypt.h>

FCMain::FCMain(QWidget *p)
    : QMainWindow(p)
{
    xcry = 0;
    setupUi(this);

    check_xcrypter(0);

    connect(actionAbout, SIGNAL(triggered()), this, SLOT(about()));
    connect(encBtn, SIGNAL(clicked()), this, SLOT(startEnc()));
    connect(decBtn, SIGNAL(clicked()), this, SLOT(startDec()));
    connect(inputFileBtn, SIGNAL(clicked()), this, SLOT(openInput()));
    connect(outputFileBtn, SIGNAL(clicked()), this, SLOT(setOutput()));
    connect(keyFileBtn, SIGNAL(clicked()), this, SLOT(openKey()));
    connect(setKeyFileBtn, SIGNAL(clicked()), this, SLOT(setKey()));
    connect(comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(check_xcrypter(int)));
}

void
FCMain::startEnc()
{
    bool ret;
    switch(comboBox->currentIndex())
    {
    case 0:
        ret = algo1e();
        break;
    case 1:
        ret = algo2e();
        break;
    case 2:
        ret = algo3e();
        break;
    case 3:
        ret = algo4e();
        break;
    case 4:
        if(xcry) {
            std::ifstream I(inputFile->text().toAscii().constData(),
                    std::ios_base::binary);
            std::ofstream O(outputFile->text().toAscii().constData(),
                    std::ios_base::binary);
            xcry->enc(I,O);
            I.close();
            O.close();
            ret = true;
        } else {
                ret = false;
        }
        break;
    default:
        ret = false;
    }
    if(!ret)
        QMessageBox::information(this,"File Crypter","Unable to process your request");
}

void
FCMain::startDec()
{
    bool ret;
    switch(comboBox->currentIndex())
    {
    case 0:
        ret = algo1d();
        break;
    case 1:
        ret = algo2d();
        break;
    case 2:
        ret = algo3d();
        break;
    case 3:
        ret = algo4d();
        break;
    case 4:
        if(xcry) {
            std::ifstream I(inputFile->text().toAscii().constData(),
                    std::ios_base::binary);
            std::ofstream O(outputFile->text().toAscii().constData(),
                    std::ios_base::binary);
            xcry->dec(I,O);
            I.close();
            O.close();
            ret = true;
        } else {
                ret = false;
        }
        break;
    default:
        ret = false;
    }
    if(!ret)
        QMessageBox::information(this,"File Crypter","Unable to process your request");
}

void
FCMain::about()
{
    QDialog *win = new QDialog;
    QVBoxLayout *vb = new QVBoxLayout(win);
    QLabel *lab = new QLabel("File Crypter");
    vb->addWidget(lab);
    lab = new QLabel(" ");
    vb->addWidget(lab);
    lab = new QLabel("version 1.5");
    vb->addWidget(lab);
    lab = new QLabel("by");
    vb->addWidget(lab);
    lab = new QLabel("René Kjellerup");
    vb->addWidget(lab);
    vb->addStretch();
    win->exec();
    delete win;
}

void
FCMain::show()
{
    QMainWindow::show();
    adjustUI();
}

void
FCMain::adjustUI()
{
    QRect rc;
    if(inputFileBtn->width() <= outputFileBtn->width())
        rc = outputFileBtn->rect();
    else
        rc = inputFileBtn->rect();

    setKeyFileBtn->setMinimumWidth(rc.width());
    inputFileBtn->setMinimumWidth(rc.width());
    outputFileBtn->setMinimumWidth(rc.width());
    this->setMinimumWidth(rc.width()*4);
}

void
FCMain::setKey()
{
    if(keyFile->text().isEmpty()) return;

    if(xcry) delete xcry;
    xcry = new xcrypter::crypt(keyFile->text().toAscii().constData());
}

void
FCMain::openKey()
{
    QString fname = QFileDialog::getOpenFileName(this, "Input File:");
    if(!fname.isNull())
        keyFile->setText(fname);

}

void
FCMain::check_xcrypter(int idx)
{
    bool vis = false;
    if(idx == 4) vis = true;

    keyFile->setVisible(vis);
    keyFileBtn->setVisible(vis);
    setKeyFileBtn->setVisible(vis);
}

void
FCMain::openInput()
{
    QString fname = QFileDialog::getOpenFileName(this, "Input File:");
    if(!fname.isNull())
        inputFile->setText(fname);
}

void
FCMain::setOutput()
{
    QString fname = QFileDialog::getSaveFileName(this, "Output File:");
    if(!fname.isNull())
        outputFile->setText(fname);
}

bool
FCMain::algo1e()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%5) {
        case 0:
          c += 0x12;
          O << c;
          break;
        case 1:
          c += 0x10;
          O << c;
          break;
        case 2:
          c += 0x14;
          O << c;
          break;
        case 3:
          c += 0x18;
          O << c;
          break;
        case 4:
          c += 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo1d()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%5) {
        case 0:
          c -= 0x12;
          O << c;
          break;
        case 1:
          c -= 0x10;
          O << c;
          break;
        case 2:
          c -= 0x14;
          O << c;
          break;
        case 3:
          c -= 0x18;
          O << c;
          break;
        case 4:
          c -= 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo2e()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%5) {
        case 0:
          c -= 0x12;
          O << c;
          break;
        case 1:
          c += 0x10;
          O << c;
          break;
        case 2:
          c -= 0x14;
          O << c;
          break;
        case 3:
          c += 0x18;
          O << c;
          break;
        case 4:
          c -= 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo2d()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%5) {
        case 0:
          c += 0x12;
          O << c;
          break;
        case 1:
          c -= 0x10;
          O << c;
          break;
        case 2:
          c += 0x14;
          O << c;
          break;
        case 3:
          c -= 0x18;
          O << c;
          break;
        case 4:
          c += 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo3e()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%5) {
        case 0:
          c += 0x12;
          O << c;
          break;
        case 1:
          c += 0x10;
          O << c;
          break;
        case 2:
          c -= 0x14;
          O << c;
          break;
        case 3:
          c -= 0x18;
          O << c;
          break;
        case 4:
          c -= 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo3d()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%5) {
        case 0:
          c -= 0x12;
          O << c;
          break;
        case 1:
          c -= 0x10;
          O << c;
          break;
        case 2:
          c += 0x14;
          O << c;
          break;
        case 3:
          c += 0x18;
          O << c;
          break;
        case 4:
          c += 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo4e()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%15) {
        case 0:
          c += 0x12;
          O << c;
          break;
        case 1:
          c += 0x10;
          O << c;
          break;
        case 2:
          c += 0x14;
          O << c;
          break;
        case 3:
          c += 0x18;
          O << c;
          break;
        case 4:
          c += 0x16;
          O << c;
          break;
        case 5:
          c += 0x12;
          O << c;
          break;
        case 6:
          c -= 0x10;
          O << c;
          break;
        case 7:
          c += 0x14;
          O << c;
          break;
        case 8:
          c -= 0x18;
          O << c;
          break;
        case 9:
          c += 0x16;
          O << c;
          break;
        case 10:
          c += 0x12;
          O << c;
          break;
        case 11:
          c += 0x10;
          O << c;
          break;
        case 12:
          c -= 0x14;
          O << c;
          break;
        case 13:
          c -= 0x18;
          O << c;
          break;
        case 14:
          c -= 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}
bool
FCMain::algo4d()
{
    unsigned long long count = 0;  // cryption counter
    unsigned char c; // tmp data
    int cc;
    std::ifstream I(inputFile->text().toAscii().constData(),
        std::ios_base::binary);
    std::ofstream O(outputFile->text().toAscii().constData(),
        std::ios_base::binary);
    while((cc = I.get()) >= 0) {
        c = (unsigned char)cc;
        switch(count%15) {
        case 0:
          c -= 0x12;
          O << c;
          break;
        case 1:
          c -= 0x10;
          O << c;
          break;
        case 2:
          c -= 0x14;
          O << c;
          break;
        case 3:
          c -= 0x18;
          O << c;
          break;
        case 4:
          c -= 0x16;
          O << c;
          break;
        case 5:
          c -= 0x12;
          O << c;
          break;
        case 6:
          c += 0x10;
          O << c;
          break;
        case 7:
          c -= 0x14;
          O << c;
          break;
        case 8:
          c += 0x18;
          O << c;
          break;
        case 9:
          c -= 0x16;
          O << c;
          break;
        case 10:
          c -= 0x12;
          O << c;
          break;
        case 11:
          c -= 0x10;
          O << c;
          break;
        case 12:
          c += 0x14;
          O << c;
          break;
        case 13:
          c += 0x18;
          O << c;
          break;
        case 14:
          c += 0x16;
          O << c;
          break;
        }
        count++;
    }
    I.close();
    O.close();
    return true;
}

file_crypter.h

Código:

#ifndef __file_crypter_h
/* FCMain -- The GUI to all the 5 encryption algorithms
 *
 * Written by René Kjellerup <katana_steel@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#define __file_crypter_h 1

#include <QMainWindow>
#include "ui_file_crypter.h"

namespace xcrypter {
class crypt;
}

class FCMain : public QMainWindow, private Ui::MainWindow
{
    Q_OBJECT
    xcrypter::crypt *xcry;
public:
    FCMain(QWidget *p=0);

    void show();

private slots:
    void startEnc();
    void startDec();
    void openInput();
    void setOutput();
    void setKey();
    void openKey();
    void check_xcrypter(int idx);
    void adjustUI();
    void about();

private:
    bool algo1e();
    bool algo1d();
    bool algo2e();
    bool algo2d();
    bool algo3e();
    bool algo3d();
    bool algo4e();
    bool algo4d();

};

#endif

Ejemplo

Código:

// ncrypter.cpp : Defines the entry point for the console application.
//
#include "crypt.h"
#include <fstream>

void usage(void);


int main(int argc, char* argv[])
{
        if((argc > 1) && (6 > argc)) {
                xcrypter::crypt *lib;
                std::ifstream I;
                std::ofstream O;
                if(argv[1][0] == '-') {
                        switch(argv[1][1]) {
                                case 'c':
                                        lib = new xcrypter::crypt(argv[2]);
                                        break;
                                case 'e':
                                        lib = new xcrypter::crypt(argv[2]);
                                        I.open(argv[3],std::ios::binary);
                                        O.open(argv[4],std::ios::binary);
                                        lib->enc(I,O,0);
                                        O.close();
                                        I.close();
                                        break;
                                case 'd':
                                        lib = new xcrypter::crypt(argv[2]);
                                        I.open(argv[3],std::ios::binary);
                                        O.open(argv[4],std::ios::binary);
                                        lib->dec(I,O,0);
                                        O.close();
                                        I.close();
                                        break;
                                default:
                                        usage();
                                        break;
                        }
                        if(lib) delete lib;
                        return 0;
                }
        }
        usage();
        return 0;
}




Uploadable.net - #1 [Code] File Crypter 1.5

Viewing all articles
Browse latest Browse all 11602

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>