--- /dev/null
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+#include "bbstdEncrypting.h"
+#include "bbstdPackage.h"
+
+
+#include <iostream>
+#include <string>
+
+
+namespace bbstd
+{
+
+//
+//
+// https://stackoverflow.com/questions/66380465/c-encoding-decoding
+//
+//
+
+class encryptor
+{
+public:
+ virtual std::string encode(std::string original) = 0;
+ virtual std::string decode(std::string secret) = 0;
+};
+
+
+
+class shift_encryptor : public encryptor
+{
+ int shift;
+
+public:
+ shift_encryptor(int shift)
+ {
+ // Your code starts here
+ this->shift = shift;
+ // Your code ends here
+ }
+
+ 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' };
+
+
+ std::string original_result = "";
+ for (int i = 0; i < original.length(); i++)
+ {
+ int c_index = 0;
+ for (int j = 0; j < sizeof(c_original); j++)
+ {
+ if (original[i] == c_original[j])
+ {
+ c_index = j;
+ break;
+ }
+ }
+ int final_index = c_index + this->shift;
+ if (final_index > sizeof(c_original) - 1)
+ final_index -= sizeof(c_original);
+ original_result += c_original[final_index];
+ }
+ return original_result;
+ // Your code ends here
+ }
+
+ 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' };
+ std::string secret_result = "";
+ for (int i = 0; i < secret.length(); i++)
+ {
+ int c_index = 0;
+ for (int j = 0; j < sizeof(c_secret); j++)
+ {
+ if (secret[i] == c_secret[j])
+ {
+ c_index = j;
+ break;
+ }
+ }
+ int final_index = c_index - this->shift;
+ if (final_index < 0)
+ final_index += sizeof(c_secret);
+ secret_result += c_secret[final_index];
+ }
+ return secret_result;
+ // Your code ends here
+ }
+};
+
+class cypher_encryptor : public encryptor
+{
+ std::string cypher;
+public:
+ cypher_encryptor(std::string cypher)
+ {
+ // Your code starts here
+ this->cypher = cypher;
+ // Your code ends here
+ }
+ 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' };
+ std::string original_result = "";
+ for (int i = 0; i < original.length(); i++)
+ {
+ int c_index = 0;
+ for (int j = 0; j < this->cypher.length(); j++)
+ {
+ if (original[i] == this->cypher[j])
+ {
+ c_index = j;
+ break;
+ }
+ }
+ original_result += c_original[c_index];
+ }
+ return original_result;
+ // Your code ends here
+ }
+
+ 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' };
+ std::string secret_result = "";
+ for (int i = 0; i < secret.length(); i++)
+ {
+ int c_index = 0;
+ for (int j = 0; j < sizeof(c_secret); j++)
+ {
+ if (secret[i] == c_secret[j])
+ {
+ c_index = j;
+ break;
+ }
+ }
+ secret_result += this->cypher[c_index];
+ }
+ return secret_result;
+ // Your code ends here
+ }
+};
+
+
+std::string encryptDecrypt(std::string toEncrypt) {
+ char key[5] = {'K', 'C', 'Q','e','r'}; //Any chars will work
+ std::string output = toEncrypt;
+
+ for (int i = 0; i < toEncrypt.size(); i++)
+ output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
+
+ return output;
+}
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,Encrypting)
+BBTK_BLACK_BOX_IMPLEMENTATION(Encrypting,bbtk::AtomicBlackBox);
+
+
+
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Encrypting::Process()
+{
+
+// THE MAIN PROCESSING METHOD BODY
+// Here we simply set the input 'In' value to the output 'Out'
+// And print out the output value
+// INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
+// void bbSet{Input|Output}NAME(const TYPE&)
+// const TYPE& bbGet{Input|Output}NAME() const
+// Where :
+// * NAME is the name of the input/output
+// (the one provided in the attribute 'name' of the tag 'input')
+// * TYPE is the C++ type of the input/output
+// (the one provided in the attribute 'type' of the tag 'input')
+
+ bbSetOutputOut( bbGetInputIn() );
+
+ if (bbGetInputType()==1)
+ {
+ shift_encryptor* shiftTest = new shift_encryptor(9);
+ if (bbGetInputMode()==1)
+ {
+ bbSetOutputOut ( shiftTest->encode( bbGetInputIn() ) );
+ }
+ if (bbGetInputMode()==2)
+ {
+ bbSetOutputOut ( shiftTest->decode( bbGetInputIn() ) );
+ }
+ }
+ if (bbGetInputType()==2)
+ {
+ cypher_encryptor* crypter = new cypher_encryptor("04dw51CeVD23 67W89XYZASTBEfyhazlvjnktbogrumcpiqxs.,:;@*$/-_OHIPKLQRUJGJMNF");
+ if (bbGetInputMode()==1)
+ {
+ bbSetOutputOut ( crypter->encode( bbGetInputIn() ) );
+ }
+ if (bbGetInputMode()==2)
+ {
+ bbSetOutputOut ( crypter->decode( bbGetInputIn() ) );
+ }
+ }
+
+ if (bbGetInputType()==3)
+ {
+ if ((bbGetInputMode()==1) ||(bbGetInputMode()==2) )
+ {
+ bbSetOutputOut ( encryptDecrypt( bbGetInputIn() ) );
+ }
+ }
+
+
+ /*
+ encodeResult = shiftTest->encode("hello world");
+ std::cout << "shift encode result == " << encodeResult << std::endl;
+
+ decodeResult = shiftTest->decode("lipps${svph");
+ std::cout << "shift encode result == " << decodeResult << std::endl;
+
+ // string encodeResult = shiftTest->en
+
+ cypher_encryptor* crypterTest = new cypher_encryptor("efyhadwzlvjnktbogrumcpiqxs");
+
+# encodeResult = crypterTest->encode("heyj fvmpe");
+ std::cout << "encryptor encode result == " << encodeResult << std::endl;
+ decodeResult = crypterTest->decode("me emt shevyp wtjp ihls ftssjkt");
+ std::cout << "encryptor decode result == " << decodeResult << std::endl;
+ */
+
+}
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Encrypting::bbUserSetDefaultValues()
+{
+
+// SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
+// Here we initialize the input 'In' to 0
+ bbSetInputIn("");
+ bbSetInputMode(0);
+ bbSetInputType(0);
+
+}
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Encrypting::bbUserInitializeProcessing()
+{
+
+// THE INITIALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should allocate the internal/output pointers
+// if any
+
+
+}
+//=====
+// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
+//=====
+void Encrypting::bbUserFinalizeProcessing()
+{
+
+// THE FINALIZATION METHOD BODY :
+// Here does nothing
+// but this is where you should desallocate the internal/output pointers
+// if any
+
+}
+}
+// EO namespace bbstd
+
+