Skip to content

Commit

Permalink
Discarded some unecessary and log-oriented precautions on io interfac…
Browse files Browse the repository at this point in the history
…e and added mixed random input source.

Former-commit-id: 43f2094
  • Loading branch information
Yuri da Silva Villas Boas committed Feb 6, 2017
1 parent cba883b commit 162bd56
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 9 deletions.
4 changes: 2 additions & 2 deletions decrypt/private_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Pub_Key Pri_Key::get_Public() const {
std::string Pri_Key::summary() const {
std::stringstream ret;
ret << std::endl;
ret << "NAME = " << _name << "_pub" << std::endl;
ret << "NAME = " << _name << "_pri" << std::endl;
ret << "K = " << _k << std::endl;
ret << "M = " << _m << std::endl;
ret << "P = " << _p << std::endl;
Expand All @@ -273,9 +273,9 @@ std::istream& operator >> (std::istream& key_file, Pri_Key& PRIVATE_KEY) {
line.find('#') != std::string::npos;
std::getline(key_file, line)
) {}
std::getline(key_file, line);
name = line.substr(0,line.rfind("_pri"));

std::getline(key_file, line);
k = stoi(line);

std::getline(key_file, line);
Expand Down
3 changes: 2 additions & 1 deletion encrypt/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#-I ../random_input/std/user_seed/ \
#-I ../random_input/std/random_device/ \
#-I ../random_input/std/pseudo_random \
#-I ../random_input/std/3_layers \

#in order to choose for different sources of random input. In the
#1st, you will be asked to enter a string of random characters of your keyboard.
Expand All @@ -26,7 +27,7 @@ g++ main.cpp \
-D __SHOW__ \
-D __PUT__ \
-lgmpxx -lgmp -lm \
-I ../random_input/std/user_seed/ \
-I ../random_input/std/3_layers/ \
-I ../ysvb-bug-proof/ \
-I ../integers/ \
-std=gnu++11 \
Expand Down
3 changes: 1 addition & 2 deletions integers/intgauss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ static GaussInt<GID> itopower (int exp);
}
friend std::istream& operator >> (std::istream& is, GaussInt<GID>& gi) {
GID real, imag;
if (is) { is >> real; }
if (is) { is >> imag; }
is >> real >> imag;
gi = GaussInt(real, imag);
return is;
}
Expand Down
4 changes: 1 addition & 3 deletions integers/public_msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ class t_public_msg : public std::deque<t_public_int> {
t_public_msg(int size = 0) : std::deque<t_public_int>(size) {}
friend std::istream& operator >> (std::istream& is, t_public_msg& tpm) {// { return this->mpz_class::
for (int i = 0, N = tpm.size(); i < N && is; i++) {
// YSVB_CHECK_1(is.good(), ==, true, "need to be good")
is >> tpm[i];
}
return is;
}
friend std::ostream& operator << (std::ostream& os, const t_public_msg& tpm) {// { return this->mpz_class::
for (int i = 0, N = tpm.size(); i < N; i++) {
os << tpm[i].gr() << std::endl;
os << tpm[i].gi() << std::endl;
os << tpm[i];
}
return os;
}
Expand Down
3 changes: 2 additions & 1 deletion key_gen/make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#-I ../random_input/std/user_seed/ \
#-I ../random_input/std/random_device/ \
#-I ../random_input/std/pseudo_random \
#-I ../random_input/std/3_layers \

#in order to choose for different sources of random input. In the
#1st, you will be asked to enter a string of random characters of your keyboard.
Expand All @@ -26,7 +27,7 @@ g++ main.cpp \
-D __SHOW__ \
-D __PUT__ \
-lgmpxx -lgmp -lm \
-I ../random_input/std/user_seed/ \
-I ../random_input/std/3_layers/ \
-I ../ysvb-bug-proof/ \
-I ../integers/ \
-I ../decrypt/ \
Expand Down
75 changes: 75 additions & 0 deletions random_input/std/3_layers/random_input.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef __RANDOM_INPUT_SOURCE__
#define __RANDOM_INPUT_SOURCE__

#include <chrono>
#include <random>
#include <iostream>

#define FNM 15 //FIRST NIBBLE
#define SNM 240 //SECOND NIBBLE MASK
#define RLS 256 //RANDOM LIMB SIZE
#define RLSMO 255 //RANDOM LIMB SIZE MINUS ONE
#define SRLS 65536 //SQUARED RANDOM LIMB SIZE
#define SRLSMO 65535 //SQUARED RANDOM LIMB SIZE MINUS ONE

class Random_Input_Source {
std::random_device _rd;
std::minstd_rand0 _generator;
public:
Random_Input_Source() {//: _generator(std::chrono::system_clock::now().time_since_epoch().count()) {
std::string user_input;
YSVB_TIMED_PUT("Please, enter a random string to serve as seed (avoid obvious stuff):")
std::getline(std::cin,user_input);
std::seed_seq user_seed (user_input.begin(),user_input.end());
_generator = std::minstd_rand0(user_seed);
}

t_int get(int n_limbs = 0, t_int initial = 0) {
int i;
// std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
for (i = 0; i < n_limbs; i++) {
_generator.discard(
(std::chrono::system_clock::now().time_since_epoch().count()+i)
& RLSMO
);

initial *= RLS;
std::uniform_int_distribution<int> distribution(0,RLSMO);
// initial += distribution(_generator);
initial += distribution(_generator) ^ _generator() & RLSMO;
}
return initial;
}
int get_int() {
_generator.discard(
std::chrono::system_clock::now().time_since_epoch().count()
& SRLSMO
);

// std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
std::uniform_int_distribution<int> distribution(0,RLSMO);
return distribution(_generator) ^ _generator() & RLSMO;
}
void get_c_str(char* c_str_data, int n) {
int i;
// std::default_random_engine generator(std::chrono::system_clock::now().time_since_epoch().count());
for (i = 0; i < n; i++) {
_generator.discard(
(std::chrono::system_clock::now().time_since_epoch().count()+i)
& RLSMO
);

std::uniform_int_distribution<int> distribution(0,RLSMO);
c_str_data[i] = distribution(_generator) ^ _generator() & RLSMO;
}
//Explanation
#if defined(__DBG__)
char a;
int b = 255;
a = b;
YSVB_CHECK_1(a, ==, -1, "This is to say: when an int is assigned to a char, what happens is that its last byte is assinged.")
#endif
}
};

#endif

0 comments on commit 162bd56

Please sign in to comment.