{"id":21766357,"url":"https://github.com/drilonaliu/parallel-permutation-cipher","last_synced_at":"2025-07-19T18:07:41.039Z","repository":{"id":254333959,"uuid":"846220524","full_name":"drilonaliu/Parallel-Permutation-Cipher","owner":"drilonaliu","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-22T19:31:31.000Z","size":331,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T05:27:18.904Z","etag":null,"topics":["cryptography","cuda","gpu","parallel-programming","permutation"],"latest_commit_sha":null,"homepage":"","language":"Cuda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drilonaliu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-22T19:01:10.000Z","updated_at":"2024-10-10T22:12:48.000Z","dependencies_parsed_at":"2024-08-22T21:28:01.849Z","dependency_job_id":"4b454d49-1ad3-4555-93c4-05baee1d57f0","html_url":"https://github.com/drilonaliu/Parallel-Permutation-Cipher","commit_stats":null,"previous_names":["drilonaliu/parallel-permutation-cipher"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drilonaliu/Parallel-Permutation-Cipher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permutation-Cipher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permutation-Cipher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permutation-Cipher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permutation-Cipher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drilonaliu","download_url":"https://codeload.github.com/drilonaliu/Parallel-Permutation-Cipher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permutation-Cipher/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265982728,"owners_count":23859573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","cuda","gpu","parallel-programming","permutation"],"created_at":"2024-11-26T13:16:55.699Z","updated_at":"2025-07-19T18:07:41.012Z","avatar_url":"https://github.com/drilonaliu.png","language":"Cuda","readme":"# Parallel Permutation Cipher\n \nIn permutation ciphering, both in C++ and CUDA, we have a method that permutes a text based on a given permutation. This method is used for both encryption and decryption. In the sequential version, we iterate over each character and permute it, whereas in the parallel version, the i-th thread permutes the i-th character of the text. To demonstrate how the algorithm works, let's take an example.\n\nWe need to permute the following text using the given permutation {2,1,0}. When permuting the letter 'F', we take the index 5 and map it to the range [0,2], resulting in the index 2. According to the given permutation, π(2) = 0. Now, we find the first index of the block to which index 5 belongs (i.e., the block [3,5]), and we add the value obtained, π(2) = 0, to this index to get the final index 3.\n\n\u003cdiv align = \"center\"\u003e\n\t\n| 0 | 1 | 2 | 3 | 4 | 5 |\n|---|---|---|---|---|---|\n| A | B | C | D | E | F |\n| C | B | A | F | E | D |\n\n\u003c/div\u003e\n\n\n$$5 \\mod 3 = 2$$\n\n$$j = \\lfloor {\\frac{5}{3}} \\rfloor \\times 3 + \\pi(2) = 1 \\times 3 + 0 = 3$$\n\n\n\n## Kernel\n```\n__global__ void applyPermutation(char* text, char* permutatedText, int* permutation, int permutationLength, int textLength) {\n\tint i = threadIdx.x+blockIdx.x*blockDim.x;\n\tif (i \u003c textLength) {\n\t\tint p = permutation[i % permutationLength];\n\t\tint j = (i / permutationLength) * permutationLength + p;\n\t\tpermutatedText[j] = text[i];\n\t}\n}\n```\n\n## Padding \n\nIn permutation ciphering, padding is considered, which is necessary when the length of the text is not a multiple of the key length. In this case, a symbol is added to represent padding, for example, the symbol @. If we have the text \"ABCDEFG,\" padding would occur as follows:\n\n\n\u003cdiv align = \"center\"\u003e \n\t\n| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |\n|---|---|---|---|---|---|---|---|---|\n| A | B | C | D | E | F | G | @ | @ |\n| C | B | A | F | E | D | @ | @ | F |\n\n\u003c/div\u003e\n\n\n```\nstring permutationEncrypt(string text, int* permutation, int permutationLength) {\n \tint m = text.length() % permutationLength;\n \t//Add the padd symbol if padding is needed.\n \tif (m != 0) {\n  \t\tint padding = permutationLength - m;\n  \t\tfor (int i = 0; i \u003c padding; i++) {\n \t\t\t  text += paddSymbol;\n \t \t}\n \t}\n \tstring encryptedText = applyPermutation(text, permutation,permutationLength);\n \treturn encryptedText;\n}\n```\n\n\nWhen decrypting the text \"ABCDEFG@@\", we look at the last block. If we encounter any @ (padding symbol), we remove every character after the padding symbol (which means we remove all padding symbols) and obtain the text \"ABCDEFG\".\n\n```\nstring permutationDecrypt(string text, int* permutation, int permutationLength) {\n\tint* inv_permutation = getInversePermutation(permutation, permutationLength);\n\tstring decryptedText = applyPermutation(text, inv_permutation, permutationLength);\n\t/*Check if padding was added by going to the last block.\n\tIf it has the padding symbol, remove everything after it.*/\n\tfor (int i = text.length() - permutationLength - 1; i \u003c text.length(); i++) {\n\t\tchar letter = decryptedText[i];;\n\t\tif (letter == paddSymbol) {\n\t\t\tdecryptedText.erase(i);\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\treturn decryptedText;\n}\n```\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fparallel-permutation-cipher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrilonaliu%2Fparallel-permutation-cipher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fparallel-permutation-cipher/lists"}