diff --git a/Examples/Encrypting Messages Using Permutations/AgapiaProgram.exe b/Examples/Encrypting Messages Using Permutations/AgapiaProgram.exe new file mode 100644 index 0000000..a7c93ce Binary files /dev/null and b/Examples/Encrypting Messages Using Permutations/AgapiaProgram.exe differ diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/AgapiaProgram.exe b/Examples/Encrypting Messages Using Permutations/Decryption code/AgapiaProgram.exe new file mode 100644 index 0000000..3747a79 Binary files /dev/null and b/Examples/Encrypting Messages Using Permutations/Decryption code/AgapiaProgram.exe differ diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/DecryptedTextParallel.txt b/Examples/Encrypting Messages Using Permutations/Decryption code/DecryptedTextParallel.txt new file mode 100644 index 0000000..4dd3034 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/DecryptedTextParallel.txt @@ -0,0 +1 @@ +Ana nu mai are nici mere nici nuci. \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/Def.txt b/Examples/Encrypting Messages Using Permutations/Decryption code/Def.txt new file mode 100644 index 0000000..91b0d54 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/Def.txt @@ -0,0 +1,17 @@ +% // Include files +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +% // Additional include directories +% // Additional library directories +% // Additional linker libs/dll etc +% // Additional source files +invers.cpp diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/Drawing1.vsd b/Examples/Encrypting Messages Using Permutations/Decryption code/Drawing1.vsd new file mode 100644 index 0000000..b5c4003 Binary files /dev/null and b/Examples/Encrypting Messages Using Permutations/Decryption code/Drawing1.vsd differ diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/MainInput.txt b/Examples/Encrypting Messages Using Permutations/Decryption code/MainInput.txt new file mode 100644 index 0000000..025c737 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/MainInput.txt @@ -0,0 +1 @@ +nrofprocs 3 \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/agapia.txt b/Examples/Encrypting Messages Using Permutations/Decryption code/agapia.txt new file mode 100644 index 0000000..8868882 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/agapia.txt @@ -0,0 +1,154 @@ +module MAIN{listen nil}{read nil} +{ + CITIRE # ( SLAVEA % SLAVEB % SLAVEC) # SCRIERE +}{speak nil}{write nil} + +module CITIRE{listen nil}{read nil} +{ +std::string strLine; +std::string strEncrypted; +std::string strDecrypted; +std::ifstream permutationTextFileRead("permutationParallel.txt"); +std::ifstream encryptedTextFileRead("encryptedTextParallel.txt"); +std::vector arrPermutation; + + int nPermutationSize = 0; + permutationTextFileRead >> nPermutationSize; + for (int i = 0; i < nPermutationSize; ++i) + { + int nPermutationElement; + permutationTextFileRead >> nPermutationElement; + arrPermutation.push_back(nPermutationElement); + } + permutationTextFileRead.close(); + if (encryptedTextFileRead.is_open()) + { + while (getline(encryptedTextFileRead, strLine)) + { + strEncrypted.append(strLine.begin(), strLine.end()); + } + encryptedTextFileRead.close(); + } + +std::vector arrInverse; + for (size_t i = 0; i < arrPermutation.size(); i++) + { + for (size_t j = 0; j < arrPermutation.size(); j++) + { + if (arrPermutation[j] == i) + { + arrInverse.push_back(j); + break; + } + } + } + + int nTextSize =(int)strEncrypted.size(); + nPermutationSize = (int)arrPermutation.size(); + int* perminverse= new int[nPermutationSize]; + for (int i = 0; i < nPermutationSize; ++i) + { + perminverse[i] = arrInverse[i]; + } + +perminversea = (int)perminverse; +perminverseb = (int)perminverse; +perminversec = (int)perminverse; +int chunkSize = nPermutationSize / 3; +chunksizea = (int)chunkSize; +chunksizeb = (int)chunkSize; +chunksizec = (int)chunkSize; +npermsizea = (int)nPermutationSize; +npermsizeb = (int)nPermutationSize; +npermsizec = (int)nPermutationSize; + +char * cstrAllContent = new char[strEncrypted.size() + 1]; +std::copy(strEncrypted.begin(), strEncrypted.end(), cstrAllContent); +cstrAllContent[strEncrypted.size()] = '\0'; +strallcontenta = (int)cstrAllContent; +strallcontentb = (int)cstrAllContent; +strallcontentc = (int)cstrAllContent; + +}{speak perminversea : int, chunksizea : int, npermsizea : int, strallcontenta : int; perminverseb : int, chunksizeb : int, npermsizeb : int, strallcontentb : int ; perminversec : int, chunksizec : int, npermsizec : int, strallcontentc : int}{write nil} + +module SLAVEA{listen perm : int, chunksizea : int, npermsizea : int, strallcontenta : int}{read nil} +{ +std::string strEncryptedChunk; +int*pPermutation=(int*)perm; +std::string strText((char*)strallcontenta); +int localsizea= chunksizea; +for (int i = 0; i < localsizea; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + +char * cstrLocalEncrypted = new char[localsizea + 1]; +std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); +cstrLocalEncrypted[localsizea] = '\0'; +locala = (int)cstrLocalEncrypted; + + +}{speak locala: int}{write nil} + +module SLAVEB{listen perm : int, chunksizeb : int, npermsizeb : int, strallcontentb : int}{read nil} +{ +std::string strEncryptedChunk; +int*pPermutation=(int*)perm; +std::string strText((char*)strallcontentb); +int localsizeb= chunksizeb; +for (int i = localsizeb ; i < 2*localsizeb; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + +char * cstrLocalEncrypted = new char[localsizeb + 1]; +std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); +cstrLocalEncrypted[localsizeb] = '\0'; +localb = (int)cstrLocalEncrypted; + + +}{speak localb: int}{write nil} + +module SLAVEC{listen perm : int, chunksizec : int, npermsizec : int, strallcontentc : int}{read nil} +{ +std::string strEncryptedChunk; +int*pPermutation=(int*)perm; +std::string strText((char*)strallcontentc); +int localsizec= chunksizec; +int last=npermsizec; +int nLocalChunkSize = last - 2*localsizec; +for (int i = 2*localsizec; i < last ; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + +char * cstrLocalEncrypted = new char[nLocalChunkSize + 1]; +std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); +cstrLocalEncrypted[nLocalChunkSize] = '\0'; +localc = (int)cstrLocalEncrypted; + +}{speak localc: int}{write nil} + + + +module SCRIERE{listen locala : int; localb : int; localc : int}{read nil} +{ +std::string strFinalEncrypted; +std::string strLocalStringA((char*)locala); +std::string strLocalStringB((char*)localb); +std::string strLocalStringC((char*)localc); +strFinalEncrypted.append(strLocalStringA.begin(), strLocalStringA.end()); +strFinalEncrypted.append(strLocalStringB.begin(), strLocalStringB.end()); +strFinalEncrypted.append(strLocalStringC.begin(), strLocalStringC.end()); +std::ofstream encryptedTextFile("DecryptedTextParallel.txt"); +encryptedTextFile< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/invers.cpp b/Examples/Encrypting Messages Using Permutations/Decryption code/invers.cpp new file mode 100644 index 0000000..d1f87e0 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/invers.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +std::vector inversePermutation(std::vector& arrPermutation) +{ + std::vector arrInverse; + for (size_t i = 0; i < arrPermutation.size(); i++) + { + for (size_t j = 0; j < arrPermutation.size(); j++) + { + if (arrPermutation[j] == i) + { + arrInverse.push_back(j); + break; + } + } + } + + return arrInverse; +} + + + \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/permutationParallel.txt b/Examples/Encrypting Messages Using Permutations/Decryption code/permutationParallel.txt new file mode 100644 index 0000000..c71fca4 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/permutationParallel.txt @@ -0,0 +1 @@ +35 5 20 7 0 4 28 6 10 25 23 16 14 22 34 1 11 3 27 29 15 9 24 19 13 18 32 2 31 21 17 33 26 8 30 12 \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/readme b/Examples/Encrypting Messages Using Permutations/Decryption code/readme new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/readme @@ -0,0 +1 @@ + diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/A b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/A new file mode 100644 index 0000000..d3f5a12 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/A @@ -0,0 +1 @@ + diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/ALTCEVA b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/ALTCEVA new file mode 100644 index 0000000..6a4ca6a --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/ALTCEVA @@ -0,0 +1,4 @@ +for (int i = 0; i < arrPermutation.size(); ++i) + { + std::cout << arrPermutation[i] << " "; + } diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/AgapiaToCCode.cpp b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/AgapiaToCCode.cpp new file mode 100644 index 0000000..3686d3a --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/AgapiaToCCode.cpp @@ -0,0 +1,231 @@ +#include "AgapiaToCCode.h" +#include "ExecutionBlackbox.h" +#include "InputTypes.h" + +#include "Includes.h" + + +void CITIRE(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& perminversea = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizea = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizea = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontenta = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& perminverseb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[0])->GetValueRef(); + int& chunksizeb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[1])->GetValueRef(); + int& npermsizeb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[2])->GetValueRef(); + int& strallcontentb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[3])->GetValueRef(); + int& perminversec = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[0])->GetValueRef(); + int& chunksizec = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[1])->GetValueRef(); + int& npermsizec = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[2])->GetValueRef(); + int& strallcontentc = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[3])->GetValueRef(); + + + // User code: + std::string strLine; + std::string strEncrypted; + std::string strDecrypted; + std::ifstream permutationTextFileRead("permutationParallel.txt"); + std::ifstream encryptedTextFileRead("encryptedTextParallel.txt"); + std::vector arrPermutation; + + int nPermutationSize = 0; + permutationTextFileRead >> nPermutationSize; + for (int i = 0; i < nPermutationSize; ++i) + { + int nPermutationElement; + permutationTextFileRead >> nPermutationElement; + arrPermutation.push_back(nPermutationElement); + } + permutationTextFileRead.close(); + if (encryptedTextFileRead.is_open()) + { + while (getline(encryptedTextFileRead, strLine)) + { + strEncrypted.append(strLine.begin(), strLine.end()); + } + encryptedTextFileRead.close(); + } + + std::vector arrInverse; + for (size_t i = 0; i < arrPermutation.size(); i++) + { + for (size_t j = 0; j < arrPermutation.size(); j++) + { + if (arrPermutation[j] == i) + { + arrInverse.push_back(j); + break; + } + } + } + + int nTextSize =(int)strEncrypted.size(); + nPermutationSize = (int)arrPermutation.size(); + int* perminverse= new int[nPermutationSize]; + for (int i = 0; i < nPermutationSize; ++i) + { + perminverse[i] = arrInverse[i]; + } + + perminversea = (int)perminverse; + perminverseb = (int)perminverse; + perminversec = (int)perminverse; + int chunkSize = nPermutationSize / 3; + chunksizea = (int)chunkSize; + chunksizeb = (int)chunkSize; + chunksizec = (int)chunkSize; + npermsizea = (int)nPermutationSize; + npermsizeb = (int)nPermutationSize; + npermsizec = (int)nPermutationSize; + + char * cstrAllContent = new char[strEncrypted.size() + 1]; + std::copy(strEncrypted.begin(), strEncrypted.end(), cstrAllContent); + cstrAllContent[strEncrypted.size()] = '\0'; + strallcontenta = (int)cstrAllContent; + strallcontentb = (int)cstrAllContent; + strallcontentc = (int)cstrAllContent; + + + +} + + + + +void SCRIERE(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& locala = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& localb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[1])->m_InputItems[0])->GetValueRef(); + int& localc = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[2])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strFinalEncrypted; + std::string strLocalStringA((char*)locala); + std::string strLocalStringB((char*)localb); + std::string strLocalStringC((char*)localc); + strFinalEncrypted.append(strLocalStringA.begin(), strLocalStringA.end()); + strFinalEncrypted.append(strLocalStringB.begin(), strLocalStringB.end()); + strFinalEncrypted.append(strLocalStringC.begin(), strLocalStringC.end()); + std::ofstream encryptedTextFile("DecryptedTextParallel.txt"); + encryptedTextFile<m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizea = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizea = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontenta = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& locala = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strEncryptedChunk; + int*pPermutation=(int*)perm; + std::string strText((char*)strallcontenta); + int localsizea= chunksizea; + for (int i = 0; i < localsizea; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + + char * cstrLocalEncrypted = new char[localsizea + 1]; + std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); + cstrLocalEncrypted[localsizea] = '\0'; + locala = (int)cstrLocalEncrypted; + + + + +} + + + + +void SLAVEB(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& perm = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizeb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizeb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontentb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& localb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strEncryptedChunk; + int*pPermutation=(int*)perm; + std::string strText((char*)strallcontentb); + int localsizeb= chunksizeb; + for (int i = localsizeb ; i < 2*localsizeb; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + + char * cstrLocalEncrypted = new char[localsizeb + 1]; + std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); + cstrLocalEncrypted[localsizeb] = '\0'; + localb = (int)cstrLocalEncrypted; + + + + +} + + + + +void SLAVEC(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& perm = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizec = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizec = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontentc = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& localc = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strEncryptedChunk; + int*pPermutation=(int*)perm; + std::string strText((char*)strallcontentc); + int localsizec= chunksizec; + int last=npermsizec; + int nLocalChunkSize = last - 2*localsizec; + for (int i = 2*localsizec; i < last ; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + char * cstrLocalEncrypted = new char[nLocalChunkSize + 1]; + std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); + cstrLocalEncrypted[nLocalChunkSize] = '\0'; + localc = (int)cstrLocalEncrypted; + + + +} + + +void InitializeAgapiaToCFunctions() +{ +ExecutionBlackbox::Get()->AddAgapiaToCFunction("CITIRE", &CITIRE); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SCRIERE", &SCRIERE); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SLAVEA", &SLAVEA); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SLAVEB", &SLAVEB); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SLAVEC", &SLAVEC); +} diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/BBALTCEVA b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/BBALTCEVA new file mode 100644 index 0000000..362b653 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/BBALTCEVA @@ -0,0 +1 @@ +std::cout< arrPermutation; + + if (testTextFile.is_open()) + { + while (getline(testTextFile, strLine)) + { + strAllContent.append(strLine.begin(), strLine.end()); + } + testTextFile.close(); + } + else + { + std::cout << "Failed to open file"; + return; + } + std::srand(unsigned(std::time(0))); + for (size_t i = 0; i < strAllContent.size(); ++i) + { + arrPermutation.push_back(i); + } + + std::random_shuffle(arrPermutation.begin(), arrPermutation.end()); + + permutationTextFileWrite << arrPermutation.size() << " "; + for (size_t i = 0; i < arrPermutation.size(); ++i) + { + permutationTextFileWrite << arrPermutation[i] << " "; + } + permutationTextFileWrite.close(); + + + int nTextSize = (int)strAllContent.size(); + + + + + int nPermutationSize = (int)arrPermutation.size(); + + + int* pPermutation = new int[nPermutationSize]; + for (int i = 0; i < nPermutationSize; ++i) + { + pPermutation[i] = arrPermutation[i]; + } + + diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/Includes.h b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/Includes.h new file mode 100644 index 0000000..3556d46 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/Includes.h @@ -0,0 +1,22 @@ +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/MAIN b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/MAIN new file mode 100644 index 0000000..221b69d --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/MAIN @@ -0,0 +1 @@ + DOI diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/MASTER b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/MASTER new file mode 100644 index 0000000..0ee341b --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/MASTER @@ -0,0 +1,3 @@ + std:cin>>n; + + diff --git a/Examples/Encrypting Messages Using Permutations/Decryption code/temp/SCRIEREI b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/SCRIEREI new file mode 100644 index 0000000..c22f1f2 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/Decryption code/temp/SCRIEREI @@ -0,0 +1,11 @@ +std::string strFinalEncrypted; +std::string strLocalStringA((char*)locala); +std::string strLocalStringB((char*)localb); +std::string strLocalStringC((char*)localc); +strFinalEncrypted.append(strLocalStringA.begin(), strLocalStringA.end()); +strFinalEncrypted.append(strLocalStringB.begin(), strLocalStringB.end()); +strFinalEncrypted.append(strLocalStringC.begin(), strLocalStringC.end()); +std::ofstream encryptedTextFile("DecryptedTextParallel.txt"); +encryptedTextFile< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +% // Additional include directories +% // Additional library directories +% // Additional linker libs/dll etc +% // Additional source files diff --git a/Examples/Encrypting Messages Using Permutations/Drawing1.vsd b/Examples/Encrypting Messages Using Permutations/Drawing1.vsd new file mode 100644 index 0000000..b5c4003 Binary files /dev/null and b/Examples/Encrypting Messages Using Permutations/Drawing1.vsd differ diff --git a/Examples/Encrypting Messages Using Permutations/MainInput.txt b/Examples/Encrypting Messages Using Permutations/MainInput.txt new file mode 100644 index 0000000..025c737 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/MainInput.txt @@ -0,0 +1 @@ +nrofprocs 3 \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/agapia.txt b/Examples/Encrypting Messages Using Permutations/agapia.txt new file mode 100644 index 0000000..c589d19 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/agapia.txt @@ -0,0 +1,148 @@ +module MAIN{listen nil}{read nil} +{ + CITIRE # ( SLAVEA% SLAVEB % SLAVEC) # SCRIERE +}{speak nil}{write nil} + +module CITIRE{listen nil}{read nil} +{ + std::ifstream testTextFile("clearText.txt"); + std::ofstream permutationTextFileWrite("permutationParallel.txt"); + std::string strAllContent,strLine, strEncrypted; + std::vector arrPermutation; + + if (testTextFile.is_open()) + { + while (getline(testTextFile, strLine)) + { + strAllContent.append(strLine.begin(), strLine.end()); + } + testTextFile.close(); + } + else + { + std::cout << "Failed to open file"; + return; + } + std::srand(unsigned(std::time(0))); + for (size_t i = 0; i < strAllContent.size(); ++i) + { + arrPermutation.push_back(i); + } + + std::random_shuffle(arrPermutation.begin(), arrPermutation.end()); + + permutationTextFileWrite << arrPermutation.size() << " "; + for (size_t i = 0; i < arrPermutation.size(); ++i) + { + permutationTextFileWrite << arrPermutation[i] << " "; + } + permutationTextFileWrite.close(); + + int nTextSize = (int)strAllContent.size(); + int nPermutationSize = (int)arrPermutation.size(); + + int* ppermutation = new int[nPermutationSize]; + for (int i = 0; i < nPermutationSize; ++i) + { + ppermutation[i] = arrPermutation[i]; + } + +ppermutationa = (int)ppermutation; +ppermutationb = (int)ppermutation; +ppermutationc = (int)ppermutation; +int chunkSize = nPermutationSize / 3; +chunksizea = (int)chunkSize; +chunksizeb = (int)chunkSize; +chunksizec = (int)chunkSize; +npermsizea = (int)nPermutationSize; +npermsizeb = (int)nPermutationSize; +npermsizec = (int)nPermutationSize; + +char * cstrAllContent = new char[strAllContent.size() + 1]; +std::copy(strAllContent.begin(), strAllContent.end(), cstrAllContent); +cstrAllContent[strAllContent.size()] = '\0'; +strallcontenta = (int)cstrAllContent; +strallcontentb = (int)cstrAllContent; +strallcontentc = (int)cstrAllContent; + +}{speak ppermutationa : int, chunksizea : int, npermsizea : int, strallcontenta : int ; ppermutationb : int, chunksizeb : int, npermsizeb : int, strallcontentb : int ; ppermutationc : int, chunksizec : int, npermsizec : int, strallcontentc : int}{write nil} + +module SLAVEA{listen perm : int, chunksizea : int, npermsizea : int, strallcontenta : int}{read nil} +{ +std::string strEncryptedChunk; +int*pPermutation=(int*)perm; +std::string strText((char*)strallcontenta); +int localsizea= chunksizea; +for (int i = 0; i < localsizea; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + +char * cstrLocalEncrypted = new char[localsizea + 1]; +std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); +cstrLocalEncrypted[localsizea] = '\0'; +locala = (int)cstrLocalEncrypted; + + +}{speak locala: int}{write nil} + +module SLAVEB{listen perm : int, chunksizeb : int, npermsizeb : int, strallcontentb : int}{read nil} +{ +std::string strEncryptedChunk; +int*pPermutation=(int*)perm; +std::string strText((char*)strallcontentb); +int localsizeb= chunksizeb; +for (int i = localsizeb; i < 2*localsizeb; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + +char * cstrLocalEncrypted = new char[localsizeb + 1]; +std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); +cstrLocalEncrypted[localsizeb] = '\0'; +localb = (int)cstrLocalEncrypted; + + +}{speak localb: int}{write nil} + +module SLAVEC{listen perm : int, chunksizec : int, npermsizec : int, strallcontentc : int}{read nil} +{ +std::string strEncryptedChunk; +int*pPermutation=(int*)perm; +std::string strText((char*)strallcontentc); +int localsizec= chunksizec; +int last=npermsizec; +int nLocalChunkSize = last - 2*localsizec; +for (int i = 2*localsizec; i < last ; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + +char * cstrLocalEncryptec = new char[nLocalChunkSize + 1]; +std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncryptec); +cstrLocalEncryptec[nLocalChunkSize] = '\0'; +localc = (int)cstrLocalEncryptec; + +}{speak localc: int}{write nil} + + + +module SCRIERE{listen locala : int; localb : int; localc : int}{read nil} +{ +std::string strFinalEncrypted; +std::string strLocalStringA((char*)locala); +std::string strLocalStringB((char*)localb); +std::string strLocalStringC((char*)localc); +strFinalEncrypted.append(strLocalStringA.begin(), strLocalStringA.end()); +strFinalEncrypted.append(strLocalStringB.begin(), strLocalStringB.end()); +strFinalEncrypted.append(strLocalStringC.begin(), strLocalStringC.end()); +std::ofstream encryptedTextFile("encryptedTextParallel.txt"); +encryptedTextFile< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/permutationParallel.txt b/Examples/Encrypting Messages Using Permutations/permutationParallel.txt new file mode 100644 index 0000000..c71fca4 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/permutationParallel.txt @@ -0,0 +1 @@ +35 5 20 7 0 4 28 6 10 25 23 16 14 22 34 1 11 3 27 29 15 9 24 19 13 18 32 2 31 21 17 33 26 8 30 12 \ No newline at end of file diff --git a/Examples/Encrypting Messages Using Permutations/temp/A b/Examples/Encrypting Messages Using Permutations/temp/A new file mode 100644 index 0000000..d3f5a12 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/A @@ -0,0 +1 @@ + diff --git a/Examples/Encrypting Messages Using Permutations/temp/ALTCEVA b/Examples/Encrypting Messages Using Permutations/temp/ALTCEVA new file mode 100644 index 0000000..6a4ca6a --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/ALTCEVA @@ -0,0 +1,4 @@ +for (int i = 0; i < arrPermutation.size(); ++i) + { + std::cout << arrPermutation[i] << " "; + } diff --git a/Examples/Encrypting Messages Using Permutations/temp/AgapiaToCCode.cpp b/Examples/Encrypting Messages Using Permutations/temp/AgapiaToCCode.cpp new file mode 100644 index 0000000..9d15ee1 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/AgapiaToCCode.cpp @@ -0,0 +1,225 @@ +#include "AgapiaToCCode.h" +#include "ExecutionBlackbox.h" +#include "InputTypes.h" + +#include "Includes.h" + + +void CITIRE(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& ppermutationa = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizea = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizea = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontenta = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& ppermutationb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[0])->GetValueRef(); + int& chunksizeb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[1])->GetValueRef(); + int& npermsizeb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[2])->GetValueRef(); + int& strallcontentb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[1])->m_InputItems[3])->GetValueRef(); + int& ppermutationc = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[0])->GetValueRef(); + int& chunksizec = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[1])->GetValueRef(); + int& npermsizec = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[2])->GetValueRef(); + int& strallcontentc = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[2])->m_InputItems[3])->GetValueRef(); + + + // User code: + std::ifstream testTextFile("clearText.txt"); + std::ofstream permutationTextFileWrite("permutationParallel.txt"); + std::string strAllContent,strLine, strEncrypted; + std::vector arrPermutation; + + if (testTextFile.is_open()) + { + while (getline(testTextFile, strLine)) + { + strAllContent.append(strLine.begin(), strLine.end()); + } + testTextFile.close(); + } + else + { + std::cout << "Failed to open file"; + return; + } + std::srand(unsigned(std::time(0))); + for (size_t i = 0; i < strAllContent.size(); ++i) + { + arrPermutation.push_back(i); + } + + std::random_shuffle(arrPermutation.begin(), arrPermutation.end()); + + permutationTextFileWrite << arrPermutation.size() << " "; + for (size_t i = 0; i < arrPermutation.size(); ++i) + { + permutationTextFileWrite << arrPermutation[i] << " "; + } + permutationTextFileWrite.close(); + + int nTextSize = (int)strAllContent.size(); + int nPermutationSize = (int)arrPermutation.size(); + + int* ppermutation = new int[nPermutationSize]; + for (int i = 0; i < nPermutationSize; ++i) + { + ppermutation[i] = arrPermutation[i]; + } + + ppermutationa = (int)ppermutation; + ppermutationb = (int)ppermutation; + ppermutationc = (int)ppermutation; + int chunkSize = nPermutationSize / 3; + chunksizea = (int)chunkSize; + chunksizeb = (int)chunkSize; + chunksizec = (int)chunkSize; + npermsizea = (int)nPermutationSize; + npermsizeb = (int)nPermutationSize; + npermsizec = (int)nPermutationSize; + + char * cstrAllContent = new char[strAllContent.size() + 1]; + std::copy(strAllContent.begin(), strAllContent.end(), cstrAllContent); + cstrAllContent[strAllContent.size()] = '\0'; + strallcontenta = (int)cstrAllContent; + strallcontentb = (int)cstrAllContent; + strallcontentc = (int)cstrAllContent; + + + +} + + + + +void SCRIERE(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& locala = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& localb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[1])->m_InputItems[0])->GetValueRef(); + int& localc = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[2])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strFinalEncrypted; + std::string strLocalStringA((char*)locala); + std::string strLocalStringB((char*)localb); + std::string strLocalStringC((char*)localc); + strFinalEncrypted.append(strLocalStringA.begin(), strLocalStringA.end()); + strFinalEncrypted.append(strLocalStringB.begin(), strLocalStringB.end()); + strFinalEncrypted.append(strLocalStringC.begin(), strLocalStringC.end()); + std::ofstream encryptedTextFile("encryptedTextParallel.txt"); + encryptedTextFile<m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizea = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizea = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontenta = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& locala = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strEncryptedChunk; + int*pPermutation=(int*)perm; + std::string strText((char*)strallcontenta); + int localsizea= chunksizea; + for (int i = 0; i < localsizea; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + char * cstrLocalEncrypted = new char[localsizea + 1]; + std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); + cstrLocalEncrypted[localsizea] = '\0'; + locala = (int)cstrLocalEncrypted; + + + + +} + + + + +void SLAVEB(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& perm = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizeb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizeb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontentb = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& localb = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strEncryptedChunk; + int*pPermutation=(int*)perm; + std::string strText((char*)strallcontentb); + int localsizeb= chunksizeb; + for (int i = localsizeb; i < 2*localsizeb; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + char * cstrLocalEncrypted = new char[localsizeb + 1]; + std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncrypted); + cstrLocalEncrypted[localsizeb] = '\0'; + localb = (int)cstrLocalEncrypted; + + + + +} + + + + +void SLAVEC(InputBlock* pNorth, InputBlock* pWest, InputBlock* pSouth, InputBlock* pEast) +{ + // Local variables declaration: + int& perm = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + int& chunksizec = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[1])->GetValueRef(); + int& npermsizec = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[2])->GetValueRef(); + int& strallcontentc = ((IntDataItem*)((SimpleProcessItem*)pWest->m_InputsInBlock[0])->m_InputItems[3])->GetValueRef(); + int& localc = ((IntDataItem*)((SimpleProcessItem*)pEast->m_InputsInBlock[0])->m_InputItems[0])->GetValueRef(); + + + // User code: + std::string strEncryptedChunk; + int*pPermutation=(int*)perm; + std::string strText((char*)strallcontentc); + int localsizec= chunksizec; + int last=npermsizec; + int nLocalChunkSize = last - 2*localsizec; + for (int i = 2*localsizec; i < last ; ++i) + { + strEncryptedChunk.append(strText.begin() + pPermutation[i], strText.begin() + pPermutation[i] + 1); + } + + char * cstrLocalEncryptec = new char[nLocalChunkSize + 1]; + std::copy(strEncryptedChunk.begin(), strEncryptedChunk.end(), cstrLocalEncryptec); + cstrLocalEncryptec[nLocalChunkSize] = '\0'; + localc = (int)cstrLocalEncryptec; + + + +} + + +void InitializeAgapiaToCFunctions() +{ +ExecutionBlackbox::Get()->AddAgapiaToCFunction("CITIRE", &CITIRE); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SCRIERE", &SCRIERE); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SLAVEA", &SLAVEA); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SLAVEB", &SLAVEB); +ExecutionBlackbox::Get()->AddAgapiaToCFunction("SLAVEC", &SLAVEC); +} diff --git a/Examples/Encrypting Messages Using Permutations/temp/BBALTCEVA b/Examples/Encrypting Messages Using Permutations/temp/BBALTCEVA new file mode 100644 index 0000000..362b653 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/BBALTCEVA @@ -0,0 +1 @@ +std::cout< arrPermutation; + + if (testTextFile.is_open()) + { + while (getline(testTextFile, strLine)) + { + strAllContent.append(strLine.begin(), strLine.end()); + } + testTextFile.close(); + } + else + { + std::cout << "Failed to open file"; + return; + } + std::srand(unsigned(std::time(0))); + for (size_t i = 0; i < strAllContent.size(); ++i) + { + arrPermutation.push_back(i); + } + + std::random_shuffle(arrPermutation.begin(), arrPermutation.end()); + + permutationTextFileWrite << arrPermutation.size() << " "; + for (size_t i = 0; i < arrPermutation.size(); ++i) + { + permutationTextFileWrite << arrPermutation[i] << " "; + } + permutationTextFileWrite.close(); + + + int nTextSize = (int)strAllContent.size(); + + + + + int nPermutationSize = (int)arrPermutation.size(); + + + int* pPermutation = new int[nPermutationSize]; + for (int i = 0; i < nPermutationSize; ++i) + { + pPermutation[i] = arrPermutation[i]; + } + + diff --git a/Examples/Encrypting Messages Using Permutations/temp/Includes.h b/Examples/Encrypting Messages Using Permutations/temp/Includes.h new file mode 100644 index 0000000..3556d46 --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/Includes.h @@ -0,0 +1,22 @@ +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + +#include + diff --git a/Examples/Encrypting Messages Using Permutations/temp/MAIN b/Examples/Encrypting Messages Using Permutations/temp/MAIN new file mode 100644 index 0000000..221b69d --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/MAIN @@ -0,0 +1 @@ + DOI diff --git a/Examples/Encrypting Messages Using Permutations/temp/MASTER b/Examples/Encrypting Messages Using Permutations/temp/MASTER new file mode 100644 index 0000000..0ee341b --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/MASTER @@ -0,0 +1,3 @@ + std:cin>>n; + + diff --git a/Examples/Encrypting Messages Using Permutations/temp/agapia.dat b/Examples/Encrypting Messages Using Permutations/temp/agapia.dat new file mode 100644 index 0000000..6e0adb9 Binary files /dev/null and b/Examples/Encrypting Messages Using Permutations/temp/agapia.dat differ diff --git a/Examples/Encrypting Messages Using Permutations/temp/agapia_transf.txt b/Examples/Encrypting Messages Using Permutations/temp/agapia_transf.txt new file mode 100644 index 0000000..baf04bc --- /dev/null +++ b/Examples/Encrypting Messages Using Permutations/temp/agapia_transf.txt @@ -0,0 +1,30 @@ +module MAIN{listen nil}{read nil} +{ + CITIRE # ( SLAVEA% SLAVEB % SLAVEC) # SCRIERE +}{speak nil}{write nil} + +module CITIRE{listen nil}{read nil} +{ + @ +}{speak ppermutationa : int, chunksizea : int, npermsizea : int, strallcontenta : int ; ppermutationb : int, chunksizeb : int, npermsizeb : int, strallcontentb : int ; ppermutationc : int, chunksizec : int, npermsizec : int, strallcontentc : int}{write nil} + +module SLAVEA{listen perm : int, chunksizea : int, npermsizea : int, strallcontenta : int}{read nil} +{ + @ +}{speak locala: int}{write nil} + +module SLAVEB{listen perm : int, chunksizeb : int, npermsizeb : int, strallcontentb : int}{read nil} +{ + @ +}{speak localb: int}{write nil} + +module SLAVEC{listen perm : int, chunksizec : int, npermsizec : int, strallcontentc : int}{read nil} +{ + @ +}{speak localc: int}{write nil} + +module SCRIERE{listen locala : int; localb : int; localc : int}{read nil} +{ + @ +}{speak nil}{write nil} +