Fine-tuned LLMs correctly migrate 92.5% of code fragments to post-quantum cryptography
Fine-tuned large language models can reliably translate pre-quantum cryptographic code to post-quantum equivalents while preserving functional correctness
Security & privacy arXiv 5 Jun 2026 Measurement Prototype evidence
Published as “Empirical Evaluation of Large Language Models for Migration of Code Fragments to Post-Quantum Cryptography”
Why it matters
Fine-tuned LLMs can automate many PQC code migrations, dramatically reducing manual effort, but human review remains necessary for complex, multi-file transformations.
Summary
Fine-tuned GPT-4.1-mini achieves 92.5 % functional correctness on a synthetic dataset of ~800 pre-to-post-quantum code pairs, far outperforming zero-shot GPT-4.1 (≈15 % success). The study also provides the first reproducible PQC migration dataset, a verification pipeline, and shows mixed results on real-world repositories, with failures on complex, multi-file cases.
What they found 2
- Fine-tuned GPT-4.1-mini attains high functional success on synthetic migrations.
“the model reached a 92.5 % success rate, meaning that the vast majority of migrated scripts not only execute successfully (are syntactically valid and runnable under the Python interpreter) but also pass the functional tests (encrypt/decrypt, sign/verify, encaps/decaps) without manual fixes.”
- Zero-shot GPT-4.1 performs poorly on functional correctness.
“only about 15 % of zero-shot GPT-4.1 outputs were functionally executable without manual intervention.”
Caveats 5
- Real-world evaluation shows failures on complex projects, e.g., python-jose suffered structural inconsistency and dependency conflicts.
- The remaining functional failures are concentrated mainly in structurally complex cases, especially key exchange and combined primitive migrations.
- While this manual labelling step limits scalability, it guarantees correctness during evaluation.
- multiple primitives and interdependent APIs caused structural inconsistencies in the output, leading to non-executable code.
- The main residual weaknesses of the fine-tuned model involve API contracts, namespace management, function signatures, and key-material representation.
What’s new here 4
- Introduces a publicly released dataset of ~800 verified pre-to-post-quantum code pairs for benchmarking LLM migration.
- Implements an automated verification pipeline that checks static similarity, dynamic execution, and cryptographic correctness.
- Evaluates fine-tuned LLMs (GPT-4.1-mini, CodeLlama-7B) for end-to-end PQC code migration, a task not previously studied.
- Maps the migration workflow to enterprise crypto-agility frameworks, demonstrating practical integration.