From: eduardo.davila@creatis.insa-lyon.fr Date: Thu, 13 Jun 2024 06:25:57 +0000 (+0200) Subject: #3519 box std Encrypting X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=19b8f91e48a6b3224bc81ded2ffa0728ef3815ef;p=bbtk.git #3519 box std Encrypting --- diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 88cde13..342da2c 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -749,7 +749,7 @@ namespace bbtk { //printf("EED BlackBox::bbRecursiveExecute bbProcess start %s \n", bbGetFullName().c_str() ); - + //auto start = std::chrono::high_resolution_clock::now(); this->bbProcess(); //auto stop = std::chrono::high_resolution_clock::now(); diff --git a/packages/std/src/bbstdAdd.xml b/packages/std/src/bbstdAdd.xml index a085e87..c12d9bc 100644 --- a/packages/std/src/bbstdAdd.xml +++ b/packages/std/src/bbstdAdd.xml @@ -3,7 +3,7 @@ laurent.guigues@creatis.insa-lyon.fr - Adds its inputs + (C++,Python) Adds its inputs math diff --git a/packages/std/src/bbstdEncrypting.cxx b/packages/std/src/bbstdEncrypting.cxx index f20d64d..c787af8 100644 --- a/packages/std/src/bbstdEncrypting.cxx +++ b/packages/std/src/bbstdEncrypting.cxx @@ -4,6 +4,8 @@ #include "bbstdEncrypting.h" #include "bbstdPackage.h" +#include "bbtkBlackBoxInputConnector.h" + #include #include @@ -12,6 +14,8 @@ namespace bbstd { +class Connection; + // // // https://stackoverflow.com/questions/66380465/c-encoding-decoding @@ -25,8 +29,6 @@ public: virtual std::string decode(std::string secret) = 0; }; - - class shift_encryptor : public encryptor { int shift; @@ -43,9 +45,20 @@ public: { // Your code starts here - char c_original[74] = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9','.',',',':',';','@','*','$','/','-','_','A','B','C','D','E','J','G','H','I','J', 'K','L','M','N','O','P','Q', 'R','S','T','U', 'V','W','X', 'Y','Z' }; - - + char c_original[73] = { + ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9', '.', ',', ':', + ';', '@', '*', '$', '/', '-', '_', 'A', 'B', 'C', + 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z' }; + + + + this->shift = this->shift % 73; + std::string original_result = ""; for (int i = 0; i < original.length(); i++) { @@ -70,7 +83,20 @@ public: std::string decode(std::string secret) { // Your code starts here - char c_secret[74] = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9','.',',',':',';','@','*','$','/','-','_','A','B','C','D','E','J','G','H','I','J', 'K','L','M','N','O','P','Q', 'R','S','T','U', 'V','W','X', 'Y','Z' }; + char c_secret[73] = { + ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9', '.', ',', ':', + ';', '@', '*', '$', '/', '-', '_', 'A', 'B', 'C', + 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z' }; + + + + this->shift = this->shift % 73; + std::string secret_result = ""; for (int i = 0; i < secret.length(); i++) { @@ -106,7 +132,16 @@ public: std::string encode(std::string original) { // Your code starts here - char c_original[74] = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9','.',',',':',';','@','*','$','/','-','_','A','B','C','D','E','J','G','H','I','J', 'K','L','M','N','O','P','Q', 'R','S','T','U', 'V','W','X', 'Y','Z' }; + char c_original[73] = { + ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9', '.', ',', ':', + ';', '@', '*', '$', '/', '-', '_', 'A', 'B', 'C', + 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z' }; + std::string original_result = ""; for (int i = 0; i < original.length(); i++) { @@ -128,7 +163,16 @@ public: std::string decode(std::string secret) { // Your code starts here - char c_secret[74] = { ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k', 'l', 'm', 'n', 'o', 'p', 'q','r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9','.',',',':',';','@','*','$','/','-','_','A','B','C','D','E','J','G','H','I','J', 'K','L','M','N','O','P','Q', 'R','S','T','U', 'V','W','X', 'Y','Z' }; + char c_secret[73] = { + ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', + 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', + '3', '4', '5', '6', '7', '8', '9', '.', ',', ':', + ';', '@', '*', '$', '/', '-', '_', 'A', 'B', 'C', + 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z' }; + std::string secret_result = ""; for (int i = 0; i < secret.length(); i++) { @@ -198,7 +242,7 @@ void Encrypting::Process() } if (bbGetInputType()==2) { - cypher_encryptor* crypter = new cypher_encryptor("04dw51CeVD23 67W89XYZASTBEfyhazlvjnktbogrumcpiqxs.,:;@*$/-_OHIPKLQRUJGJMNF"); + cypher_encryptor* crypter = new cypher_encryptor("04dw51CeVD23 67W89XYZASTBEfyhazlvjnktbogrumcpiqxs.,:;@*$/-_OHIPKLQRUJGMNF"); if (bbGetInputMode()==1) { bbSetOutputOut ( crypter->encode( bbGetInputIn() ) ); @@ -216,7 +260,36 @@ void Encrypting::Process() bbSetOutputOut ( encryptDecrypt( bbGetInputIn() ) ); } } - + + if (bbGetInputType()==4) + { + InputConnectorMapType::iterator i = bbGetInputConnectorMap().find("In"); + bbtk::Connection *c = i->second->GetConnection(); + int idchar1 = 0; + int idchar2 = 8; + int idcode = 8; + if (c!=NULL) + { + int pos = c->GetBlackBoxFrom()->bbGetFullName().find("<"); + std::string idstr1 = c->GetBlackBoxFrom()->bbGetFullName().substr(pos-2,2); + idchar1 = std::stoi( idstr1 ); + std::string idstr2 = c->GetBlackBoxFrom()->bbGetFullName().substr(pos-1,1); + idchar2 = idstr2.at(0); + idcode = idchar1 + idchar2; + } + + shift_encryptor* shiftTest = new shift_encryptor(idcode); + cypher_encryptor* crypter = new cypher_encryptor("04dw51CeVD23 67W89XYZASTBEfyhazlvjnktbogrumcpiqxs.,:;@*$/-_OHIPKLQRUJGMNF"); + if (bbGetInputMode()==1) + { + bbSetOutputOut ( shiftTest->encode( crypter->encode( bbGetInputIn() )) ); + } // if + if (bbGetInputMode()==2) + { + bbSetOutputOut ( crypter->decode( shiftTest->decode( bbGetInputIn() )) ); + } // if + } + /* encodeResult = shiftTest->encode("hello world"); diff --git a/packages/std/src/bbstdEncrypting.h b/packages/std/src/bbstdEncrypting.h index 85922e1..a8b53c7 100644 --- a/packages/std/src/bbstdEncrypting.h +++ b/packages/std/src/bbstdEncrypting.h @@ -37,7 +37,7 @@ BBTK_BEGIN_DESCRIBE_BLACK_BOX(Encrypting,bbtk::AtomicBlackBox); BBTK_CATEGORY("empty"); BBTK_INPUT(Encrypting,In,"Input string",std::string,""); BBTK_INPUT(Encrypting,Mode,"(default 0) 0:Nothing Type1: 0_Nothing 1_Encode 2_Decode Type2: 0_Nothing 1_Encode 2_Decode Type3: 0_Nothing 1:EncodeDecode",int,""); - BBTK_INPUT(Encrypting,Type,"(default 0) 0:Nothing 1:shiftTest(LowerCase) 2:cypher_encryptor(LowerCase) 3:EncodeDecode",int,""); + BBTK_INPUT(Encrypting,Type,"(default 0) 0:Nothing 1:shiftTest(LowerCase) 2:cypher_encryptor(LowerCase) 3:EncodeDecode 4:EncodeDecode2",int,""); BBTK_OUTPUT(Encrypting,Out,"Output string",std::string,""); BBTK_END_DESCRIBE_BLACK_BOX(Encrypting); //===== diff --git a/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx b/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx index 4117fdf..5c7eb64 100644 --- a/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx +++ b/packages/vtk/src/bbvtkRescaleSlopeIntercept.cxx @@ -149,7 +149,6 @@ void RescaleSlopeIntercept::Process() //===== void RescaleSlopeIntercept::bbUserSetDefaultValues() { - // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 bbSetInputIn(NULL); @@ -161,7 +160,8 @@ void RescaleSlopeIntercept::bbUserSetDefaultValues() filter2 = NULL; mchange = NULL; } -//===== + +//===== // Don't edit this file. This file is generated from xml description.. //===== void RescaleSlopeIntercept::bbUserInitializeProcessing() @@ -174,12 +174,12 @@ void RescaleSlopeIntercept::bbUserInitializeProcessing() filter2 = vtkImageShiftScale::New(); mchange = vtkImageChangeInformation::New(); } -//===== + +//===== // Don't edit this file. This file is generated from xml description.. //===== void RescaleSlopeIntercept::bbUserFinalizeProcessing() { - // THE FINALIZATION METHOD BODY : // Here does nothing // but this is where you should desallocate the internal/output pointers @@ -189,7 +189,6 @@ void RescaleSlopeIntercept::bbUserFinalizeProcessing() filter2->Delete(); } -} -// EO namespace bbvtk +}// EO namespace bbvtk