-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Ashitemaru/Sharnn
- Loading branch information
Showing
17 changed files
with
470 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,9 @@ | |
cmake-build-*/ | ||
bin/ | ||
build/ | ||
<<<<<<< HEAD | ||
.vscode/* | ||
assess | ||
======= | ||
.vscode/ | ||
>>>>>>> origin/master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,3 @@ ADD_TEST(test1) | |
ADD_TEST(test2) | ||
ADD_TEST(test3) | ||
ADD_TEST(test4) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
#pragma once | ||
|
||
#include "NonLinear.hpp" | ||
#include "RNN.hpp" | ||
#include "SpongeHash.hpp" | ||
|
||
class RNNHash : public SpongeHash<136, 64, 10> { | ||
public: | ||
RNNHash() : SpongeHash(HM_t{}) { | ||
} | ||
~RNNHash() override = default; | ||
void sponge_F(HM_t &h, uint32_t km) override { | ||
DSTChaoticSystem cs(cs_q, km, cs_ks, cs_us); | ||
RNN<200> rnn{&cs}; | ||
NonLinear<10, 50> nl{nl_nr, &cs}; | ||
|
||
rnn.forward(h, wo); | ||
nl.forward(wo, out); | ||
|
||
for (int i = 0; i < 50; i++) { | ||
h.ptr()[i * 4 + 0] = (out[i] & 0xFF000000) >> 24; | ||
h.ptr()[i * 4 + 1] = (out[i] & 0x00FF0000) >> 16; | ||
h.ptr()[i * 4 + 2] = (out[i] & 0x0000FF00) >> 8; | ||
h.ptr()[i * 4 + 3] = (out[i] & 0x000000FF); | ||
} | ||
} | ||
|
||
private: | ||
const static uint32_t cs_q = 0x789ABCDE, cs_ks = 0x10, cs_us = 10, | ||
nl_nr = 8; | ||
uint32_t wo[10]{}, out[50]{}; | ||
#pragma once | ||
|
||
#include "NonLinear.hpp" | ||
#include "RNN.hpp" | ||
#include "SpongeHash.hpp" | ||
|
||
class RNNHash : public SpongeHash<136, 64, 10> { | ||
public: | ||
RNNHash() : SpongeHash(HM_t{}) { | ||
} | ||
~RNNHash() override = default; | ||
void sponge_F(HM_t &h, uint32_t km) override { | ||
DSTChaoticSystem cs(cs_q, km, cs_ks, cs_us); | ||
RNN<200> rnn{&cs}; | ||
NonLinear<10, 50> nl{nl_nr, &cs}; | ||
|
||
rnn.forward(h, wo); | ||
nl.forward(wo, out); | ||
|
||
for (int i = 0; i < 50; i++) { | ||
h.ptr()[i * 4 + 0] = (out[i] & 0xFF000000) >> 24; | ||
h.ptr()[i * 4 + 1] = (out[i] & 0x00FF0000) >> 16; | ||
h.ptr()[i * 4 + 2] = (out[i] & 0x0000FF00) >> 8; | ||
h.ptr()[i * 4 + 3] = (out[i] & 0x000000FF); | ||
} | ||
} | ||
|
||
private: | ||
const static uint32_t cs_q = 0x789ABCDE, cs_ks = 0x10, cs_us = 10, | ||
nl_nr = 8; | ||
uint32_t wo[10]{}, out[50]{}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gen: | ||
g++ sample.cpp -o main | ||
# ./main |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const int block_size {136}; | ||
const int filp_count {10000}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <fstream> | ||
#include <random> | ||
#include <chrono> | ||
#include <vector> | ||
#include <iostream> | ||
#include <algorithm> | ||
|
||
#include "../src/RNNHash.hpp" | ||
#include "../include/define.h" | ||
|
||
const int flip_count {10000}; | ||
|
||
|
||
void flip_test() { | ||
std::ifstream s {"text.in", std::ifstream::binary}; | ||
std::ofstream record {"diffusion.out"}; | ||
std::stringstream ssbuf; | ||
ssbuf << s.rdbuf(); | ||
auto stream {ssbuf.str()}; | ||
|
||
auto buf = new byte[stream.size()]; | ||
std::copy(stream.begin(), stream.end(), buf); | ||
std::cerr << buf << std::endl; | ||
|
||
std::random_device dev; | ||
std::mt19937 rng(dev()); | ||
std::uniform_int_distribution<std::mt19937::result_type> byte_dist(0, stream.size() - 1); | ||
std::uniform_int_distribution<std::mt19937::result_type> bit_dist(0, 7); | ||
|
||
RNNHash h; | ||
RNNHash::Out_t original = h(ssbuf); | ||
// record << stream << std::endl; | ||
// record << original.to_binary_string() << std::endl << std::endl; | ||
|
||
|
||
for (int i = 0; i < flip_count; i++) { | ||
auto bit_r {bit_dist(rng)}; | ||
auto byte_r {byte_dist(rng)}; | ||
auto byte_buf = buf + byte_r; | ||
|
||
*byte_buf = ~ ((*byte_buf) | (0xff ^ (1 << bit_r))) | ((*byte_buf) & (0xff ^ (1 << bit_r))); | ||
|
||
std::stringstream input; | ||
std::string new_stream {(char *)buf}; | ||
input.str(new_stream); | ||
|
||
RNNHash hash; | ||
RNNHash::Out_t out = hash(input); | ||
// std::cerr << new_stream << std::endl; | ||
// record << "flip byte: " << byte_r << "; bit: " << bit_r << std::endl; | ||
// record << out.to_binary_string() << std::endl; | ||
out ^= original; | ||
record << out.one_count() << std::endl; | ||
// if (out.one_count() == 0) { | ||
// std::fstream opt {"1.bin"}; | ||
// std::ofstream ori{"2.bin"}; | ||
// opt << new_stream << std::endl; | ||
// ori << stream << std::endl; | ||
// exit(0); | ||
// } | ||
|
||
*byte_buf = ~ ((*byte_buf) | (0xff ^ (1 << bit_r))) | ((*byte_buf) & (0xff ^ (1 << bit_r))); | ||
} | ||
|
||
} | ||
|
||
int main() { | ||
|
||
flip_test(); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.