{"id":21766355,"url":"https://github.com/drilonaliu/parallel-permuation-cipher-attack","last_synced_at":"2025-03-21T05:24:14.122Z","repository":{"id":254337597,"uuid":"846235590","full_name":"drilonaliu/Parallel-Permuation-Cipher-Attack","owner":"drilonaliu","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-23T18:11:24.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T02:18:25.326Z","etag":null,"topics":["attack","cryptography","cuda","gpu","parallel-computing"],"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:41:40.000Z","updated_at":"2024-10-10T22:18:37.000Z","dependencies_parsed_at":"2024-08-22T21:52:13.307Z","dependency_job_id":null,"html_url":"https://github.com/drilonaliu/Parallel-Permuation-Cipher-Attack","commit_stats":null,"previous_names":["drilonaliu/parallel-permuation-cipher-attack"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permuation-Cipher-Attack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permuation-Cipher-Attack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permuation-Cipher-Attack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drilonaliu%2FParallel-Permuation-Cipher-Attack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drilonaliu","download_url":"https://codeload.github.com/drilonaliu/Parallel-Permuation-Cipher-Attack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244741963,"owners_count":20502382,"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":["attack","cryptography","cuda","gpu","parallel-computing"],"created_at":"2024-11-26T13:16:55.646Z","updated_at":"2025-03-21T05:24:14.103Z","avatar_url":"https://github.com/drilonaliu.png","language":"Cuda","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parallel-Permuation-Cipher-Attack\n \nIt is a assumed that we know the plain text and the cipher text, and we need to find the key. In addition, it is also assumed that the key length does not exceed 8. The attack is a brute force attack which tries all the possible keys in parallel.\nThread i tries the i-th permutation and compares the original text with the cipher text. For example, for length 3, there would be working 6 = 3! threads in parallel.  \n\n* Thread 1 : 1 2 3\n* Thread 2 : 1 3 2\n* Thread 3 : 2 1 3\n* Thread 4 : 2 3 1\n* Thread 5 : 3 2 1\n* Thread 5 : 3 1 2\n\nThis list of permuatations is generated on the CPU and is then sent on the GPU. For each length we run n! threads active that brute force the key. \n\n\nThe number of permutations of length n is excactly $n!$. Each thread then itereates on the text and checks if permuting that text with the key gives the cipher text. If it encounters a letter which doesnt match with the cipher text, then it stops.\n\n\n```\n__global__ void cudaAttack(char* text, char* encrypted, char* permutatedText1, int* permutations, int permutationLength, int textLength) {\n\n\tint i = threadIdx.x + blockIdx.x * blockDim.x;\n\tint permutation[8];\n\tint m = i * permutationLength;\n\tint factorial = f(permutationLength);\n\tif (i \u003c factorial) {\n\t\tchar pT[8];\n\t\t//Fill the permutation array\n\t\tfor (int k = 0; k \u003c permutationLength; k++) {\n\t\t\tpermutation[k] = permutations[m + k];\n\t\t}\n\t\tbool found = true;\n\t\tfor (int c = 0; c \u003c textLength; c++) {\n\t\t\tint p = permutation[c % permutationLength];\n\t\t\tint j = (c / permutationLength) * permutationLength + p;\n\t\t\tpT[j] = text[c];\n\n\t\t\t//Dont bother going through all the text if one character is not same as the plain text.\n\t\t\tif (!(pT[j] == encrypted[j])) {\n\t\t\t\tfound = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tif (found) {\n\t\t\tprintf(\"\\n\\nAttack is successful! Permutation is: \");\n\t\t\tfor (int m = 0; m \u003c permutationLength; m++) {\n\t\t\t\tprintf(\"%d\", permutation[m]);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fparallel-permuation-cipher-attack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrilonaliu%2Fparallel-permuation-cipher-attack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrilonaliu%2Fparallel-permuation-cipher-attack/lists"}