{"id":23532602,"url":"https://github.com/conduition/cardseed","last_synced_at":"2025-05-14T16:19:30.057Z","repository":{"id":193542919,"uuid":"679947356","full_name":"conduition/cardseed","owner":"conduition","description":"Pseudo-random numbers derived from playing cards using PBKDF2.","archived":false,"fork":false,"pushed_at":"2023-09-08T17:02:02.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-14T16:19:19.288Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/conduition.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}},"created_at":"2023-08-18T01:50:22.000Z","updated_at":"2023-09-08T17:01:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"33899812-a141-4ea1-990a-ba22846d1a70","html_url":"https://github.com/conduition/cardseed","commit_stats":null,"previous_names":["conduition/cardseed"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fcardseed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fcardseed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fcardseed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/conduition%2Fcardseed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/conduition","download_url":"https://codeload.github.com/conduition/cardseed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254179900,"owners_count":22027884,"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":[],"created_at":"2024-12-25T23:11:51.591Z","updated_at":"2025-05-14T16:19:30.040Z","avatar_url":"https://github.com/conduition.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `cardseed`\n\nThe `cardseed` crate provides parsing and serializing of playing cards.\n\nIn cryptographic contexts, cards can be used to encode and generate entropy. A deck of 52 randomly shuffled playing cards encodes $52! \\approx 2^{228}$ different possible combinations. The `cardseed` crate makes it easy to parse and convert cards shuffled in the real world into secure pseudo-random data which can be used to derive encryption or signing keys, seed random number generators, or other such mischief.\n\n```rust\nuse cardseed::Deck;\nuse std::error::Error;\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    let deck = \"AS 3H KC 3C\".parse::\u003cDeck\u003e()?;\n    let secret = deck.hash(Some(\"bestpasswordever\"))?;\n    let expected = [35, 20, 205, 7, 35, 104, 123, 150, 57, 148, 101,\n                    109, 151, 0, 87, 15, 103, 14, 67, 214, 165, 165,\n                    44, 218, 5, 232, 30, 26, 100, 90, 169, 244];\n    assert_eq!(secret, expected);\n    Ok(())\n}\n```\n\n## Cards\n\nCards are composed of two fields: a `value` and a `suit`. The `value` field is a `u32` corresponding to the face value of the card, minus 1 (since we index from zero). The `suit` field is a `cardseed::Suit` enum member, corresponding to one of the four playing card suits.\n\nWhen serialized, a Card is represented as a string with two characters. The first character represents the face value of the card, and the second represents the suit. For instance, `\"7H\"` is the seven of hearts.\n\n### Face Values\n\n| Character | Card | Value |\n|:---------:|:----:|:-----:|\n| `A` | Ace | 0 |\n| `2` | 2 | 1 |\n| `3` | 3 | 2 |\n| `4` | 4 | 3 |\n| `5` | 5 | 4 |\n| `6` | 6 | 5 |\n| `7` | 7 | 6 |\n| `8` | 8 | 7 |\n| `9` | 9 | 8 |\n| `T` | Ten | 9 |\n| `J` | Jack | 10 |\n| `Q` | Queen | 11 |\n| `K` | King | 12 |\n\n### Suits\n\n| Character | Suit | Value |\n|:---------:|:----:|:-----:|\n| `S` | Spades | 0 |\n| `C` | Clubs | 1 |\n| `H` | Hearts | 2 |\n| `D` | Diamonds | 3 |\n\nAny card in a standard deck can be represented uniquely as any `u32` from 0 to 51, by multiplying the `suit` field's value by 13, and adding the card's `value` field.\n\n```rust\nuse cardseed::{Card, Suit};\n\nlet card = Card {\n    suit: Suit::Clubs,\n    value: 4,\n};\nassert_eq!(u32::from(card), 17);\n```\n\nFor instance, the card `\"TD\"`, the ten of diamonds, could be represented as the integer $(3 \\cdot 13) + 9 = 48$.\n\n## Decks\n\nA `Deck` is a vector of any number of cards. A `Deck` can be serialized and parsed as a string of serialized `Card`s, each `Card` string separated by whitespace.\n\n```rust\nuse cardseed::{Deck, Card, Suit};\nuse std::vec::Vec;\n\nlet deck = Deck {\n    cards: vec![\n        Card {\n            suit: Suit::Clubs,\n            value: 10,\n        },\n        Card {\n            suit: Suit::Hearts,\n            value: 12,\n        },\n        Card {\n            suit: Suit::Diamonds,\n            value: 1,\n        },\n    ],\n};\n\nlet deck_str = format!(\"{}\", deck);\nassert_eq!(deck_str, \"JC KH 2D\");\n\nlet parsed_deck = match deck_str.parse::\u003cDeck\u003e() {\n    Ok(deck) =\u003e deck,\n    Err(e) =\u003e panic!(\"failed to parse deck: {}\", e),\n};\nassert_eq!(parsed_deck, deck);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconduition%2Fcardseed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fconduition%2Fcardseed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fconduition%2Fcardseed/lists"}