{"id":18929771,"url":"https://github.com/kevincharm/gfc-fpe","last_synced_at":"2025-09-07T08:33:55.713Z","repository":{"id":160530692,"uuid":"635321257","full_name":"kevincharm/gfc-fpe","owner":"kevincharm","description":"Generalised Feistel cipher for stateless shuffling","archived":false,"fork":false,"pushed_at":"2024-04-21T22:56:41.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-30T17:40:38.352Z","etag":null,"topics":["cryptography","feistel","fpe","shuffle"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevincharm.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-02T12:54:24.000Z","updated_at":"2024-04-21T22:56:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"235e6683-19a3-43c6-9035-8121fbd0f5d6","html_url":"https://github.com/kevincharm/gfc-fpe","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/kevincharm/gfc-fpe","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevincharm%2Fgfc-fpe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevincharm%2Fgfc-fpe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevincharm%2Fgfc-fpe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevincharm%2Fgfc-fpe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevincharm","download_url":"https://codeload.github.com/kevincharm/gfc-fpe/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevincharm%2Fgfc-fpe/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274012428,"owners_count":25207248,"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-09-07T02:00:09.463Z","response_time":67,"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":["cryptography","feistel","fpe","shuffle"],"created_at":"2024-11-08T11:35:07.629Z","updated_at":"2025-09-07T08:33:55.693Z","avatar_url":"https://github.com/kevincharm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Feistel Shuffle (GFC-FPE)\n\n![Welcome to the crypto casino](https://user-images.githubusercontent.com/10385659/235708675-d264838a-b1fb-4084-8cbe-3b0abd6013f0.png)\n\nA generalised Feistel cipher that implements format-preserving encryption, bijectively mapping $X \\rightarrow X$ with pseudorandom permutation $\\pi^{S}$ determined by a random seed $S$. This algorithm was originally proposed by Black \u0026 Rogaway [1].\n\n## Iteration Bounds\n\nFor this implementation of the generalised Feistel cipher, the selection of parameters $a$ and $b$ for a cipher on domain $k$ are automatically chosen as $a = b = h = \\lceil \\sqrt{k} \\rceil$ (the _next perfect square_). This gives (from [1]):\n\n$$\n\\delta_{k} = 2 \\cdot \\sqrt{k} + 1\n$$\n\nwhere $\\delta_{k}$ denotes the number of elements that lie outside of the domain $k$ for which we need to perform an additional cycle-walk iteration.\n\nIt follows that the upper bound of cycle-walking iterations $C$ (from [2]) is denoted by:\n\n$$\nC = \\lceil \\frac{n}{h} \\rceil\n$$\n\n## Pseudorandom Round Functions\n\nWith an input domain $D$, the round function $f_i$ should output unique keys $K_0, ..., K_{r-1}$, where $D \\subset K$, that will be used as the round keys for $r$ rounds of Feistel.\n\n## Feistel Rounds\n\nAccording to [3], performing $r = 4$ rounds of Feistel is sufficient for CCA security (whatever the hell that is).\n\n## Randomness of Permutations\n\nWe do a little empirical testing to show the randomness of permutations generated by GFC-FPE.\n\nThe following figure shows the permuted indices (y-axis) for each input (x-axis) in a domain of size $10000$ with $r = 4$ Feistel rounds, using keccak256 and some 256-bit random seed as the pseudorandom function.\n\n![gfc_single](https://user-images.githubusercontent.com/10385659/235701085-ec598e00-9822-4101-b434-3426613e2037.png)\n\nThe following figure plots 10 instances of GFC-FPE outputs with the same configuration as above, but using a different 256-bit random seed for each instance.\n\n![gfc_10_runs](https://user-images.githubusercontent.com/10385659/235701120-0877141b-df82-428d-97c7-9803612d280c.png)\n\n## Literature\n\n[[1]](https://eprint.iacr.org/2001/012.pdf) John Black and Phillip Rogaway. 2002. Ciphers with arbitrary finite domains. In _Topics in Cryptology—CT-RSA 2002: The Cryptographers’ Track at the RSA Conference 2002 San Jose, CA, USA, February 18–22, 2002 Proceedings_, Springer, 114–130.\n\n[[2]](https://citeseerx.ist.psu.edu/document?repid=rep1\u0026type=pdf\u0026doi=44a92f047caf3e1b8f83375a9fcfb10aaa5380eb) Bruce Schneier and John Kelsey. 2005. Unbalanced Feistel networks and block cipher design. In _Fast Software Encryption: Third International Workshop Cambridge, UK, February 21–23 1996 Proceedings_, Springer, 121–144.\n\n[[3]](https://www.researchgate.net/profile/Michael-Luby-2/publication/220618451_How_to_Construct_Pseudorandom_Permutations_from_Pseudorandom_Functions/links/5fe0073aa6fdccdcb8ebce5d/How-to-Construct-Pseudorandom-Permutations-from-Pseudorandom-Functions.pdf) Michael Luby and Charles Rackoff. 1988. How to construct pseudorandom permutations from pseudorandom functions. _SIAM Journal on Computing_ 17, 2 (1988), 373–386.\n\n[[4]](https://www.iacr.org/archive/crypto2010/62230607/62230607.pdf) Viet Tung Hoang and Phillip Rogaway. 2010. On Generalized Feistel Networks. In _CRYPTO_, Springer, 613–630.\n\n[[5]](https://github.com/ethereum/research/blob/master/shuffling/feistel_shuffle.py) Vitalik Buterin. 2018. `feistel_shuffle.py`. In _ethereum/research_.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevincharm%2Fgfc-fpe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevincharm%2Fgfc-fpe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevincharm%2Fgfc-fpe/lists"}