four-word-networking 2.4.0

Convert IP addresses to memorable, family-friendly word groups with autocomplete API. IPv4 = 4 words, IPv6 = 6-12 words. Perfect reconstruction with progressive hints and validation.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
#!/usr/bin/env python3
"""
Generate optimized wordlist using proper noun replacements for 5-character autocomplete.

This script creates an optimized version of GOLD_WORDLIST.txt by replacing problematic
words with proper nouns that have unique 5-character prefixes.
"""

import sys
from collections import defaultdict
from pathlib import Path


def read_wordlist(file_path):
    """Read words from the wordlist file."""
    words = []
    with open(file_path, "r", encoding="utf-8") as f:
        for line in f:
            word = line.strip()
            if word:
                words.append(word.lower())
    return words


def get_expanded_proper_nouns():
    """Comprehensive list of proper nouns across many categories."""

    proper_nouns = set()

    # Countries and territories
    proper_nouns.update(
        [
            "afghanistan",
            "albania",
            "algeria",
            "andorra",
            "angola",
            "argentina",
            "armenia",
            "australia",
            "austria",
            "azerbaijan",
            "bahamas",
            "bahrain",
            "bangladesh",
            "barbados",
            "belarus",
            "belgium",
            "belize",
            "benin",
            "bhutan",
            "bolivia",
            "bosnia",
            "botswana",
            "brazil",
            "brunei",
            "bulgaria",
            "burkina",
            "burundi",
            "cambodia",
            "cameroon",
            "canada",
            "cape",
            "central",
            "chad",
            "chile",
            "china",
            "colombia",
            "comoros",
            "congo",
            "costa",
            "croatia",
            "cuba",
            "cyprus",
            "czechia",
            "denmark",
            "djibouti",
            "dominica",
            "dominican",
            "ecuador",
            "egypt",
            "salvador",
            "equatorial",
            "eritrea",
            "estonia",
            "eswatini",
            "ethiopia",
            "fiji",
            "finland",
            "france",
            "gabon",
            "gambia",
            "georgia",
            "ghana",
            "greece",
            "grenada",
            "guatemala",
            "guinea",
            "guyana",
            "haiti",
            "honduras",
            "hungary",
            "iceland",
            "india",
            "indonesia",
            "iran",
            "iraq",
            "ireland",
            "israel",
            "italy",
            "ivory",
            "jamaica",
            "japan",
            "jordan",
            "kazakhstan",
            "kenya",
            "kiribati",
            "korea",
            "kosovo",
            "kuwait",
            "kyrgyzstan",
            "laos",
            "latvia",
            "lebanon",
            "lesotho",
            "liberia",
            "libya",
            "liechtenstein",
            "lithuania",
            "luxembourg",
            "madagascar",
            "malawi",
            "malaysia",
            "maldives",
            "mali",
            "malta",
            "marshall",
            "mauritania",
            "mauritius",
            "mexico",
            "micronesia",
            "moldova",
            "monaco",
            "mongolia",
            "montenegro",
            "morocco",
            "mozambique",
            "myanmar",
            "namibia",
            "nauru",
            "nepal",
            "netherlands",
            "zealand",
            "nicaragua",
            "niger",
            "nigeria",
            "north",
            "norway",
            "oman",
            "pakistan",
            "palau",
            "palestine",
            "panama",
            "papua",
            "paraguay",
            "peru",
            "philippines",
            "poland",
            "portugal",
            "qatar",
            "romania",
            "russia",
            "rwanda",
            "samoa",
            "marino",
            "sao",
            "saudi",
            "senegal",
            "serbia",
            "seychelles",
            "sierra",
            "singapore",
            "slovakia",
            "slovenia",
            "solomon",
            "somalia",
            "south",
            "spain",
            "lanka",
            "sudan",
            "suriname",
            "sweden",
            "switzerland",
            "syria",
            "taiwan",
            "tajikistan",
            "tanzania",
            "thailand",
            "togo",
            "tonga",
            "trinidad",
            "tunisia",
            "turkey",
            "turkmenistan",
            "tuvalu",
            "uganda",
            "ukraine",
            "emirates",
            "united",
            "uruguay",
            "uzbekistan",
            "vanuatu",
            "vatican",
            "venezuela",
            "vietnam",
            "yemen",
            "zambia",
            "zimbabwe",
        ]
    )

    # Major cities
    proper_nouns.update(
        [
            "abuja",
            "accra",
            "addis",
            "adelaide",
            "algiers",
            "almaty",
            "amman",
            "amsterdam",
            "ankara",
            "antananarivo",
            "apia",
            "ashgabat",
            "asmara",
            "astana",
            "asuncion",
            "athens",
            "atlanta",
            "auckland",
            "baghdad",
            "baku",
            "bamako",
            "bandar",
            "bangalore",
            "bangkok",
            "bangui",
            "banjul",
            "barcelona",
            "basseterre",
            "beijing",
            "beirut",
            "belgrade",
            "belmopan",
            "berlin",
            "bern",
            "bishkek",
            "bissau",
            "bogota",
            "brasilia",
            "bratislava",
            "brazzaville",
            "bridgetown",
            "brisbane",
            "brussels",
            "bucharest",
            "budapest",
            "buenos",
            "bujumbura",
            "cairo",
            "calgary",
            "canberra",
            "cape",
            "caracas",
            "castries",
            "cayenne",
            "chicago",
            "chisinau",
            "cologne",
            "colombo",
            "conakry",
            "copenhagen",
            "dakar",
            "dallas",
            "damascus",
            "delhi",
            "dhaka",
            "dili",
            "djibouti",
            "dodoma",
            "doha",
            "dublin",
            "dushanbe",
            "edinburgh",
            "florence",
            "frankfurt",
            "freetown",
            "funafuti",
            "gaborone",
            "geneva",
            "georgetown",
            "glasgow",
            "guatemala",
            "hamburg",
            "hanoi",
            "harare",
            "havana",
            "helsinki",
            "honiara",
            "houston",
            "islamabad",
            "istanbul",
            "jakarta",
            "juba",
            "kabul",
            "kampala",
            "kathmandu",
            "khartoum",
            "kigali",
            "kingston",
            "kingstown",
            "kinshasa",
            "kuala",
            "kuwait",
            "lagos",
            "leipzig",
            "libreville",
            "lilongwe",
            "lima",
            "lisbon",
            "ljubljana",
            "lome",
            "london",
            "luanda",
            "lusaka",
            "madrid",
            "majuro",
            "malabo",
            "male",
            "managua",
            "manama",
            "manila",
            "maputo",
            "marseille",
            "maseru",
            "mbabane",
            "melbourne",
            "mexico",
            "miami",
            "milan",
            "minsk",
            "mogadishu",
            "monaco",
            "monrovia",
            "montevideo",
            "montreal",
            "moroni",
            "moscow",
            "mumbai",
            "munich",
            "muscat",
            "nairobi",
            "nassau",
            "ndjamena",
            "niamey",
            "nicosia",
            "nouakchott",
            "nukualofa",
            "oslo",
            "ottawa",
            "ouagadougou",
            "panama",
            "paramaribo",
            "paris",
            "perth",
            "phnom",
            "podgorica",
            "port",
            "porto",
            "prague",
            "praia",
            "pretoria",
            "pristina",
            "pyongyang",
            "quito",
            "rabat",
            "reykjavik",
            "riga",
            "riyadh",
            "rome",
            "roseau",
            "saint",
            "san",
            "sanaa",
            "santiago",
            "santo",
            "sao",
            "sarajevo",
            "seattle",
            "seoul",
            "shanghai",
            "singapore",
            "skopje",
            "sofia",
            "stockholm",
            "sucre",
            "suva",
            "sydney",
            "taipei",
            "tallinn",
            "tarawa",
            "tashkent",
            "tbilisi",
            "tegucigalpa",
            "tehran",
            "thimphu",
            "tirana",
            "tokyo",
            "toronto",
            "tripoli",
            "tunis",
            "ulaanbaatar",
            "vaduz",
            "valletta",
            "vancouver",
            "vatican",
            "venice",
            "victoria",
            "vienna",
            "vientiane",
            "vilnius",
            "warsaw",
            "washington",
            "wellington",
            "windhoek",
            "yaounde",
            "yaren",
            "yerevan",
            "zagreb",
            "zurich",
        ]
    )

    # Common names
    proper_nouns.update(
        [
            "aaron",
            "abdul",
            "abraham",
            "adam",
            "adrian",
            "ahmed",
            "akira",
            "alan",
            "albert",
            "alejandro",
            "alexander",
            "alfred",
            "alice",
            "amanda",
            "amy",
            "andrew",
            "angela",
            "anna",
            "anthony",
            "antonio",
            "arthur",
            "barbara",
            "beatrice",
            "benjamin",
            "bernard",
            "betty",
            "brian",
            "bruce",
            "carlos",
            "carol",
            "catherine",
            "charles",
            "chris",
            "christian",
            "christine",
            "christopher",
            "claudia",
            "daniel",
            "david",
            "deborah",
            "dennis",
            "diana",
            "diane",
            "dmitri",
            "donald",
            "donna",
            "dorothy",
            "douglas",
            "edward",
            "elena",
            "elizabeth",
            "emily",
            "eric",
            "eugene",
            "evelyn",
            "fernando",
            "francesco",
            "francis",
            "francisco",
            "frank",
            "gary",
            "george",
            "giovanni",
            "giuseppe",
            "gloria",
            "gonzalez",
            "gregory",
            "harold",
            "helen",
            "helena",
            "henry",
            "ibrahim",
            "irene",
            "isaac",
            "isabella",
            "jackie",
            "jacob",
            "jacques",
            "james",
            "janet",
            "jason",
            "jean",
            "jeffrey",
            "jennifer",
            "jeremy",
            "jerry",
            "jessica",
            "joan",
            "johannes",
            "jonathan",
            "jorge",
            "jose",
            "joseph",
            "joshua",
            "juan",
            "judith",
            "julia",
            "julie",
            "justin",
            "karen",
            "kathleen",
            "kenneth",
            "kevin",
            "kimberly",
            "larry",
            "laura",
            "lawrence",
            "leonardo",
            "linda",
            "lisa",
            "lorenzo",
            "louis",
            "luis",
            "mahmoud",
            "margaret",
            "maria",
            "marie",
            "mario",
            "mark",
            "martin",
            "martinez",
            "mary",
            "matthew",
            "maxime",
            "melissa",
            "michael",
            "michelle",
            "miguel",
            "mohammed",
            "nancy",
            "natasha",
            "nicholas",
            "nicolas",
            "nicole",
            "olivier",
            "patricia",
            "patrick",
            "paul",
            "peter",
            "philippe",
            "rachel",
            "rafael",
            "raymond",
            "rebecca",
            "ricardo",
            "richard",
            "robert",
            "roberto",
            "rodrigo",
            "ronald",
            "ruth",
            "sandra",
            "sarah",
            "scott",
            "sebastian",
            "sharon",
            "stephanie",
            "stephen",
            "steven",
            "susan",
            "theodore",
            "thomas",
            "timothy",
            "valentina",
            "valerie",
            "victoria",
            "vincent",
            "vladimir",
            "walter",
            "william",
            "wolfgang",
            "xavier",
        ]
    )

    # Rivers and landmarks
    proper_nouns.update(
        [
            "amazon",
            "brahmaputra",
            "colorado",
            "columbia",
            "congo",
            "danube",
            "dnieper",
            "euphrates",
            "ganges",
            "hudson",
            "indus",
            "irrawaddy",
            "jordan",
            "lena",
            "mackenzie",
            "mekong",
            "mississippi",
            "missouri",
            "murray",
            "niger",
            "nile",
            "orinoco",
            "rhine",
            "rio",
            "thames",
            "tigris",
            "volga",
            "yangtze",
            "yellow",
            "yukon",
            "zambezi",
        ]
    )

    # Mountains
    proper_nouns.update(
        [
            "aconcagua",
            "alps",
            "andes",
            "annapurna",
            "appalachian",
            "atlas",
            "caucasus",
            "denali",
            "everest",
            "fuji",
            "himalaya",
            "kilimanjaro",
            "matterhorn",
            "mckinley",
            "mont",
            "olympus",
            "rockies",
            "ural",
            "vesuvius",
        ]
    )

    # Historical figures
    proper_nouns.update(
        [
            "archimedes",
            "aristotle",
            "augustus",
            "bach",
            "beethoven",
            "caesar",
            "churchill",
            "cleopatra",
            "columbus",
            "confucius",
            "copernicus",
            "darwin",
            "edison",
            "einstein",
            "franklin",
            "galileo",
            "gandhi",
            "hamilton",
            "homer",
            "jefferson",
            "leonardo",
            "lincoln",
            "michelangelo",
            "mozart",
            "napoleon",
            "newton",
            "picasso",
            "plato",
            "shakespeare",
            "socrates",
            "tesla",
            "voltaire",
            "washington",
        ]
    )

    # Brands
    proper_nouns.update(
        [
            "adobe",
            "boeing",
            "canon",
            "cisco",
            "coca",
            "dell",
            "disney",
            "fedex",
            "ferrari",
            "ford",
            "hyundai",
            "ibm",
            "mercedes",
            "nike",
            "oracle",
            "pepsi",
            "siemens",
            "volkswagen",
            "walmart",
            "xerox",
        ]
    )

    # Mythology
    proper_nouns.update(
        [
            "apollo",
            "ares",
            "artemis",
            "athena",
            "atlas",
            "buddha",
            "ceres",
            "diana",
            "hades",
            "hera",
            "hercules",
            "hermes",
            "isis",
            "juno",
            "jupiter",
            "mars",
            "mercury",
            "minerva",
            "neptune",
            "odin",
            "osiris",
            "pluto",
            "poseidon",
            "saturn",
            "thor",
            "venus",
            "zeus",
        ]
    )

    return proper_nouns


