I am currently trying to reimplement a paper I read about neural net cryptanalysis. The paper claims to use a 128-256-256-128 Cascade-Feed-Forward net for cryptanalysis of DES. I think the term is MatLab specific - see their documentation about it (https://www.mathworks.com/help/deeplearning/ref/cascadeforwardnet.html).
It's basically a network where each layer connects to every input in the following layers below.
I wanted to implement this in Tensorflow 2, but I am not quite experienced with it. Should I just concatenate every output tensor like in this clumsy example I made below?
import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense class CascadeNet(tf.keras.Model): def __init__(self): super(CascadeNet, self).__init__() self.layer1 = Dense(128, activation='relu', input_shape=(64,)) self.layer2 = Dense(256, activation='relu', input_shape=(128,)) self.layer3 = Dense(256, activation='relu', input_shape=(128 + 256,)) self.layer4 = Dense(128, activation='relu', input_shape=(128 + 256 * 2,)) self.out_layer = Dense(64, activation='sigmoid', input_shape=(128 * 2 + 256 * 2,)) def call(self, input): result1 = self.layer1(input) result2 = self.layer2(result1) tmp_result = tf.concat((result1, result2), axis=1) result3 = self.layer3(tmp_result) tmp_result = tf.concat((tmp_result, result3), axis=1) result4 = self.layer4(tmp_result) tmp_result = tf.concat((tmp_result, result4), axis=1) return self.out_layer(tmp_result)
The input as well as the outputs are 64 bits. I encoded them as int8.
There is also this Reddit thread where the topic got discussed: https://www.reddit.com/r/crypto/comments/7m4g6e/des_neural_cryptanalysis_by_m_alani/. Somebody tried to implement it in PyTorch (https://gist.github.com/sorrge/4460c251081a833fee9d03913e6debb0)
Is this the same what MatLab and the linked PyTorch implementation does?
Is the code somewhat correct?
How can you improve it?
About the usefulnes of this network architecture:
In the reddit post they doubt the usefulness of the network architecture and I think I can confirm that. What is your opinion about it?