<p>I'm not quite sure it's possible. Hash functions are used to map an input to an output in a way that is not reversible. </p>

<p>Many companies store a hash of your password on their servers so in case of a security breach they haven't given the adversaries a long list of passwords. </p>

<p>As far as it goes for finding the exact hash of a word, it seems infeasible. </p>

<p>Edit: Binary classification refers to the possible output being two possible states. A ten dimensional one-hot vector is not binary.</p>

CC BY-SA 3.0
2018-04-09T16:14:14.970Z
I figured out that it isn't binary classification and I try currently to understand NN but I will not warm up with the predictions...
Flajt
CC BY-SA 3.0
2018-02-16T13:57:45.773Z
2018-02-16T14:43:56.487Z
2018-02-16T14:43:56.487Z
Daniel
<p>My goal is to build a neural net that can find patterns between a hash and a word on it's own. So that it returns the word of any hash that I will input. </p>

<p>Unfortunatally my skill in the area of neural net isn´t advanced, and I want to use this project to learn more. So I use a German dictionary and encode it via <code>one_hot</code> encoding. Then I generate the <code>sha256</code> value of every word inside (before I have done this I cleaned the file and wrote every word in another line) it. So I got an big array with the shape of 20000x20000 for the words and another for the hashs. </p>

<p>So then I used the a example of the Keras homepage for <code>binary classification</code> because the one_hot values are represented by ones and zeros.</p>

<p>So if I want to predict a hashs I get these error: <code>Error when checking : expected dense_1_input to have shape (20000,) but got array with shape (1,)</code>. So I don't know if this model is working for my problem but I couldn't convert one hash into a size of 20000x20000. (The hash will <code>one_hot</code> encoded for that prediction). So how could I get it to accept different shaped hashs/one hash only?  </p>

<p>Is there a way to train the model with each hash after another for example with a for loop?!<br>
EDIT: So I figured out that I can convert a list of characters into a numpy.array with 2 dimensions. So I <code>hot_encoded</code> every character and create a list of them, these list I passed inside the <code>np.array(words,ndim=2)</code>. So this I have done for my hashs aswell. Then after I run the code I got this error: <code>ValueError: setting an array element with a sequence</code> So I tried to reshape the array with the <code>.reshape(20000)</code> command but nothing chaged. So what to do with that? EDIT2: I figured out now that the problem is that <code>enhot_encoding</code> generates diffrent sized "arrays" for each word, and if I fill this into a real array and this into a neuronal net it have to return this error. But still the question is: How to convert single words and hashs to a format that I can train a neuronal net with and get usefull output so I can enter any hash and it should return some kind of word(lable). If you need the actual code please inform me and I will upload it`s current state.
Code:  </p>

<pre><code>model = Sequential()
model.add(Dense(64, input_shape=20000, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dense(units=64, activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(19957, activation='sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='rmsprop', metrics=['accuracy'])
print("Fitting data...")
model.fit(test_hashs,test_words ,epochs=10,batch_size=128, verbose=1)


train_y=input("Input a hash that is not contained in the training data: ")
#train_x=pd.Series(hashlib.sha256(str.encode(train_y)).hexdigest())
train_y=pd.Series(train_y)
#test_x=pd.get_dummies(train_x)
test_y=pd.get_dummies(train_y)
model.save("first_test")
print(model.evaluate(test_y))
#score=model.evaluate(test_x, test_y, batch_size=128,)
print("Score: "+score)
prediction=model.predict(test_x,verbose=1)
for i in prediction:
    print(i)
</code></pre>

<unsupervised-learning><keras><python>
Keras pattern finding between hash and word
Flajt
# Keras pattern finding between hash and word

(Asked by: username_0 on 2018-01-26)

My goal is to build a neural net that can find patterns between a hash and a word on it's own. So that it returns the word of any hash that I will input. 
Unfortunatally my skill in the area of neural net isn´t advanced, and I want to use this project to learn more. So I use a German dictionary and encode it via one_hot encoding. Then I generate the sha256 value of every word inside (before I have done this I cleaned the file and wrote every word in another line) it. So I got an big array with the shape of 20000x20000 for the words and another for the hashs. 
So then I used the a example of the Keras homepage for binary classification because the one_hot values are represented by ones and zeros.
So if I want to predict a hashs I get these error: Error when checking : expected dense_1_input to have shape (20000,) but got array with shape (1,). So I don't know if this model is working for my problem but I couldn't convert one hash into a size of 20000x20000. (The hash will one_hot encoded for that prediction). So how could I get it to accept different shaped hashs/one hash only?  
Is there a way to train the model with each hash after another for example with a for loop?!
EDIT: So I figured out that I can convert a list of characters into a numpy.array with 2 dimensions. So I hot_encoded every character and create a list of them, these list I passed inside the np.array(words,ndim=2). So this I have done for my hashs aswell. Then after I run the code I got this error: ValueError: setting an array element with a sequence So I tried to reshape the array with the .reshape(20000) command but nothing chaged. So what to do with that? EDIT2: I figured out now that the problem is that enhot_encoding generates diffrent sized "arrays" for each word, and if I fill this into a real array and this into a neuronal net it have to return this error. But still the question is: How to convert single words and hashs to a format that I can train a neuronal net with and get usefull output so I can enter any hash and it should return some kind of word(lable). If you need the actual code please inform me and I will upload it`s current state.
Code:  
model = Sequential()
model.add(Dense(64, input_shape=20000, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dense(units=64, activation="relu"))
model.add(Dropout(0.5))
model.add(Dense(19957, activation='sigmoid'))
model.compile(loss='binary_crossentropy',optimizer='rmsprop', metrics=['accuracy'])
print("Fitting data...")
model.fit(test_hashs,test_words ,epochs=10,batch_size=128, verbose=1)


train_y=input("Input a hash that is not contained in the training data: ")
#train_x=pd.Series(hashlib.sha256(str.encode(train_y)).hexdigest())
train_y=pd.Series(train_y)
#test_x=pd.get_dummies(train_x)
test_y=pd.get_dummies(train_y)
model.save("first_test")
print(model.evaluate(test_y))
#score=model.evaluate(test_x, test_y, batch_size=128,)
print("Score: "+score)
prediction=model.predict(test_x,verbose=1)
for i in prediction:
    print(i)

**Tags:** unsupervised-learning, keras, python


---

## 1 answers

### Answer by username_1 on 2018-02-16. Score: 1 | Accepted answer

I'm not quite sure it's possible. Hash functions are used to map an input to an output in a way that is not reversible.

Many companies store a hash of your password on their servers so in case of a security breach they haven't given the adversaries a long list of passwords.

As far as it goes for finding the exact hash of a word, it seems infeasible.

Edit: Binary classification refers to the possible output being two possible states. A ten dimensional one-hot vector is not binary.

> **Comments:**
> **username_0**: I figured out that it isn't binary classification and I try currently to understand NN but I will not warm up with the predictions...  

---

