github.com/jiajun1992/watercarver@v0.0.0-20191031150618-dfc2b17c0c4a/StadiumForWaterCarver/src/CipherTable.cpp (about) 1 #include "CipherTable.h" 2 3 #include "Functions.h" 4 5 CipherTable::CipherTable() : m_(0), n_(0), owner_(true) {} 6 7 CipherTable::CipherTable(string& ciphers, long m, ElGammal* elgammal) : m_(m), owner_(true) { 8 Functions::parse_ciphers(ciphers, m, C_, elgammal); 9 10 if (m == 0) { 11 n_ = 0; 12 } else { 13 n_ = C_.at(0)->size(); 14 } 15 } 16 17 CipherTable::CipherTable(vector<vector<Cipher_elg>* >* ciphers, long m): m_(m), owner_(false) { 18 C_ = *ciphers; 19 if (m == 0) { 20 n_ = 0; 21 } else { 22 n_ = C_.at(0)->size(); 23 } 24 } 25 26 CipherTable::~CipherTable() { 27 if (owner_) { 28 for (unsigned int i = 0; i < C_.size(); i++) { 29 delete C_.at(i); 30 } 31 32 for (unsigned int i = 0; i < elements_.size(); i++) { 33 delete elements_.at(i); 34 } 35 } 36 } 37 38 39 vector<vector<Cipher_elg>* >* CipherTable::getCMatrix() { 40 return &C_; 41 } 42 43 vector<vector<Mod_p>* >* CipherTable::getElementsMatrix() { 44 return &elements_; 45 } 46 47 string CipherTable::getCipher(int i, int j) { 48 stringstream cipher_str; 49 cipher_str << C_.at(i)->at(j); 50 return cipher_str.str(); 51 } 52 53 Cipher_elg& CipherTable::get_elg_cipher(int i, int j) { 54 return C_.at(i)->at(j); 55 } 56 57 string CipherTable::getElement(int i, int j) { 58 stringstream cipher_str; 59 cipher_str << elements_.at(i)->at(j); 60 return cipher_str.str(); 61 } 62 63 string CipherTable::encode_all_ciphers() { 64 return Functions::ciphers_to_str(&C_); 65 } 66 67 int CipherTable::rows() { 68 return m_; 69 } 70 71 int CipherTable::cols() { 72 return n_; 73 } 74 75 void CipherTable::set_dimentions(int m, int n) { 76 m_ = m; 77 n_ = n; 78 }