{"id":25879816,"url":"https://github.com/constantin9845/trivium-encoder","last_synced_at":"2025-07-31T09:36:31.237Z","repository":{"id":255298572,"uuid":"848627592","full_name":"constantin9845/Trivium-encoder","owner":"constantin9845","description":"Trivium stream cipher implementation with cryptographically secure IV and Key generator.","archived":false,"fork":false,"pushed_at":"2025-04-08T08:27:04.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T08:35:33.322Z","etag":null,"topics":["cryptography","csprng","trivium"],"latest_commit_sha":null,"homepage":"","language":"C++","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/constantin9845.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-28T05:35:50.000Z","updated_at":"2025-04-08T08:27:08.000Z","dependencies_parsed_at":"2025-04-08T08:38:14.987Z","dependency_job_id":null,"html_url":"https://github.com/constantin9845/Trivium-encoder","commit_stats":null,"previous_names":["constantin9845/trivium-encoder"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/constantin9845/Trivium-encoder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constantin9845%2FTrivium-encoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constantin9845%2FTrivium-encoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constantin9845%2FTrivium-encoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constantin9845%2FTrivium-encoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/constantin9845","download_url":"https://codeload.github.com/constantin9845/Trivium-encoder/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/constantin9845%2FTrivium-encoder/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268017357,"owners_count":24181669,"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-31T02:00:08.723Z","response_time":66,"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","csprng","trivium"],"created_at":"2025-03-02T13:28:18.949Z","updated_at":"2025-07-31T09:36:31.229Z","avatar_url":"https://github.com/constantin9845.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trivium Stream Cipher\n\nA C++ library for encrypting and decrypting text/raw byte data using the **Trivium Stream Cipher** with a cryptographically secure key generator.\n\n## Overview\n\nThe **Trivium Stream Cipher** is a cryptographic algorithm that generates a pseudorandom bit stream used for encrypting data.\n\nThis C++ implementation of the Trivium cipher provides easy-to-use functions for encryption and decryption of text/byte data, with support for generating random keys and IVs, or using user-specified ones. The cipher operates at a high speed and is suitable for stream encryption in scenarios where lightweight, fast encryption is required.\n\nThe library allows:\n- **Random key and IV generation** for encryption,\n- **Encryption** of text/byte data using Trivium with customizable key and IV, and\n- **Decryption** of previously encrypted data.\n\n## Functions Overview:\n\nThe library provides the following functions for encryption and decryption:\n\n1. **`generateKeyIV()`**  \n   Generates a random **80-bit key and IV** stored in a bitset. It is used to initialize the Trivium cipher.\n\n2. **`generateKeyIV(int)`**  \n   Generates a random **80-bit key and IV** stored in unsiged char array. It is used to initialize the Trivium cipher.\n\n3. **`encrypt(const std::string\u0026 text)`**  \n   Encrypts a given **text** string using a randomly generated key and IV.\n\n4. **`encrypt(const std::string\u0026 text, const std::bitset\u003c80\u003e\u0026 key)`**  \n   Encrypts the **text** string using a user-provided **key** and a randomly generated IV.\n\n5. **`encrypt(const std::string\u0026 text, const std::bitset\u003c80\u003e\u0026 key, const std::bitset\u003c80\u003e\u0026 iv)`**  \n   Encrypts the **text** string using a user-provided **key** and **IV**.\n\n6. **`encrypt(unsigned char* input, const int\u0026 size)`**  \n   Encrypts a given **byte** array using a randomly generated key and IV.\n\n7. **`encrypt(unsigned char* input, const int\u0026 size, unsigned char* key)`**  \n   Encrypts the **byte** aarray using a user-provided **key** and a randomly generated IV.\n\n8. **`encrypt(unsigned char* input, const int\u0026 size, unsigned char* key, unsigned char* iv)`**  \n   Encrypts the **byte** array using a user-provided **key** and **IV**.\n\n9. **`decrypt(const std::string\u0026 content, const std::bitset\u003c80\u003e\u0026 key, const std::bitset\u003c80\u003e\u0026 iv)`**  \n   Decrypts the **content** using the provided **key** and **IV**.\n\n10. **`decrypt(unsigned char* input, unsigned char* key, unsigned char* iv, const int\u0026 size)`**  \n   Decrypts the **byte** array using the provided **key** and **IV**.\n\n\n## Return type\n\nThe encrypt/decrypt functions return a Trivium object that contains the output as well as the key/iv **if these were generated during run**.\n\n```cpp\n\n// Text data \nTrivium::Output enc = Trivium::encrypt(input);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      \nstd::cout\u003c\u003cenc.iv;       \n\nTrivium::Output enc = Trivium::encrypt(input, KEY);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      \nstd::cout\u003c\u003cenc.iv;       \n\nTrivium::Output enc = Trivium::encrypt(input, key, IV);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      \nstd::cout\u003c\u003cenc.iv;       \n\nTrivium::Output dec = Trivium::decrypt(input, key, IV);\nstd::cout\u003c\u003cdec.content;\nstd::cout\u003c\u003cenc.key;      \nstd::cout\u003c\u003cenc.iv;       \n\n// byte data\nTrivium::BitOutput enc = Trivium::encrypt(input, 16);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      \nstd::cout\u003c\u003cenc.iv;     \n\nTrivium::BitOutput enc = Trivium::encrypt(input, 16, key);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      // NULLPTR\nstd::cout\u003c\u003cenc.iv;  \n\nTrivium::BitOutput enc = Trivium::encrypt(input, 16, key, iv);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      // NULLPTR\nstd::cout\u003c\u003cenc.iv;       // NULLPTR\n\nTrivium::BitOutput enc = Trivium::decrypt(input, 16, key, iv);\nstd::cout\u003c\u003cenc.content;\nstd::cout\u003c\u003cenc.key;      // NULLPTR\nstd::cout\u003c\u003cenc.iv;       // NULLPTR \n```\n\n## Text Data Example\n\n```cpp\n#include \"trivium.h\"\n\nint main(){\n    std::string text = \"Hello, World!\";\n\n    std::bitset\u003c80\u003e key = Trivium::generateKeyIV();\n    std::bitset\u003c80\u003e iv = Trivium::generateKeyIV();\n\n    // Encrypt with random key and IV\n    Trivium::Output result1 = Trivium::encrypt(text);\n\n    // Encrypt with user-defined key and random IV\n    Trivium::Output result2 = Trivium::encrypt(text, key);\n\n    // Encrypt with user-defined key and IV\n    Trivium::Output result3 = Trivium::encrypt(text, key, iv);\n\n    // Output the encrypted text, key, and IV\n    std::cout \u003c\u003c \"Key: \" \u003c\u003c result1.key \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"IV: \" \u003c\u003c result1.iv \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"Encoded Text: \" \u003c\u003c result1.content \u003c\u003c std::endl;\n\n    // Decrypt the content using the same key and IV\n    Trivium::Output decryption = Trivium::decrypt(result1.content, result1.key, result1.iv);\n\n    // Output the decrypted text\n    std::cout \u003c\u003c \"Key: \" \u003c\u003c decryption.key \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"IV: \" \u003c\u003c decryption.iv \u003c\u003c std::endl;\n    std::cout \u003c\u003c \"Decoded Text: \" \u003c\u003c decryption.content \u003c\u003c std::endl;\n\n    return 0;\n}\n```\n\n## Byte Data Example\n\n```cpp\n#include \"trivium.h\"\n\nint main(){\n    unsigned char* input = new unsigned char[]{\n\t\t0x1f, 0xd4, 0xee, 0x65,\n\t\t0x60, 0x3e, 0x61, 0x30,\n\t\t0xcf, 0xc2, 0xa8, 0x2a,\n\t\t0xb3, 0xd5, 0x6c, 0x24\n\t};\n\n    unsigned char* key = Trivium::generateKeyIV(1);\n    unsigned char* iv = Trivium::generateKeyIV(1);\n\n    // Encrypt with random key and IV\n    Trivium::BitOutput result1 = Trivium::encrypt(input, 16);\n\n    // Encrypt with user-defined key and random IV\n    Trivium::BitOutput result2 = Trivium::encrypt(input, 16, key);\n\n    // Encrypt with user-defined key and IV\n    Trivium::BitOutput result3 = Trivium::encrypt(input, 16, key, iv);\n\n    // Output the encrypted text, key, and IV\n    std::cout \u003c\u003c \"Key: \" \u003c\u003c result1.key \u003c\u003c std::endl;\n    for(int i = 0; i \u003c 10; i++){\n        std::cout\u003c\u003cstd::hex\u003c\u003cstatic_cast\u003cint\u003e(result1.iv[i])\u003c\u003c\" \";\n    }\n    std::cout \u003c\u003c \"IV: \" \u003c\u003c result1.iv \u003c\u003c std::endl;\n    for(int i = 0; i \u003c 10; i++){\n        std::cout\u003c\u003cstd::hex\u003c\u003cstatic_cast\u003cint\u003e(result1.key[i])\u003c\u003c\" \";\n    }\n    std::cout \u003c\u003c \"Encoded Text:\" \u003c\u003cstd::endl;\n    for(int i = 0; i \u003c 16; i++){\n        std::cout\u003c\u003cstd::hex\u003c\u003cstatic_cast\u003cint\u003e(result1.content[i])\u003c\u003c\" \";\n    }\n\n    // Decrypt the content using the same key and IV\n    Trivium::BitOutput decryption = Trivium::decrypt(result1.content, result1.key, result1.iv);\n\n    // Output the decrypted text\n    std::cout \u003c\u003c \"Decoded Text:\" \u003c\u003cstd::endl;\n    for(int i = 0; i \u003c 16; i++){\n        std::cout\u003c\u003cstd::hex\u003c\u003cstatic_cast\u003cint\u003e(decryption.content[i])\u003c\u003c\" \";\n    }\n\n    return 0;\n}\n```\n\n\n## Additional guidelines\n\nIt is important to retain the key and IV after encryption. Decryption is not possible if lost.\n\nEach new encryption round, a new IV should be used. \nThe same key can be reused as long as a new IV was added.\n\n## Info\n\nWindows Key/IV generator not tested yet.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstantin9845%2Ftrivium-encoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconstantin9845%2Ftrivium-encoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconstantin9845%2Ftrivium-encoder/lists"}