|
You last visited: Today at 01:32
Advertisement
[C++] Strings hashing
Discussion on [C++] Strings hashing within the C/C++ forum part of the Coders Den category.
08/24/2015, 20:58
|
#1
|
elite*gold: 0
Join Date: Jul 2015
Posts: 325
Received Thanks: 274
|
[C++] Strings hashing
Heyo Com,
Suche jemanden, der mir teilweise erklären oder auch nur auf den richtigen Pfad leiten kann, wie ich bei C++ meine Strings hashe.
Danke im voraus,
sL1nky
|
|
|
08/24/2015, 21:50
|
#2
|
elite*gold: 8
Join Date: Sep 2014
Posts: 625
Received Thanks: 178
|
Schritt 1: Hashing-Verfahren wählen.
|
|
|
08/24/2015, 22:17
|
#3
|
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
|
Schritt 2: Nach einer Bibliothek für Hashes oder sonstige Implementierungen gewählter Hash-Funktion suchen
(Tipp: SHA3 ist ganz gut für kryptographische Anforderungen, MurmurHash oder XXHash für Sachen, bei denen die Kollisionen weniger wichtig sind als die Geschwindigkeit)
Padmak
|
|
|
08/24/2015, 23:01
|
#4
|
elite*gold: 0
Join Date: Jul 2015
Posts: 325
Received Thanks: 274
|
kenne mich da ehrlich 0 aus :c
|
|
|
08/25/2015, 01:36
|
#5
|
elite*gold: 58
Join Date: Jun 2008
Posts: 2,311
Received Thanks: 8,420
|
Was hält dich davon ab, etwas zu recherchieren? Wir haben den Teil mit "auf den richtigen Pfad leiten" erfüllt, für den Rest bist du zuständig
Bisschen Motivation:
~ Hier war ein Video von Shia LaBeouf's "Just Do It!" ~
Padmak
|
|
|
08/25/2015, 11:34
|
#6
|
elite*gold: 198
Join Date: Mar 2011
Posts: 835
Received Thanks: 263
|
Library -> 
Kann: SHA-1, SHA-2 (SHA-224, SHA-256, SHA-384, and SHA-512), SHA-3, Tiger, WHIRLPOOL, RIPEMD-128, RIPEMD-256, RIPEMD-160, RIPEMD-320
Habs nicht getestet aber etwa so müsste es funktionieren.
Code:
#include <cryptopp/sha.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <string>
int main()
{
CryptoPP::SHA3 sha3;
std::string source = "Hello";
std::string hash = "";
CryptoPP::StringSource(source, true, new CryptoPP::HashFilter(sha3, new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))));
std::cout << "Unhashed: " << source << std::endl;
std::cout << "Hashed: " << hash << std::endl;
}
|
|
|
08/25/2015, 16:16
|
#7
|
elite*gold: 966
Join Date: Apr 2010
Posts: 1,105
Received Thanks: 681
|
Kommt natürlich auf den Anwendungsfall an, aber die STL bietet mit  bereits eine Möglichkeit Strings zu hashen.
Mit freundlichen Grüßen
Jeoni
|
|
|
09/01/2015, 16:04
|
#8
|
elite*gold: 0
Join Date: Aug 2015
Posts: 37
Received Thanks: 3
|
Quote:
int hash = 0;
int offset = 'a' - 1;
for(string::const_iterator it=s.begin(); it!=s.end(); ++it) {
hash = hash << 1 | (*it - offset);
}
|
This could work
|
|
|
10/02/2015, 21:51
|
#9
|
elite*gold: 0
Join Date: Sep 2015
Posts: 18
Received Thanks: 1
|
Quote:
Originally Posted by ƬheGame
Library -> 
Kann: SHA-1, SHA-2 (SHA-224, SHA-256, SHA-384, and SHA-512), SHA-3, Tiger, WHIRLPOOL, RIPEMD-128, RIPEMD-256, RIPEMD-160, RIPEMD-320
Habs nicht getestet aber etwa so müsste es funktionieren.
Code:
#include <cryptopp/sha.h>
#include <cryptopp/filters.h>
#include <cryptopp/hex.h>
#include <string>
int main()
{
CryptoPP::SHA3 sha3;
std::string source = "Hello";
std::string hash = "";
CryptoPP::StringSource(source, true, new CryptoPP::HashFilter(sha3, new CryptoPP::HexEncoder(new CryptoPP::StringSink(hash))));
std::cout << "Unhashed: " << source << std::endl;
std::cout << "Hashed: " << hash << std::endl;
}
|
Yeah it's great and also libtom can be useful too
Code:
//Hashes the input string using sha1
unsigned char* hSHA1(const std::string& input) {
hash_state hs;
sha1_init(&hs);
unsigned char* checksum = new unsigned char[sha1_desc.hashsize];
sha1_process(&hs, (const unsigned char*) input.c_str(), input.size());
sha1_done(&hs, checksum);
return checksum;
}
|
|
|
10/03/2015, 02:54
|
#10
|
elite*gold: 0
Join Date: Feb 2008
Posts: 2,754
Received Thanks: 1,748
|
Quote:
Originally Posted by xAxTer
Yeah it's great and also libtom can be useful too
Code:
//Hashes the input string using sha1
unsigned char* hSHA1(const std::string& input) {
hash_state hs;
sha1_init(&hs);
unsigned char* checksum = new unsigned char[sha1_desc.hashsize];
sha1_process(&hs, (const unsigned char*) input.c_str(), input.size());
sha1_done(&hs, checksum);
return checksum;
}
|
Well, I did not test it, but why do you use dynamic raw arrays?
Whoever uses this will probably (and thought futher pretty surely) forget to delete the dynamically crafted array which will cause if the hashing is used more often, which is absolutely possible heavy memory leaks.
It should work perfectly with an usual std::vector, locally created and copied (in this example, moving should work of course, too).
Code:
std::vector hSHA1(const std::string& input) {
hash_state hs;
sha1_init(&hs);
std::vector<unsigned char> checksum;
checksum.resize(sha1_desc.hashsize);
sha1_process(&hs, reinterpret_cast<const unsigned char*>(input.c_str()), input.size());
sha1_done(&hs, &checksum[0]);
return checksum;
}
I did not test this, but it should work. Correct me if I'm wrong.
But yet I think cryptopp is the better way to go. No specific reason then rather personal preference but why would you prefer to use C libraries instead of C++ ones when already programming in C++?
|
|
|
 |
Similar Threads
|
Bitcoin gegen Hashing power - Günstiger Bitcoin Cloud Mining Hoster
12/11/2014 - Freebies - 3 Replies
Hey! Auf der Suche nach einem fairen Bitcoin Cloud Mining Hoster bin ich auf folgende Seite gestoßen: Cloudmining-review.com/
Dort ist eine Übersicht mit Anbietern. Dadurch bin ich auf cloudhashinsercives gekommen echt ne tolle Seite!
Dort kann man seine Bitcoins gegen Hashingpower tauschen. Der Preis für 1 GH/s beträgt 0.0015 BTC. Der Vertrag läuft für 5 Jahre und es fallen keine weiteren Kosten an. Die Auszahling findet täglich statt. Bis jetzt habe ich nur gutes gelesen. Das erste...
|
[QUESTION]Hashing Password
12/02/2013 - Rappelz Private Server - 1 Replies
Welcome, if i want put password to sa like " password " i have to code it at md5 or another to put it onto authserver/gameserver.opt ??
Thanks, i forgot that one point ;-;
|
Looking for help with hashing (C#)
01/04/2013 - Rappelz Private Server - 7 Replies
Hello, everyone. I've been following this forum for some time. I never post because I can generally find what I'm looking for by searching the forum or by otherwise using web resources. I am however at a loss and thought I'd try my luck here on Epvp.
I'm writing a few tools in C# and I need a function to hash the names of rdb files. Since I have no clue where to start Thought I'd ask around.
I was using a tool that was given to me up until now but, as an example; When I try to hash...
|
PW encryption / hashing
05/09/2012 - Shaiya Private Server - 4 Replies
Is anyone here working on password encryption for the users_master table?
I just want to make sure I'm not duplicating effort.
I seem to only able to find bits an pieces about it with the search function.
|
[How To] Password Hashing
07/03/2011 - Shaiya PServer Development - 13 Replies
I wrote this during breakfast on my way to work so there isn't a ton of documentation along with it.
A quick answer to why storing passwords (in plain text) in a database is bad: Why are plain text passwords bad, and how do I convince my boss that his treasured websites are in jeopardy? - Stack Overflow
Here is what my .. looked like after I implemented password hashing:
http://a.imageshack.us/img261/2329/shaiyapsusersm aster.gif
As you can see I changed the data types on a few...
|
All times are GMT +1. The time now is 01:32.
|
|