danke für deinen Ansatz ich hab mal folgendes draus gemacht:
Code: Alles auswählen
QString KryptEnt::encrypt(QString begin, QString pw )
{
if(pw.size()<20)
{
QMessageBox::information( this, "Password Error", "The Password is to short(min. 20 chars)!", QMessageBox::Ok );
return "failed";
}
if(begin.size()<pw.size())
{
QString msg = QString("The text is to short(min. %1 chars)!").arg( QString::number(pw.size()) );
QMessageBox::information( this,"Text Error", msg, QMessageBox::Ok );
return "failed";
}
QString out;
for(int i=0; i < pw.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ pw.at(i).toAscii());
out.append(c);
}
for(int i = pw.size(); i < begin.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ begin.at(i - pw.size()).toAscii());
out.append(c);
}
return out;
}
QString KryptEnt::decrypt(QString begin, QString pw)
{
QString out;
for(int i=0; i < pw.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ pw.at(i).toAscii());
out.append(c);
}
for(int i = pw.size(); i < begin.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ out.at(i - pw.size()).toAscii());
out.append(c);
}
return out;
}
das problem ist das der gleiche fehler auftritt wie vorher
aber ich glaube das es an der art und weise meiner ausgabe
liegen koennte das der fehler aufzutreten
scheint
weil ich benutze zur eingabe und zur ausgabe 2 QTextEdit die vll nicht alle zeichen richtig darstellen koennen
Wen es interressiert hier mein ganzes Programm(natuerlich nur ein test programm)
Code: Alles auswählen
//main.cpp
#include <QApplication>
#include "KryptEnt.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
KryptEnt* window = new KryptEnt;
window->show();
return app.exec();
}
Code: Alles auswählen
//KryptEnt.h
#ifndef KRYPTENT_H
#define KRYPTENT_H
#include <QtGui>
class KryptEnt : public QWidget
{
Q_OBJECT
public:
KryptEnt( QWidget *parent = 0 );
QString encrypt(QString , QString );
QString decrypt(QString , QString );
QLineEdit* pw;
QTextEdit* text;
QTextEdit *ausgabe;
QPushButton *krypt;
QPushButton *entkrypt;
private slots:
void kryptn();
void entkryptn();
};
#endif
Code: Alles auswählen
#include "KryptEnt.h"
#include <QString>
#include <QMessageBox>
KryptEnt::KryptEnt( QWidget *parent): QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout;
QHBoxLayout *ltext = new QHBoxLayout;
QVBoxLayout *lausgabe = new QVBoxLayout;
QVBoxLayout *lpw = new QVBoxLayout;
QVBoxLayout *but = new QVBoxLayout;
pw = new QLineEdit;
pw->setText("00000000000000000000");
text = new QTextEdit;
text->setText("0123456789ABCFGHIJKLMNOPQRSTUVWXYZ0123456789ABCFGHIJKLMNOPQRSTUVWXYZ");
ausgabe = new QTextEdit;
ausgabe->setLineWrapMode(QTextEdit::WidgetWidth);
ausgabe->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
pw->setEchoMode(QLineEdit::Password);
krypt = new QPushButton("encrypt->");
entkrypt = new QPushButton("decrypt->");
but->addWidget(krypt);
but->addWidget(entkrypt);
QGroupBox *methods = new QGroupBox(tr("Methods"));
methods->setLayout(but);
ltext->addWidget(text);
ltext->addWidget(methods);
lpw->addWidget(pw);
lausgabe->addWidget(ausgabe);
QGroupBox *gpw = new QGroupBox(tr("Please enter Password:"));
QGroupBox *gtext = new QGroupBox(tr("Enter text to encrypt/decrypt:"));
QGroupBox *gausgabe = new QGroupBox(tr("Encrypt/Decrypt text:"));
gpw->setLayout(lpw);
gtext->setLayout(ltext);
gausgabe->setLayout(lausgabe);
layout->addWidget(gpw);
layout->addWidget(gtext);
layout->addWidget(gausgabe);
connect( krypt, SIGNAL(clicked()), this, SLOT(kryptn()) );
connect( entkrypt, SIGNAL(clicked()), this, SLOT(entkryptn()) );
setLayout(layout);
setWindowTitle("EntKrypt");
}
//********************main-funktions*********************
QString KryptEnt::encrypt(QString begin, QString pw )
{
if(pw.size()<20)
{
QMessageBox::information( this, "Password Error", "The Password is to short(min. 20 chars)!", QMessageBox::Ok );
return "failed";
}
if(begin.size()<pw.size())
{
QString msg = QString("The text is to short(min. %1 chars)!").arg( QString::number(pw.size()) );
QMessageBox::information( this,"Text Error", msg, QMessageBox::Ok );
return "failed";
}
QString out;
for(int i=0; i < pw.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ pw.at(i).toAscii());
out.append(c);
}
for(int i = pw.size(); i < begin.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ begin.at(i - pw.size()).toAscii());
out.append(c);
}
return out;
}
QString KryptEnt::decrypt(QString begin, QString pw)
{
QString out;
for(int i=0; i < pw.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ pw.at(i).toAscii());
out.append(c);
}
for(int i = pw.size(); i < begin.size(); i++)
{
QChar c = QChar(begin.at(i).toAscii() ^ out.at(i - pw.size()).toAscii());
out.append(c);
}
return out;
}
//****************own solts********************************
void KryptEnt::kryptn()
{
ausgabe->setText( encrypt( text->toPlainText(), pw->text() ) );
}
void KryptEnt::entkryptn()
{
ausgabe->setText( decrypt( text->toPlainText(), pw->text() ) );
}
ja ich weiss mein englisch und meine variablen nameswahl sind grausam -.-