Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.
Rust downloadmanagerguihacktoberfesthomebrewlightweightlinuxlinux-distributionlocal-firstmacosmacos-packagemedia-toolboxopen-sourcerustsveltetauritrendingtrending-repositorieswindowswindows-desktopytdlp
feat(p2p): add Pokémon wordlist and share code generation functions
Tonho2ee9790fe1b8
diff --git a/src-tauri/src/platforms/p2p/words.rs b/src-tauri/src/platforms/p2p/words.rsnew file mode 100644index 00000000..798a4c27--- /dev/null+++ b/src-tauri/src/platforms/p2p/words.rs@@ -0,0 +1,88 @@+/// 256 Pokémon names for generating human-friendly share codes.+/// 4 unique Pokémon = 32 bits of entropy, enough for LAN transfer identification.+pub static WORDLIST: [&str; 256] = [+ "bulbasaur", "ivysaur", "venusaur", "charmander", "charmeleon", "charizard", "squirtle", "wartortle",+ "blastoise", "caterpie", "butterfree", "weedle", "beedrill", "pidgey", "pidgeot", "rattata",+ "raticate", "spearow", "fearow", "ekans", "arbok", "pikachu", "raichu", "sandshrew",+ "sandslash", "nidoran", "nidorina", "nidoqueen", "nidorino", "nidoking", "clefairy", "clefable",+ "vulpix", "ninetales", "jigglypuff", "wigglytuff", "zubat", "golbat", "oddish", "gloom",+ "vileplume", "paras", "parasect", "venonat", "venomoth", "diglett", "dugtrio", "meowth",+ "persian", "psyduck", "golduck", "mankey", "primeape", "growlithe", "arcanine", "poliwag",+ "poliwhirl", "poliwrath", "abra", "kadabra", "alakazam", "machop", "machoke", "machamp",+ "bellsprout", "weepinbell", "victreebel", "tentacool", "tentacruel", "geodude", "graveler", "golem",+ "ponyta", "rapidash", "slowpoke", "slowbro", "magnemite", "magneton", "farfetchd", "doduo",+ "dodrio", "seel", "dewgong", "grimer", "muk", "shellder", "cloyster", "gastly",+ "haunter", "gengar", "onix", "drowzee", "hypno", "krabby", "kingler", "voltorb",+ "electrode", "exeggcute", "exeggutor", "cubone", "marowak", "hitmonlee", "hitmonchan", "lickitung",+ "koffing", "weezing", "rhyhorn", "rhydon", "chansey", "tangela", "kangaskhan", "horsea",+ "seadra", "goldeen", "seaking", "staryu", "starmie", "scyther", "jynx", "electabuzz",+ "magmar", "pinsir", "tauros", "magikarp", "gyarados", "lapras", "ditto", "eevee",+ "vaporeon", "jolteon", "flareon", "porygon", "omanyte", "omastar", "kabuto", "kabutops",+ "aerodactyl", "snorlax", "articuno", "zapdos", "moltres", "dratini", "dragonair", "dragonite",+ "mewtwo", "mew", "chikorita", "bayleef", "meganium", "cyndaquil", "quilava", "typhlosion",+ "totodile", "croconaw", "feraligatr", "sentret", "furret", "hoothoot", "noctowl", "ledyba",+ "spinarak", "ariados", "crobat", "chinchou", "lanturn", "pichu", "cleffa", "igglybuff",+ "togepi", "togetic", "natu", "xatu", "mareep", "flaaffy", "ampharos", "bellossom",+ "marill", "azumarill", "sudowoodo", "politoed", "hoppip", "skiploom", "jumpluff", "aipom",+ "sunkern", "sunflora", "yanma", "wooper", "quagsire", "espeon", "umbreon", "murkrow",+ "slowking", "misdreavus", "unown", "wobbuffet", "girafarig", "pineco", "forretress", "dunsparce",+ "gligar", "steelix", "snubbull", "granbull", "qwilfish", "scizor", "shuckle", "heracross",+ "sneasel", "teddiursa", "ursaring", "slugma", "magcargo", "swinub", "piloswine", "corsola",+ "remoraid", "octillery", "delibird", "mantine", "skarmory", "houndour", "houndoom", "kingdra",+ "phanpy", "donphan", "porygon2", "stantler", "smeargle", "tyrogue", "hitmontop", "smoochum",+ "elekid", "magby", "miltank", "blissey", "raikou", "entei", "suicune", "larvitar",+ "pupitar", "tyranitar", "lugia", "celebi", "treecko", "grovyle", "sceptile", "torchic",+ "combusken", "blaziken", "mudkip", "marshtomp", "swampert", "ralts", "gardevoir", "absol",+];++/// Generate a 4-word share code from random bytes.+/// Always picks 4 **different** Pokémon (no repeats).+pub fn generate_code() -> String {+ use rand::RngExt;+ let mut rng = rand::rng();+ let mut indices = Vec::with_capacity(4);++ while indices.len() < 4 {+ let idx: usize = rng.random_range(0..256);+ if !indices.contains(&idx) {+ indices.push(idx);+ }+ }++ indices+ .iter()+ .map(|&i| WORDLIST[i])+ .collect::<Vec<_>>()+ .join("-")+}++/// Look up a word's index in the wordlist. Returns None if not found.+pub fn word_index(word: &str) -> Option<u8> {+ let lower = word.to_lowercase();+ WORDLIST+ .iter()+ .position(|w| *w == lower)+ .map(|i| i as u8)+}++/// Validate that a string looks like a P2P share code (exactly 4 Pokémon names separated by dashes).+pub fn is_valid_code(s: &str) -> bool {+ let parts: Vec<&str> = s.split('-').collect();+ if parts.len() != 4 {+ return false;+ }+ // All 4 must be valid and unique+ let mut seen = Vec::with_capacity(4);+ for word in &parts {+ match word_index(word) {+ Some(idx) => {+ if seen.contains(&idx) {+ return false;+ }+ seen.push(idx);+ }+ None => return false,+ }+ }+ true+}