Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'bit';
- chotable = {["k"]=0x1100, ["h"]=0x1102, ["u"]=0x1103, ["y"]=0x1105, ["i"]=0x1106, [";"]=0x1107, ["n"]=0x1109, ["j"]=0x110B, ["l"]=0x110C, ["o"]=0x110E, ["0"]=0x110F, ["'"]=0x1110, ["p"]=0x1111, ["m"]=0x1112};
- jungtable = {["f"]=0x1161, ["6"]=0x1163, ["t"]=0x1165, ["e"]=0x1167, ["v"]=0x1169, ["4"]=0x116D, ["b"]=0x116E, ["5"]=0x1172, ["g"]=0x1173, ["d"]=0x1175, ["8"]=0x1174, ["/"]=0x1169, ["9"]=0x116E, ["c"]=0x1166, ["7"]=0x1168, ["r"]=0x1162, ["G"]=0x1164};
- jongtable = {["w"]=0x11AF, ["q"]=0x11BA, ["a"]=0x11BC, ["s"]=0x11AB, ["z"]=0x11B7, ["x"]=0x11A8, ["1"]=0x11C2, ["2"]=0x11BB, ["3"]=0x11B8, ["!"]=0x11A9, ["@"]=0x11B0, ["#"]=0x11BD, ["Q"]=0x11C1, ["W"]=0x11C0, ["E"]=0x11AC, ["$"]=0x11B5, ["%"]=0x11B4, ["R"]=0x11B6, ["T"]=0x11B3, ["A"]=0x11AE, ["S"]=0x11AD, ["D"]=0x11B5, ["F"]=0x11B1, ["Z"]=0x11BE, ["X"]=0x11B9, ["C"]=0x11BF, ["V"]=0x11AA};
- etc = {["`"]="*", ["~"]="โป", ["&"]="โ", ["*"]="โ", ["("]="'", ["^"]="=", [")"]="~", ["-"]=")", ["_"]=";", ["="]=">", ["+"]="+", ["\\"]=":", ["|"]="\\", ["["]="(", ["]"]="<", ["{"]="%", ["}"]="/", ["\""]="ยท", ["?"]="!", ["<"]=",", [">"]=".", ["M"]="\"", ["N"]="-", ["B"]="?", [" "]=" ", ["."]=".", [","]=","};
- composition = {[0x11001100]=0x1101, [0x11031103]=0x1104, [0x11071107]=0x1108, [0x11091109]=0x110a, [0x110c110c]=0x110d, [0x11691161]=0x116a, [0x11691162]=0x116b, [0x11691175]=0x116c, [0x116e1165]=0x116f, [0x116e1166]=0x1170, [0x116e1175]=0x1171, [0x11731175]=0x1174, [0x11a8118a]=0x11a9, [0x11a811ba]=0x11aa, [0x11ab11bd]=0x11ac, [0x11ab11c2]=0x11ad, [0x11af11a8]=0x11b0, [0x11af11b7]=0x11b1, [0x11af11b8]=0x11b2, [0x11af11ba]=0x11b3, [0x11af11c0]=0x11b4, [0x11af11c1]=0x11b5, [0x11af11c2]=0x11b6, [0x11b811ba]=0x11b9, [0x11ba11ba]=0x11bb, [0x11611169] = 0x116a, [0x11621169] = 0x116b, [0x1165116e] = 0x116f, [0x1166116e] = 0x1170, [0x11751169] = 0x116c, [0x1175116e] = 0x1171};
- syllable_base = 0xac00;
- choseong_base = 0x1100;
- jungseong_base = 0x1161;
- jongseong_base = 0x11a7;
- njungseong = 21;
- njongseong = 28;
- function compose(cho, jung, jong)
- if cho == 0 then
- thisoutput = jung;
- elseif cho == 0 and jung == 0 then
- thisoutput = "";
- else
- if cho == 0 and jung == 0 and jong == 0 then
- return ""; --wtf
- elseif cho == 0 and jung == 0 then
- thisoutput = jong;
- elseif cho == 0 then
- thisoutput = jung;
- elseif jung == 0 and cho ~= 0 then
- thisoutput = cho;
- else
- if cho ~= 0 then
- cho = cho - choseong_base;
- end
- if jong ~= 0 then
- jong = jong - jongseong_base;
- end
- if jung ~= 0 then
- jung = jung - jungseong_base;
- end
- thisoutput = (cho * njungseong + jung) * njongseong + jong + syllable_base;
- end
- end
- --ucs4 to utf8
- first = bit.bor(0xE0, bit.brshift(bit.band(thisoutput, 0xF000), 12));
- second = bit.bor(0x80, bit.brshift(bit.band(thisoutput, 0xFC0), 6));
- third = bit.bor(0x80, bit.band(thisoutput, 0x3F));
- return string.char(first, second, third);
- end
- input = "k8ofSk8";
- output = "";
- len = string.len(input);
- cho = 0;
- jung = 0;
- jong = 0;
- for i=0,len do
- now = string.sub(input, i, i);
- if chotable[now] ~= nil then
- if cho ~= 0 then
- if composition[cho * 0x10000 + chotable[now]] ~= nil and jong == 0 and jung == 0 then
- cho = composition[cho * 0x10000 + chotable[now]];
- else
- output = output..compose(cho, jung, jong);
- cho = chotable[now];
- jung = 0;
- jong = 0;
- end
- else
- cho = chotable[now];
- jung = 0;
- jong = 0;
- end
- elseif jungtable[now] ~= nil then
- if jung ~= 0 and composition[jung * 0x10000 + jungtable[now]] ~= nil then
- jung = composition[jung * 0x10000 + jungtable[now]];
- elseif jung == 0 then
- jung = jungtable[now];
- else
- output = output..compose(cho, jung, jong);
- cho = 0;
- jung = jungtable[now];
- jong = 0;
- end
- elseif jongtable[now] ~= nil then
- if jong ~= 0 and composition[jong * 0x10000 + jongtable[now]] ~= nil then
- jong = composition[jong * 0x10000 + jongtable[now]];
- elseif jong == 0 then
- jong = jongtable[now];
- else
- output = output..compose(cho, jung, jong);
- cho = 0;
- jung = 0;
- jong = jongtable[now];
- end
- elseif etc[now] ~= nil then
- if cho ~= 0 or jung ~= 0 or jong ~= 0 then
- output = output..compose(cho, jung, jong);
- end
- cho = 0;
- jung = 0;
- jong = 0;
- output = output..etc[now];
- else
- cho = 0;
- jung = 0;
- jong = 0;
- end
- end
- if cho ~= 0 or jung ~= 0 or jong ~= 0 then
- output = output..compose(cho, jung, jong);
- end
- print(output);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement