The Naibbe cipher
#67
(13-08-2025, 06:45 PM)RobGea wrote: You are not allowed to view links. Register or Login to view.i would be interested to know which "language-independent morphological parser" you used. Web-based or software or whatever, thanks

First, you need to install Pandas for Python:
pip3 install pandas seaborn matplotlib

I wrote a Python script that does this job.
Call example (the number is variable and specifies how many top n combinations are output):

python parser.py naibbe_Cleaned_52_01_10_word_lines.txt parsed.txt 25

Code:
#!/usr/bin/env python3 import sys import re from collections import Counter def find_affixes(words, min_prefix_len=2, min_suffix_len=2, top_n=None):     prefixes = Counter()     suffixes = Counter()     for w in words:         if len(w) >= min_prefix_len:             for i in range(min_prefix_len, min(len(w), 6)):                 prefixes[w[:i]] += 1         if len(w) >= min_suffix_len:             for i in range(min_suffix_len, min(len(w), 6)):                 suffixes[w[-i:]] += 1     if top_n is None:         return prefixes.most_common(), suffixes.most_common()     else:         return prefixes.most_common(top_n), suffixes.most_common(top_n) def segment_word_multi(word, prefix_set, suffix_set):     parts = []     stem = word     # Mehrere Präfixe entfernen     while True:         match = None         for p in sorted(prefix_set, key=len, reverse=True):             if stem.startswith(p) and len(stem) > len(p) + 1:                 match = p                 break         if match:             parts.append(match)             stem = stem[len(match):]         else:             break     suffix_parts = []     # Mehrere Suffixe entfernen     while True:         match = None         for s in sorted(suffix_set, key=len, reverse=True):             if stem.endswith(s) and len(stem) > len(s) + 1:                 match = s                 break         if match:             suffix_parts.insert(0, match)             stem = stem[:-len(match)]         else:             break     parts.append(stem)     parts.extend(suffix_parts)     return parts def find_stem(parts, prefix_set, suffix_set):     for p in parts:         if p not in prefix_set and p not in suffix_set:             return p     return "" def main():     argc = len(sys.argv)     if argc < 3 or argc > 4:         print(f"Usage: {sys.argv[0]} <input_file> <output_file> [top_n|'all']")         sys.exit(1)     input_file = sys.argv[1]     output_file = sys.argv[2]     top_n = 10  # Standardwert     if argc == 4:         param = sys.argv[3].lower()         if param == "all":             top_n = None  # Alle ausgeben         else:             try:                 top_n = int(param)                 if top_n < 1:                     raise ValueError()             except ValueError:                 print("Der dritte Parameter muss eine positive ganze Zahl oder 'all' sein.")                 sys.exit(1)     with open(input_file, "r", encoding="utf-8") as f:         text = f.read()     words = [w.lower() for w in re.findall(r"[A-Za-z]+", text)]     top_prefixes, top_suffixes = find_affixes(words, top_n=top_n)     prefix_set = {p for p, _ in top_prefixes}     suffix_set = {s for s, _ in top_suffixes}     stem_counter = Counter()     def replacer(match):         token = match.group(0)         parts = segment_word_multi(token.lower(), prefix_set, suffix_set)         stem = find_stem(parts, prefix_set, suffix_set)         stem_counter[stem] += 1         segmented = "/".join(parts)         if token[0].isupper():             segmented = segmented.capitalize()         return segmented     output_text = re.sub(r"[A-Za-z]+", replacer, text)     with open(output_file, "w", encoding="utf-8") as f:         f.write(output_text)         f.write("\n\n=== Präfixe ===\n")         for p, c in top_prefixes:             f.write(f"{p}\t{c}\n")         f.write("\n=== Stämme ===\n")         for s, c in stem_counter.most_common():             if s != "":                 f.write(f"{s}\t{c}\n")         f.write("\n=== Suffixe ===\n")         for s, c in top_suffixes:             f.write(f"{s}\t{c}\n") if __name__ == "__main__":     main()

For the heat map, the call is as follows:

python heatmap_prefix_suffix.py parsed.txt 25

Code:
#!/usr/bin/env python3 import sys from collections import Counter import pandas as pd import seaborn as sns import matplotlib.pyplot as plt def extract_prefix_suffix(word):     parts = word.split('/')     if len(parts) < 3:         return [], [], None     stem_index = len(parts) // 2     prefix = parts[:stem_index]     suffix = parts[stem_index+1:]     return prefix, suffix, parts[stem_index] def main():     if len(sys.argv) < 2:         print("Usage: python heatmap_prefix_suffix.py output_segmented.txt [N]")         sys.exit(1)     filename = sys.argv[1]     top_n = 20  # default number of top prefixes and suffixes     if len(sys.argv) >= 3:         try:             top_n = int(sys.argv[2])         except ValueError:             print("Parameter N must be an integer.")             sys.exit(1)     prefix_suffix_counts = Counter()     with open(filename, 'r', encoding='utf-8') as f:         for line in f:             words = line.strip().split()             for w in words:                 prefix, suffix, stem = extract_prefix_suffix(w)                 for pre in prefix:                     for suf in suffix:                         prefix_suffix_counts[(pre, suf)] += 1     if not prefix_suffix_counts:         print("No prefix-suffix combinations found.")         sys.exit(1)     data = []     for (pre, suf), count in prefix_suffix_counts.items():         data.append({"prefix": pre, "suffix": suf, "count": count})     df = pd.DataFrame(data)     # Select top N prefixes and suffixes by total count     top_prefixes = df.groupby('prefix')['count'].sum().nlargest(top_n).index     top_suffixes = df.groupby('suffix')['count'].sum().nlargest(top_n).index     pivot = df.pivot(index='prefix', columns='suffix', values='count').fillna(0)     pivot_top = pivot.loc[top_prefixes, top_suffixes]     plt.figure(figsize=(18, 12))     sns.heatmap(pivot_top, annot=True, fmt=".0f", cmap="YlGnBu", cbar_kws={"shrink": 0.5})     plt.title(f"Top {top_n} Prefix-Suffix Combinations")     plt.xlabel("Suffix")     plt.ylabel("Prefix")     plt.xticks(rotation=45, ha='right', fontsize=12)     plt.yticks(rotation=0, fontsize=12)  # Präfix-Beschriftungen waagerecht     plt.subplots_adjust(bottom=0.2)  # make space for xlabel     plt.show() if __name__ == "__main__":     main()
[+] 1 user says Thank You to bi3mw for this post
Reply


Messages In This Thread
The Naibbe cipher - by magnesium - 03-08-2025, 04:18 PM
RE: The Naibbe cipher - by bi3mw - 03-08-2025, 04:46 PM
RE: The Naibbe cipher - by magnesium - 03-08-2025, 06:45 PM
RE: The Naibbe cipher - by oshfdk - 03-08-2025, 10:24 PM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 02:24 AM
RE: The Naibbe cipher - by oshfdk - 04-08-2025, 08:57 AM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 10:37 AM
RE: The Naibbe cipher - by oshfdk - 04-08-2025, 10:56 AM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 11:28 AM
RE: The Naibbe cipher - by pfeaster - 04-08-2025, 01:31 PM
RE: The Naibbe cipher - by oshfdk - 04-08-2025, 01:55 PM
RE: The Naibbe cipher - by Yavernoxia - 04-08-2025, 02:02 PM
RE: The Naibbe cipher - by oshfdk - 04-08-2025, 02:32 PM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 02:30 PM
RE: The Naibbe cipher - by oshfdk - 04-08-2025, 02:57 PM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 03:18 PM
RE: The Naibbe cipher - by bi3mw - 03-08-2025, 10:38 PM
RE: The Naibbe cipher - by oshfdk - 03-08-2025, 10:44 PM
RE: The Naibbe cipher - by MarcoP - 04-08-2025, 10:17 AM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 02:34 AM
RE: The Naibbe cipher - by Yavernoxia - 04-08-2025, 11:03 AM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 11:47 AM
RE: The Naibbe cipher - by Yavernoxia - 04-08-2025, 12:12 PM
RE: The Naibbe cipher - by Mauro - 04-08-2025, 02:21 PM
RE: The Naibbe cipher - by MarcoP - 04-08-2025, 04:28 PM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 06:33 PM
RE: The Naibbe cipher - by oshfdk - 04-08-2025, 06:50 PM
RE: The Naibbe cipher - by magnesium - 04-08-2025, 07:37 PM
RE: The Naibbe cipher - by RobGea - 04-08-2025, 06:18 PM
RE: The Naibbe cipher - by Juan_Sali - 05-08-2025, 12:15 AM
~ - by magnesium - 05-08-2025, 01:33 AM
RE: The Naibbe cipher - by MarcoP - 05-08-2025, 07:35 AM
RE: The Naibbe cipher - by Koen G - 05-08-2025, 08:31 AM
RE: The Naibbe cipher - by magnesium - 05-08-2025, 12:35 PM
RE: The Naibbe cipher - by Rafal - 05-08-2025, 01:19 PM
RE: The Naibbe cipher - by magnesium - 05-08-2025, 02:17 PM
RE: The Naibbe cipher - by magnesium - 05-08-2025, 03:54 PM
RE: The Naibbe cipher - by joben - 06-08-2025, 08:18 AM
RE: The Naibbe cipher - by oaken - 06-08-2025, 12:33 PM
RE: The Naibbe cipher - by MarcoP - 06-08-2025, 03:17 PM
RE: The Naibbe cipher - by quimqu - 13-08-2025, 10:40 PM
RE: The Naibbe cipher - by davidma - 14-08-2025, 12:25 AM
RE: The Naibbe cipher - by quimqu - 14-08-2025, 10:17 AM
RE: The Naibbe cipher - by Rafal - 07-08-2025, 11:04 AM
RE: The Naibbe cipher - by hermesj - 07-08-2025, 09:45 PM
RE: The Naibbe cipher - by magnesium - 08-08-2025, 02:24 AM
RE: The Naibbe cipher - by RobGea - 09-08-2025, 03:16 AM
RE: The Naibbe cipher - by magnesium - 11-08-2025, 02:07 AM
RE: The Naibbe cipher - by Petrasti - 10-08-2025, 06:15 AM
RE: The Naibbe cipher - by Mauro - 10-08-2025, 11:53 AM
RE: The Naibbe cipher - by magnesium - 11-08-2025, 02:22 AM
RE: The Naibbe cipher - by Petrasti - 10-08-2025, 02:37 PM
RE: The Naibbe cipher - by Mauro - 10-08-2025, 03:31 PM
RE: The Naibbe cipher - by Petrasti - 10-08-2025, 03:36 PM
RE: The Naibbe cipher - by Petrasti - 10-08-2025, 04:11 PM
RE: The Naibbe cipher - by Mauro - 10-08-2025, 04:52 PM
RE: The Naibbe cipher - by RobGea - 10-08-2025, 04:56 PM
RE: The Naibbe cipher - by Petrasti - 10-08-2025, 05:42 PM
RE: The Naibbe cipher - by ReneZ - 11-08-2025, 12:30 AM
RE: The Naibbe cipher - by anyasophira - 12-08-2025, 04:57 AM
RE: The Naibbe cipher - by magnesium - 12-08-2025, 10:01 PM
RE: The Naibbe cipher - by bi3mw - 13-08-2025, 05:50 AM
RE: The Naibbe cipher - by magnesium - 13-08-2025, 11:41 AM
RE: The Naibbe cipher - by bi3mw - 13-08-2025, 05:50 PM
RE: The Naibbe cipher - by magnesium - 13-08-2025, 06:04 PM
RE: The Naibbe cipher - by bi3mw - 13-08-2025, 06:31 PM
RE: The Naibbe cipher - by magnesium - 13-08-2025, 06:38 PM
RE: The Naibbe cipher - by RobGea - 13-08-2025, 06:45 PM
RE: The Naibbe cipher - by bi3mw - 13-08-2025, 08:16 PM
RE: The Naibbe cipher - by bi3mw - 13-08-2025, 09:49 PM
RE: The Naibbe cipher - by ReneZ - 14-08-2025, 02:24 AM
RE: The Naibbe cipher - by bi3mw - 14-08-2025, 04:47 PM
RE: The Naibbe cipher - by RobGea - 05-09-2025, 07:52 PM
RE: The Naibbe cipher - by magnesium - 05-09-2025, 07:57 PM
RE: The Naibbe cipher - by nablator - 05-09-2025, 10:08 PM
RE: The Naibbe cipher - by magnesium - 05-09-2025, 10:52 PM
RE: The Naibbe cipher - by magnesium - 06-09-2025, 01:33 AM
RE: The Naibbe cipher - by bi3mw - 05-01-2026, 04:40 PM
RE: The Naibbe cipher - by MarcoP - 06-01-2026, 09:03 AM
RE: The Naibbe cipher - by Koen G - 06-01-2026, 09:47 AM
RE: The Naibbe cipher - by magnesium - 06-01-2026, 10:02 PM
RE: The Naibbe cipher - by Labyrinthinesecurity - 07-01-2026, 05:34 PM
RE: The Naibbe cipher - by magnesium - 07-01-2026, 06:14 PM
RE: The Naibbe cipher - by ahalay-mahalay - 19-01-2026, 10:02 PM
RE: The Naibbe cipher - by tlepkali - 31-08-2026, 08:56 AM
RE: The Naibbe cipher - by DG97EEB - 01-09-2026, 08:50 PM
RE: The Naibbe cipher - by Koen G - 01-09-2026, 09:53 PM
RE: The Naibbe cipher - by JoeyB - 01-09-2026, 10:35 PM
RE: The Naibbe cipher - by nablator - 02-09-2026, 01:35 PM
RE: The Naibbe cipher - by magnesium - 02-09-2026, 12:51 AM
RE: The Naibbe cipher - by Pointless.. - 02-09-2026, 02:10 PM
RE: The Naibbe cipher - by nablator - 02-09-2026, 02:29 PM
RE: The Naibbe cipher - by Pointless.. - 02-09-2026, 03:08 PM
RE: The Naibbe cipher - by Koen G - 02-09-2026, 03:08 PM
RE: The Naibbe cipher - by ololololo - 02-09-2026, 03:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The Naibbe cipher was amazing, and it made me think of a late night party I went to addekallstrom 0 2,249 28-09-2025, 09:22 AM
Last Post: addekallstrom

Forum Jump:


Users browsing this thread: 1 Guest(s)