def calculate_min_prefix_lengths(words):
    """Calculate minimum prefix length needed to uniquely identify each word."""
    word_to_min_prefix = {}

    for word in words:
        min_length = 1

        while min_length <= len(word):
            prefix = word[:min_length]
            conflicts = [w for w in words if w != word and w.startswith(prefix)]

            if not conflicts:
                word_to_min_prefix[word] = min_length
                break

            min_length += 1

        if word not in word_to_min_prefix:
            word_to_min_prefix[word] = len(word)

    return word_to_min_prefix


def find_conflict_groups(words, max_prefix_length=5):
    """Find groups of words that conflict within the given prefix length."""
    prefix_to_words = defaultdict(list)

    for word in words:
        prefix = word[:max_prefix_length]
        prefix_to_words[prefix].append(word)

    return {
        prefix: word_list
        for prefix, word_list in prefix_to_words.items()
        if len(word_list) > 1
    }


def select_optimal_replacements(words, proper_nouns, target_prefix_length=5):
    """Select optimal word replacements using proper nouns."""

    # Calculate current problematic words
    word_to_min_prefix = calculate_min_prefix_lengths(words)
    problematic_words = [
        word
        for word, min_len in word_to_min_prefix.items()
        if min_len > target_prefix_length
    ]

    # Find unique proper nouns (no conflicts with existing words or other proper nouns)
    unique_proper_nouns = []
    for noun in proper_nouns:
        noun_prefix = noun[:target_prefix_length]
        # Check conflicts with existing dictionary
        conflicts_existing = [w for w in words if w.startswith(noun_prefix)]
        # Check conflicts with other proper nouns
        conflicts_nouns = [
            n for n in proper_nouns if n != noun and n.startswith(noun_prefix)
        ]

        if not conflicts_existing and not conflicts_nouns:
            unique_proper_nouns.append(noun)

    print(
        f"Found {len(unique_proper_nouns)} unique proper nouns for {len(problematic_words)} problematic words"
    )

    # Get conflict groups to prioritize high-impact replacements
    conflict_groups = find_conflict_groups(words, target_prefix_length)

    # Strategy: Replace words that resolve the most conflicts first
    replacements = {}
    used_proper_nouns = set()
    remaining_problematic = set(problematic_words)

    # Sort conflict groups by size (largest first)
    sorted_conflicts = sorted(
        conflict_groups.items(), key=lambda x: len(x[1]), reverse=True
    )

    for prefix, conflict_words in sorted_conflicts:
        # Find problematic words in this conflict group
        group_problematic = [w for w in conflict_words if w in remaining_problematic]

        if group_problematic and unique_proper_nouns:
            # Choose the most problematic word to replace (longest or most complex)
            word_to_replace = max(
                group_problematic, key=lambda w: (word_to_min_prefix[w], len(w))
            )

            # Find a suitable proper noun replacement
            available_nouns = [
                n for n in unique_proper_nouns if n not in used_proper_nouns
            ]
            if available_nouns:
                replacement_noun = available_nouns[0]
                replacements[word_to_replace] = replacement_noun
                used_proper_nouns.add(replacement_noun)
                remaining_problematic.discard(word_to_replace)
                print(
                    f"Replace '{word_to_replace}' → '{replacement_noun}' (resolves {len(conflict_words)} conflicts in '{prefix}' group)"
                )

    # Fill remaining slots with any problematic words we can replace
    remaining_nouns = [n for n in unique_proper_nouns if n not in used_proper_nouns]
    for word in list(remaining_problematic):
        if remaining_nouns:
            replacement = remaining_nouns.pop(0)
            replacements[word] = replacement
            used_proper_nouns.add(replacement)
            remaining_problematic.discard(word)

    print(f"\nTotal replacements planned: {len(replacements)}")
    print(f"Problematic words remaining: {len(remaining_problematic)}")

    return replacements


def generate_optimized_wordlist(input_file, output_file, replacements):
    """Generate the optimized wordlist with replacements."""

    words = read_wordlist(input_file)

    # Apply replacements
    optimized_words = []
    replacement_count = 0

    for word in words:
        if word in replacements:
            optimized_words.append(replacements[word])
            replacement_count += 1
        else:
            optimized_words.append(word)

    # Verify we still have 4096 words
    assert len(optimized_words) == len(
        words
    ), f"Word count mismatch: {len(optimized_words)} vs {len(words)}"

    # Sort the optimized words for consistency
    optimized_words.sort()

    # Write to output file
    with open(output_file, "w", encoding="utf-8") as f:
        for word in optimized_words:
            f.write(f"{word}\n")

    print(f"\nOptimized wordlist generated:")
    print(f"  Input: {input_file} ({len(words)} words)")
    print(f"  Output: {output_file} ({len(optimized_words)} words)")
    print(f"  Replacements applied: {replacement_count}")

    return optimized_words


def main():
    input_file = "GOLD_WORDLIST.txt"
    output_file = "GOLD_WORDLIST_OPTIMIZED.txt"

    if not Path(input_file).exists():
        print(f"Error: {input_file} not found!")
        sys.exit(1)

    print("=" * 80)
    print("GENERATING OPTIMIZED WORDLIST FOR 5-CHARACTER AUTOCOMPLETE")
    print("=" * 80)
    print()

    # Load data
    print("Loading wordlist and proper nouns...")
    words = read_wordlist(input_file)
    proper_nouns = get_expanded_proper_nouns()

    print(f"Current dictionary: {len(words)} words")
    print(f"Proper noun candidates: {len(proper_nouns)} words")
    print()

    # Find optimal replacements
    print("Calculating optimal replacements...")
    replacements = select_optimal_replacements(words, proper_nouns, 5)
    print()

    # Generate optimized wordlist
    print("Generating optimized wordlist...")
    optimized_words = generate_optimized_wordlist(input_file, output_file, replacements)

    print(f"\n✅ Successfully generated {output_file}")
    print("\nNext steps:")
    print("1. Run validation script to verify 5-character uniqueness")
    print("2. Test compatibility with four-word networking system")
    print("3. Generate analysis report")


if __name__ == "__main__":
    main()