Skip to content

Commit 2feb1ad

Browse files
committed
Merge branch 'release/v0.2.0'
2 parents 8ef6646 + 658d2a7 commit 2feb1ad

File tree

11 files changed

+273
-268
lines changed

11 files changed

+273
-268
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build/
2+
pkg/

MrHash.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ FORMS += mainwindow.ui about.ui
3333

3434
RESOURCES += res/icon.qrc
3535

36-
TRANSLATIONS = t1_it.ts qt_it.ts
36+
# Coming soon...
37+
#TRANSLATIONS = t1_it.ts qt_it.ts
3738

3839
########################### CONFIGURATION ############################
3940
CONFIG += c++14

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# mrhash
2-
Mr. Hash is a program that calculates many hash strings (MD4, MD5, SHA1, SHA256, SHA384, SHA512, Tiger, HAVAL, RIPE-MD, CRC32...) of a given text.
1+
# Mr. Hash
2+
Mr. Hash calculates in real-time many hash strings of a given text.
3+
4+
![](http://img.shields.io/badge/version-v0.2.0-red.svg?style=flat) ![](https://img.shields.io/badge/platform-windows | linux | mac-yellow.svg?style=flat) ![](http://img.shields.io/badge/architecture-x86 | x64-green.svg?style=flat) ![](http://img.shields.io/badge/license-GPL%20v2-blue.svg?style=flat)
5+
6+
## Screenshots
7+
![](/doc/img/screenshot.png)
8+
9+
## Supported Algorithms
10+
11+
+ MD4
12+
+ MD5
13+
+ SHA
14+
+ SHA1
15+
+ SHA-224
16+
+ SHA-256
17+
+ SHA-384
18+
+ SHA-512
19+
+ SHA3
20+
+ SHA3-224
21+
+ SHA3-256
22+
+ SHA3-384
23+
+ SHA3-512
24+
+ Tiger
25+
+ HAVAL
26+
+ RIPEMD
27+
+ CRC16
28+
+ CRC32
29+

doc/img/screenshot.png

73.9 KB
Loading

include/crc32.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace CRC32 {
55
extern int* crc_table;
66
int* generate_table();
77
int reflect(int data, int bits);
8-
int crc32(int crc, const char* data, int length);
8+
int crc32(int crc, const char* data, unsigned int length);
99
}
1010

1111
#endif // _CRC32_H_

src/about.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
#include <QDesktopWidget>
2+
13
#include "about.hpp"
24

35
About::About( QWidget* parent ) : QDialog( parent ) {
46
setupUi( this );
7+
this->setFixedSize( this->size() );
8+
this->setGeometry( QStyle::alignedRect( Qt::LeftToRight, Qt::AlignCenter, this->size(),
9+
qApp->desktop()->availableGeometry() ) );
10+
tabWidget->setCurrentIndex( 0 );
11+
versionLabel->setText( QString("v%1.%2.%3").arg(MAJOR_VER).arg(MINOR_VER).arg(PATCH_VER) );
512
}
613

714
About::~About() {}

src/crc32.cpp

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,36 @@
33
int* CRC32::crc_table;
44

55
int* CRC32::generate_table() {
6-
int crc;
7-
int* table = new int[256];
8-
for(int i = 0; i < 256; i++) {
9-
crc = i << 24;
10-
for(int j = 0; j < 8; j++) {
11-
if(crc & 0x80000000) {
12-
crc = (crc << 1) ^ 0x04c11db7;
13-
} else {
14-
crc = crc << 1;
15-
}
16-
}
17-
table[i] = crc;
18-
}
19-
return table;
6+
int crc;
7+
int* table = new int[256];
8+
for ( int i = 0; i < 256; i++ ) {
9+
crc = i << 24;
10+
for ( int j = 0; j < 8; j++ ) {
11+
if ( crc & 0x80000000 )
12+
crc = ( crc << 1 ) ^ 0x04c11db7;
13+
else
14+
crc = crc << 1;
15+
}
16+
table[i] = crc;
17+
}
18+
return table;
2019
}
2120

22-
int CRC32::reflect(int data, int bits) {
23-
int x = 0;
24-
for(int i = 0; i < bits; i++) {
25-
x = x << 1;
26-
x |= data & 1;
27-
data = data >> 1;
28-
}
29-
return x;
21+
int CRC32::reflect( int data, int bits ) {
22+
int x = 0;
23+
for ( int i = 0; i < bits; i++ ) {
24+
x = x << 1;
25+
x |= data & 1;
26+
data = data >> 1;
27+
}
28+
return x;
3029
}
3130

32-
33-
int CRC32::crc32(int crc, const char* data, int length) {
34-
crc = ~reflect(crc, 32);
35-
if(!crc_table) {
36-
crc_table = generate_table();
37-
}
38-
for (int i = 0; i < length; i++) {
39-
crc = (crc << 8) ^ crc_table[((crc >> 24) ^ reflect(data[i], 8)) & 0xff];
40-
}
41-
return ~reflect(crc, 32);
31+
int CRC32::crc32( int crc, const char* data, unsigned int length ) {
32+
crc = ~reflect( crc, 32 );
33+
if ( !crc_table )
34+
crc_table = generate_table();
35+
for ( unsigned int i = 0; i < length; ++i )
36+
crc = ( crc << 8 ) ^ crc_table[( ( crc >> 24 ) ^ reflect( data[i], 8 ) ) & 0xff];
37+
return ~reflect( crc, 32 );
4238
}

src/globalstuff.cpp

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,35 @@
1717

1818
using std::string;
1919

20-
string charToHex(const char *buf, unsigned int len)
21-
{
22-
// Hm, can be optimized... :)
23-
unsigned int i;
24-
string ret;
25-
char tmp[3], cur;
26-
27-
for (i = 0; i < len; ++i) {
28-
cur = *(buf + i);
29-
if (cur == 0) {
30-
ret += "00";
31-
} else {
32-
sprintf(tmp, "%X", 0xFF & *(buf + i));
33-
if (strlen(tmp) == 1)
34-
ret += '0';
35-
ret += tmp;
36-
}
37-
}
38-
39-
return ret;
20+
string charToHex( const char* buf, unsigned int len ) {
21+
// Hm, can be optimized... :)
22+
unsigned int i;
23+
string ret;
24+
char tmp[3], cur;
25+
26+
for ( i = 0; i < len; ++i ) {
27+
cur = *( buf + i );
28+
if ( cur == 0 )
29+
ret += "00";
30+
else {
31+
sprintf( tmp, "%X", 0xFF & *( buf + i ) );
32+
if ( strlen( tmp ) == 1 )
33+
ret += '0';
34+
ret += tmp;
35+
}
36+
}
37+
38+
return ret;
4039
}
4140

42-
unsigned int calcBufSize(struct stat file_stat)
43-
{
44-
unsigned int ret;
41+
unsigned int calcBufSize( struct stat file_stat ) {
42+
unsigned int ret;
4543

46-
ret = file_stat.st_size;
47-
if (ret < 100000)
48-
ret = 100000;
49-
else if (ret > 200000)
50-
ret = 200000;
44+
ret = file_stat.st_size;
45+
if ( ret < 100000 )
46+
ret = 100000;
47+
else if ( ret > 200000 )
48+
ret = 200000;
5149

52-
return ret;
50+
return ret;
5351
}

src/mainwindow.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,18 @@ MainWindow::MainWindow( QWidget* parent ) : QMainWindow( parent ) {
3232
this->setFixedSize( this->size() );
3333
this->setGeometry( QStyle::alignedRect( Qt::LeftToRight, Qt::AlignCenter, this->size(),
3434
qApp->desktop()->availableGeometry() ) );
35-
this->setWindowTitle("MrHash v" + QString::number(MAJOR_VER) + "." + QString::number(MINOR_VER));
35+
this->setWindowTitle( "MrHash v" + QString::number( MAJOR_VER ) + "." + QString::number( MINOR_VER ) );
3636

3737

3838
connect( actionAboutQt, SIGNAL( triggered() ), qApp, SLOT( aboutQt() ) );
3939
}
4040

4141
MainWindow::~MainWindow() {}
4242

43-
namespace Hex {
44-
static string digits = "0123456789abcdef";
45-
std::string hex( char* bin, int length ) {
46-
std::string s( length * 2, ' ' );
47-
for ( int i = 0; i < length; i++ ) {
48-
s[i * 2] = digits[( bin[i] >> 4 ) & 0xf];
49-
s[i * 2 + 1] = digits[bin[i] & 0xf];
50-
}
51-
return s;
52-
}
53-
std::string hex( int bin ) {
54-
std::string s( sizeof( int ) * 2, ' ' );
55-
for ( unsigned int i = 0; i < sizeof( int ) * 2; i++ ) {
56-
s[sizeof( int ) * 2 - 1 - i] = digits[bin & 0xf];
57-
bin = bin >> 4;
58-
}
59-
return s;
60-
}
61-
}
62-
6343
QString crc32( string msg ) {
6444
int crc32_ctx = CRC32::crc32( 0, msg.c_str(), msg.length() );
65-
return QString::fromStdString( Hex::hex( crc32_ctx ) ).toUpper();
45+
//note: right(8) removes the unneeded Fs that appear sometimes at the start of the crc32
46+
return QString::number(crc32_ctx, 16).right(8).toUpper();
6647
}
6748

6849
QString tiger( string msg ) {
@@ -84,7 +65,7 @@ void MainWindow::on_textEdit_textChanged() {
8465
QString haval224 = QString::fromStdString( hav.calcHaval( text, 224, 5 ) ).toLower();
8566
QString haval256 = QString::fromStdString( hav.calcHaval( text, 256, 5 ) ).toLower();
8667
QString base64 = textEdit->toPlainText().toUtf8().toBase64();
87-
crc16edit->setText( QString::number(qChecksum(text.c_str(), qstrlen(text.c_str()))) );
68+
crc16edit->setText( QString::number( qChecksum( text.c_str(), qstrlen( text.c_str() ) ) ) );
8869
crc32edit->setText( crc32( text ) );
8970
md4edit->setText( QCryptographicHash::hash( text.c_str(), QCryptographicHash::Md4 ).toHex() );
9071
md5edit->setText( QCryptographicHash::hash( text.c_str(), QCryptographicHash::Md5 ).toHex() );

0 commit comments

Comments
 (0)