{"id":22526132,"url":"https://github.com/maxmouchet/gfc","last_synced_at":"2025-10-11T17:33:32.386Z","repository":{"id":39155357,"uuid":"346752517","full_name":"maxmouchet/gfc","owner":"maxmouchet","description":"Implementation of a Generalized-Feistel Cipher for generating random permutations.","archived":false,"fork":false,"pushed_at":"2025-07-01T07:28:51.000Z","size":65,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-27T04:13:37.916Z","etag":null,"topics":["feistel-cipher","random-permutations","speck"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxmouchet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-11T15:43:15.000Z","updated_at":"2025-07-20T13:56:27.000Z","dependencies_parsed_at":"2023-02-17T02:00:44.944Z","dependency_job_id":null,"html_url":"https://github.com/maxmouchet/gfc","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/maxmouchet/gfc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmouchet%2Fgfc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmouchet%2Fgfc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmouchet%2Fgfc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmouchet%2Fgfc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxmouchet","download_url":"https://codeload.github.com/maxmouchet/gfc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmouchet%2Fgfc/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267320257,"owners_count":24068527,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["feistel-cipher","random-permutations","speck"],"created_at":"2024-12-07T06:13:53.964Z","updated_at":"2025-10-11T17:33:27.367Z","avatar_url":"https://github.com/maxmouchet.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎲 gfc — fast \u0026 lazy random permutations\n\n[![Tests Status](https://img.shields.io/github/actions/workflow/status/maxmouchet/gfc/tests.yml?logo=github\u0026label=tests)](https://github.com/maxmouchet/gfc/actions/workflows/tests.yml)\n[![PyPI](https://img.shields.io/pypi/v/pygfc?color=blue\u0026logo=pypi\u0026logoColor=white)](https://pypi.org/project/pygfc/)\n\ngfc is a C implementation of a Generalized-Feistel Cipher [[1, alg. 3]](#1) for generating random permutations.  \nIt uses [Speck](https://en.wikipedia.org/wiki/Speck_%28cipher%29) 64/128 as the random function, and can generate permutations with up to `2^64` elements.  \nThe permutation is computed, and reversed, _on-the-fly_, without any mutable state and by using very little memory.\n\n## Usage\n\n### C / C++\n\n#### API\n\n```c\n#include \u003cgfc/gfc.h\u003e\nGFC* gfc_init(uint64_t range, uint64_t rounds, uint64_t seed);\nvoid gfc_destroy(GFC* gfc);\nuint64_t gfc_decrypt(const GFC* gfc, uint64_t m);\nuint64_t gfc_encrypt(const GFC* gfc, uint64_t m);\n```\n\n#### Example\n\n```c\n// main.c\n// gcc -Iinclude/ src/gfc.c main.c -o main\n#include \u003cassert.h\u003e\n#include \u003cgfc/gfc.h\u003e\n\nint main() {\n  GFC* gfc = gfc_init(65536, 6, 42);\n  \n  for (uint64_t i = 0; i \u003c 65536; i++) {\n    uint64_t enc = gfc_encrypt(gfc, i);\n    uint64_t dec = gfc_decrypt(gfc, enc);\n    assert(enc != i);\n    assert(dec == i);\n  }\n\n  gfc_destroy(gfc);\n  return 0;\n}\n```\n\n#### CMake Integration\n\n```cmake\ncmake_minimum_required(VERSION 3.12)\nproject(example)\nadd_subdirectory(gfc)\nadd_executable(main main.c)\ntarget_link_libraries(main PRIVATE gfc)\n```\n\n```bash\ngit submodule add https://github.com/maxmouchet/gfc.git\nmkdir build \u0026\u0026 cd build\ncmake .. \u0026\u0026 cmake --build .\n./main\n```\n\n### Python\n\n```\npip install pygfc\n```\n\n```python\nfrom pygfc import Permutation\n# Permutation(range, rounds, seed)\nperm = Permutation(2 ** 16, 8, 42)\nassert set(perm) == set(range(2 ** 16))\nassert all(perm.inv(perm[i]) == i for i in range(2 ** 16))\n```\n\n## Dependencies\n\nThe Speck implementation is from [madmo/speck](https://github.com/madmo/speck) and is licensed under the ISC license (MIT-compatible).  \n\n## References\n\n\u003ca id=\"1\"\u003e[1]\u003c/a\u003e Black, John, and Phillip Rogaway. \"Ciphers with arbitrary finite domains.\" _Cryptographers’ track at the RSA conference_. Springer, Berlin, Heidelberg, 2002.\nhttps://web.cs.ucdavis.edu/~rogaway/papers/subset.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxmouchet%2Fgfc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxmouchet%2Fgfc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxmouchet%2Fgfc/lists"}