#!/usr/bin/python2.2 # # a quick and dirty implementation of the 'koremutake' phonetic transform for # byte streams # by Dan Sandler <(dsandler)@dsandler.org> # # koremutake originally by Josef Falk and Filip Salomonsson # see http://shorl.com/koremutake.php import re _alphabet = """ BA BE BI BO BU BY DA DE DI DO DU DY FA FE FI FO FU FY GA GE GI GO GU GY HA HE HI HO HU HY JA JE JI JO JU JY KA KE KI KO KU KY LA LE LI LO LU LY MA ME MI MO MU MY NA NE NI NO NU NY PA PE PI PO PU PY RA RE RI RO RU RY SA SE SI SO SU SY TA TE TI TO TU TY VA VE VI VO VU VY BRA BRE BRI BRO BRU BRY DRA DRE DRI DRO DRU DRY FRA FRE FRI FRO FRU FRY GRA GRE GRI GRO GRU GRY PRA PRE PRI PRO PRU PRY STA STE STI STO STU STY TRA TRE """.lower() _syllables = _alphabet.split() _vowel_list=['a','e','i','o','u','y'] _vowels = "".join(_vowel_list) # bidirectional_convert_list # will convert ['ko','re','mu','ta','ke'] to [39,l67,52,78,37] # will do the reverse, too # it's crazy def bidirectional_convert_list(words): a = [] for w in words: try: a.append(_syllables[int(w)]) except Exception: try: a.append(_syllables.index(w)) except Exception: pass return a def kore_to_bytes(s): i = 0 syll = "" a = [] while i < len(s): c = s[i] if c != ' ': syll += c if re.match("[%s]" % _vowels, c): a.append(_syllables.index(syll)) syll = "" i += 1 return ''.join(map(chr,a)) def bytes_to_kore(s): i = 0 a = [] while i < len(s): a.append(_syllables[ord(s[i])]) i += 1 return ''.join(a) if __name__ == "__main__": def usage(): print """usage: koremutake.py (-k|-b|-h) [str] if str omitted, standard input is read, line by line, stripping newlines flags: -k: koremutake -> raw bytes -b: bytes -> koremutake -n: input is a textual representation of an integer (i.e. 12345) -h: show help""" import sys if len(sys.argv) >= 2: arg = sys.argv[1] else: usage() ; sys.exit(1) if len(sys.argv) > 2: input = [" ".join(sys.argv[2:])] else: input = map(lambda l: l[:-1], sys.stdin.readlines()) if arg == "-k": for l in input: print kore_to_bytes(l.lower()) elif arg == "-b": for l in input: print bytes_to_kore(l) elif arg == "-n": for l in input: i = long(l) s = "" while i > 0: s += "%c" % (i&0xff) i = i >> 8 print bytes_to_kore(s) else: usage() sys.exit(1)