-
Notifications
You must be signed in to change notification settings - Fork 0
/
strutil.cpp
73 lines (56 loc) · 1.66 KB
/
strutil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "strutil.h"
#include <QString>
#include <QStringList>
#include <QDebug>
QString formatNumber(const QString &c )
{
return QString ( "%L1" ).arg (c.toInt());
}
QString capitalizeName(const QString &text)
{
QString orig=text.toLower();
QStringList words = orig.split(QRegExp ( "\\W+" ), QString::SkipEmptyParts );
QString aux;
int wc=0;
foreach(QString w, words){
// if (wc>0) continue;
aux=w;
w[0] = w[0].toUpper();
if (w.toLower()=="de") w = w.toLower();
orig.replace ( QRegExp ( QString( "\\b(%1)\\b" ).arg ( aux ) ) , w );
wc++;
}
return orig.replace(QRegExp("^\\s*(\\w\\s*)$"), "\\1");
}
QByteArray unscrambleString(const QByteArray &pwd)
{
if((pwd.length()>0) && (pwd.length() % 2 == 0) ){
QByteArray bytes = QByteArray::fromHex(pwd);
char decbyte = bytes[0];
bytes.remove(0,1);
QByteArray pbytes;
pbytes.append(decbyte);
foreach(char byte , bytes){
pbytes.append(byte xor decbyte);
}
return pbytes;
}
return QByteArray();
}
//qDebug() << unscrambleString("3706075650425e5b524556");
//qDebug() << unscrambleString("721d1e1e1b1c1501061d1c1701");
//qDebug() << unscrambleString(scramblePassword(QObject::tr("á")));
QByteArray scrambleString(const QByteArray &pwd)
{
if(!pwd.isEmpty()){
QByteArray encString;
quint16 encByte = pwd.at(0);
encString.append(encByte);
for(int i=1; i<pwd.length(); i++){
quint16 curByte = pwd.at(i);
encString.append(curByte ^ encByte);
}
return encString.toHex();
}
return QByteArray();
}