Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. require 'bit';
  2. 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};
  3.  
  4. 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};
  5.  
  6. 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};
  7.  
  8. etc = {["`"]="*", ["~"]="โ€ป", ["&"]="โ€œ", ["*"]="โ€", ["("]="'", ["^"]="=", [")"]="~", ["-"]=")", ["_"]=";", ["="]=">", ["+"]="+", ["\\"]=":", ["|"]="\\", ["["]="(", ["]"]="<", ["{"]="%", ["}"]="/", ["\""]="ยท", ["?"]="!", ["<"]=",", [">"]=".", ["M"]="\"", ["N"]="-", ["B"]="?", [" "]=" ", ["."]=".", [","]=","};
  9.  
  10. 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};
  11.  
  12. syllable_base = 0xac00;
  13. choseong_base = 0x1100;
  14. jungseong_base = 0x1161;
  15. jongseong_base = 0x11a7;
  16. njungseong = 21;
  17. njongseong = 28;
  18.  
  19. function compose(cho, jung, jong)
  20. if cho == 0 then
  21. thisoutput = jung;
  22. elseif cho == 0 and jung == 0 then
  23. thisoutput = "";
  24. else
  25. if cho == 0 and jung == 0 and jong == 0 then
  26. return ""; --wtf
  27. elseif cho == 0 and jung == 0 then
  28. thisoutput = jong;
  29. elseif cho == 0 then
  30. thisoutput = jung;
  31. elseif jung == 0 and cho ~= 0 then
  32. thisoutput = cho;
  33. else
  34. if cho ~= 0 then
  35. cho = cho - choseong_base;
  36. end
  37. if jong ~= 0 then
  38. jong = jong - jongseong_base;
  39. end
  40. if jung ~= 0 then
  41. jung = jung - jungseong_base;
  42. end
  43. thisoutput = (cho * njungseong + jung) * njongseong + jong + syllable_base;
  44. end
  45. end
  46. --ucs4 to utf8
  47. first = bit.bor(0xE0, bit.brshift(bit.band(thisoutput, 0xF000), 12));
  48. second = bit.bor(0x80, bit.brshift(bit.band(thisoutput, 0xFC0), 6));
  49. third = bit.bor(0x80, bit.band(thisoutput, 0x3F));
  50. return string.char(first, second, third);
  51. end
  52.  
  53. input = "k8ofSk8";
  54. output = "";
  55. len = string.len(input);
  56. cho = 0;
  57. jung = 0;
  58. jong = 0;
  59. for i=0,len do
  60. now = string.sub(input, i, i);
  61. if chotable[now] ~= nil then
  62. if cho ~= 0 then
  63. if composition[cho * 0x10000 + chotable[now]] ~= nil and jong == 0 and jung == 0 then
  64. cho = composition[cho * 0x10000 + chotable[now]];
  65. else
  66. output = output..compose(cho, jung, jong);
  67. cho = chotable[now];
  68. jung = 0;
  69. jong = 0;
  70. end
  71. else
  72. cho = chotable[now];
  73. jung = 0;
  74. jong = 0;
  75. end
  76. elseif jungtable[now] ~= nil then
  77. if jung ~= 0 and composition[jung * 0x10000 + jungtable[now]] ~= nil then
  78. jung = composition[jung * 0x10000 + jungtable[now]];
  79. elseif jung == 0 then
  80. jung = jungtable[now];
  81. else
  82. output = output..compose(cho, jung, jong);
  83. cho = 0;
  84. jung = jungtable[now];
  85. jong = 0;
  86. end
  87. elseif jongtable[now] ~= nil then
  88. if jong ~= 0 and composition[jong * 0x10000 + jongtable[now]] ~= nil then
  89. jong = composition[jong * 0x10000 + jongtable[now]];
  90. elseif jong == 0 then
  91. jong = jongtable[now];
  92. else
  93. output = output..compose(cho, jung, jong);
  94. cho = 0;
  95. jung = 0;
  96. jong = jongtable[now];
  97. end
  98. elseif etc[now] ~= nil then
  99. if cho ~= 0 or jung ~= 0 or jong ~= 0 then
  100. output = output..compose(cho, jung, jong);
  101. end
  102. cho = 0;
  103. jung = 0;
  104. jong = 0;
  105. output = output..etc[now];
  106. else
  107. cho = 0;
  108. jung = 0;
  109. jong = 0;
  110. end
  111. end
  112. if cho ~= 0 or jung ~= 0 or jong ~= 0 then
  113. output = output..compose(cho, jung, jong);
  114. end
  115. print(output);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement