Created
December 2, 2019 20:45
-
-
Save hosteren/85c2d2cc6ed3b963b6519a8f5e9bcc82 to your computer and use it in GitHub Desktop.
Convert latin letters to runes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
elder_rune_dict = { | |
"a": "ᚨ", | |
"b": "ᛒ", | |
"c": "ᚲ", | |
"d": "ᛞ", | |
"e": "ᛖ", | |
"f": "ᚠ", | |
"g": "ᚷ", | |
"h": "ᚺ", | |
"i": "ᛁ", | |
"j": "ᛃ", | |
"k": "ᚲ", | |
"l": "ᛚ", | |
"m": "ᛗ", | |
"n": "ᚾ", | |
"o": "ᛟ", | |
"p": "ᛈ", | |
"r": "ᚱ", | |
"s": "ᛊ", | |
"t": "ᛏ", | |
"u": "ᚢ", | |
"w": "ᚹ", | |
"z": "ᛉ", | |
"æ": "ᛇ", | |
" ": "᛬" | |
} | |
saxon_rune_dict = { | |
"a": "ᚪ", | |
"b": "ᛒ", | |
"c": "ᚳ", | |
"d": "ᛞ", | |
"e": "ᛖ", | |
"f": "ᚠ", | |
"g": "ᚷ", | |
"h": "ᚻ", | |
"i": "ᛁ", | |
"j": "ᛄ", | |
"l": "ᛚ", | |
"m": "ᛗ", | |
"n": "ᚾ", | |
"o": "ᚩ", | |
"p": "ᛈ", | |
"r": "ᚱ", | |
"s": "ᛋ", | |
"t": "ᛏ", | |
"u": "ᚢ", | |
"w": "ᚹ", | |
"x": "ᛉ", | |
"y": "ᚣ", | |
"æ": "ᚫ", | |
" ": " ", | |
".": "᛬" | |
} | |
young_rune_dict = { | |
"a": "ᛅ", | |
"b": "ᛒ", | |
"e": "ᛁ", | |
"f": "ᚠ", | |
"h": "ᚼ", | |
"i": "ᛁ", | |
"k": "ᚴ", | |
"l": "ᛚ", | |
"m": "ᛘ", | |
"n": "ᚾ", | |
"r": "ᚱ", | |
"s": "ᛋ", | |
"t": "ᛏ", | |
"u": "ᚢ", | |
"æ": "ᚬ", | |
" ": "᛬" | |
} | |
medieval_rune_dict = { | |
"a": "ᛆ", | |
"b": "ᛒ", | |
"c": "ᛍ", | |
"d": "ᛑ", | |
"e": "ᛂ", | |
"f": "ᚠ", | |
"g": "ᚵ", | |
"h": "ᚼ", | |
"i": "ᛁ", | |
"k": "ᚴ", | |
"l": "ᛚ", | |
"m": "ᛘ", | |
"n": "ᚿ", | |
"o": "ᚮ", | |
"p": "ᛔ", | |
"r": "ᚱ", | |
"s": "ᛋ", | |
"t": "ᛐ", | |
"u": "ᚢ", | |
"v": "ᚡ", | |
"y": "ᛦ", | |
"z": "ᛎ", | |
"æ": "ᛅ", | |
"ø": "ᚯ", | |
" ": "᛬" | |
} | |
alphabets = { | |
"elder": elder_rune_dict, | |
"saxon": saxon_rune_dict, | |
"young": young_rune_dict, | |
"medieval": medieval_rune_dict | |
} | |
# When writing in runes letters do not occur twice, like mississippi would be spelled misisipi | |
def rune_trim(txt_not_runes): | |
trimmed = ''.join([txt_not_runes[i] for i in range(len(txt_not_runes)-1) if txt_not_runes[i+1]!= txt_not_runes[i]]+[txt_not_runes[-1]]) | |
return trimmed | |
# Not every letter we use today was used 1500 years ago | |
def find_alphabet(txt_trimmed_runes): | |
matches = [] | |
match_max = len(txt_trimmed_runes) | |
elder_match = 0 | |
saxon_match = 0 | |
young_match = 0 | |
medieval_match = 0 | |
for char in txt_trimmed_runes: | |
if char in elder_rune_dict.keys(): | |
elder_match = elder_match + 1 | |
if char in saxon_rune_dict.keys(): | |
saxon_match = saxon_match + 1 | |
if char in young_rune_dict.keys(): | |
young_match = young_match + 1 | |
if char in medieval_rune_dict.keys(): | |
medieval_match = medieval_match + 1 | |
if elder_match == match_max: | |
matches.append("elder") | |
if saxon_match == match_max: | |
matches.append("saxon") | |
if young_match == match_max: | |
matches.append("young") | |
if medieval_match == match_max: | |
matches.append("medieval") | |
return matches | |
# Replaces characters in string with runes and returns it | |
def translate2runes(txt_ready, alphabet): | |
for char in txt_ready: | |
if char in alphabet.keys(): | |
txt_ready = txt_ready.replace(char, alphabet[char]) | |
return txt_ready | |
ting = input("Hvad? ") | |
trimmed_ting = rune_trim(ting.lower()) | |
matched_ting = find_alphabet(trimmed_ting) | |
with open("runes.txt", "w", encoding="utf-8") as file: | |
for alpha in matched_ting: | |
file.write(alpha + "\n" + translate2runes(trimmed_ting, alphabets[alpha]) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment