Skip to content

Commit

Permalink
Merge branch 'release/v0.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Jun 12, 2015
2 parents 8ef6646 + 658d2a7 commit 2feb1ad
Show file tree
Hide file tree
Showing 11 changed files with 273 additions and 268 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
pkg/
3 changes: 2 additions & 1 deletion MrHash.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ FORMS += mainwindow.ui about.ui

RESOURCES += res/icon.qrc

TRANSLATIONS = t1_it.ts qt_it.ts
# Coming soon...
#TRANSLATIONS = t1_it.ts qt_it.ts

########################### CONFIGURATION ############################
CONFIG += c++14
Expand Down
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# mrhash
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.
# Mr. Hash
Mr. Hash calculates in real-time many hash strings of a given text.

![](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)

## Screenshots
![](/doc/img/screenshot.png)

## Supported Algorithms

+ MD4
+ MD5
+ SHA
+ SHA1
+ SHA-224
+ SHA-256
+ SHA-384
+ SHA-512
+ SHA3
+ SHA3-224
+ SHA3-256
+ SHA3-384
+ SHA3-512
+ Tiger
+ HAVAL
+ RIPEMD
+ CRC16
+ CRC32

Binary file added doc/img/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion include/crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace CRC32 {
extern int* crc_table;
int* generate_table();
int reflect(int data, int bits);
int crc32(int crc, const char* data, int length);
int crc32(int crc, const char* data, unsigned int length);
}

#endif // _CRC32_H_
7 changes: 7 additions & 0 deletions src/about.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#include <QDesktopWidget>

#include "about.hpp"

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

About::~About() {}
60 changes: 28 additions & 32 deletions src/crc32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,36 @@
int* CRC32::crc_table;

int* CRC32::generate_table() {
int crc;
int* table = new int[256];
for(int i = 0; i < 256; i++) {
crc = i << 24;
for(int j = 0; j < 8; j++) {
if(crc & 0x80000000) {
crc = (crc << 1) ^ 0x04c11db7;
} else {
crc = crc << 1;
}
}
table[i] = crc;
}
return table;
int crc;
int* table = new int[256];
for ( int i = 0; i < 256; i++ ) {
crc = i << 24;
for ( int j = 0; j < 8; j++ ) {
if ( crc & 0x80000000 )
crc = ( crc << 1 ) ^ 0x04c11db7;
else
crc = crc << 1;
}
table[i] = crc;
}
return table;
}

int CRC32::reflect(int data, int bits) {
int x = 0;
for(int i = 0; i < bits; i++) {
x = x << 1;
x |= data & 1;
data = data >> 1;
}
return x;
int CRC32::reflect( int data, int bits ) {
int x = 0;
for ( int i = 0; i < bits; i++ ) {
x = x << 1;
x |= data & 1;
data = data >> 1;
}
return x;
}


int CRC32::crc32(int crc, const char* data, int length) {
crc = ~reflect(crc, 32);
if(!crc_table) {
crc_table = generate_table();
}
for (int i = 0; i < length; i++) {
crc = (crc << 8) ^ crc_table[((crc >> 24) ^ reflect(data[i], 8)) & 0xff];
}
return ~reflect(crc, 32);
int CRC32::crc32( int crc, const char* data, unsigned int length ) {
crc = ~reflect( crc, 32 );
if ( !crc_table )
crc_table = generate_table();
for ( unsigned int i = 0; i < length; ++i )
crc = ( crc << 8 ) ^ crc_table[( ( crc >> 24 ) ^ reflect( data[i], 8 ) ) & 0xff];
return ~reflect( crc, 32 );
}
56 changes: 27 additions & 29 deletions src/globalstuff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,35 @@

using std::string;

string charToHex(const char *buf, unsigned int len)
{
// Hm, can be optimized... :)
unsigned int i;
string ret;
char tmp[3], cur;

for (i = 0; i < len; ++i) {
cur = *(buf + i);
if (cur == 0) {
ret += "00";
} else {
sprintf(tmp, "%X", 0xFF & *(buf + i));
if (strlen(tmp) == 1)
ret += '0';
ret += tmp;
}
}

return ret;
string charToHex( const char* buf, unsigned int len ) {
// Hm, can be optimized... :)
unsigned int i;
string ret;
char tmp[3], cur;

for ( i = 0; i < len; ++i ) {
cur = *( buf + i );
if ( cur == 0 )
ret += "00";
else {
sprintf( tmp, "%X", 0xFF & *( buf + i ) );
if ( strlen( tmp ) == 1 )
ret += '0';
ret += tmp;
}
}

return ret;
}

unsigned int calcBufSize(struct stat file_stat)
{
unsigned int ret;
unsigned int calcBufSize( struct stat file_stat ) {
unsigned int ret;

ret = file_stat.st_size;
if (ret < 100000)
ret = 100000;
else if (ret > 200000)
ret = 200000;
ret = file_stat.st_size;
if ( ret < 100000 )
ret = 100000;
else if ( ret > 200000 )
ret = 200000;

return ret;
return ret;
}
27 changes: 4 additions & 23 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,18 @@ MainWindow::MainWindow( QWidget* parent ) : QMainWindow( parent ) {
this->setFixedSize( this->size() );
this->setGeometry( QStyle::alignedRect( Qt::LeftToRight, Qt::AlignCenter, this->size(),
qApp->desktop()->availableGeometry() ) );
this->setWindowTitle("MrHash v" + QString::number(MAJOR_VER) + "." + QString::number(MINOR_VER));
this->setWindowTitle( "MrHash v" + QString::number( MAJOR_VER ) + "." + QString::number( MINOR_VER ) );


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

MainWindow::~MainWindow() {}

namespace Hex {
static string digits = "0123456789abcdef";
std::string hex( char* bin, int length ) {
std::string s( length * 2, ' ' );
for ( int i = 0; i < length; i++ ) {
s[i * 2] = digits[( bin[i] >> 4 ) & 0xf];
s[i * 2 + 1] = digits[bin[i] & 0xf];
}
return s;
}
std::string hex( int bin ) {
std::string s( sizeof( int ) * 2, ' ' );
for ( unsigned int i = 0; i < sizeof( int ) * 2; i++ ) {
s[sizeof( int ) * 2 - 1 - i] = digits[bin & 0xf];
bin = bin >> 4;
}
return s;
}
}

QString crc32( string msg ) {
int crc32_ctx = CRC32::crc32( 0, msg.c_str(), msg.length() );
return QString::fromStdString( Hex::hex( crc32_ctx ) ).toUpper();
//note: right(8) removes the unneeded Fs that appear sometimes at the start of the crc32
return QString::number(crc32_ctx, 16).right(8).toUpper();
}

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

0 comments on commit 2feb1ad

Please sign in to comment.