|
|
(未显示2个用户的8个中间版本) |
第1行: |
第1行: |
| This adaptable C++ code converts [[聊天字母|ASCII-based alphabet]] to ampersand-encoded [[PUA]]. [http://tio.run/##7VdLb@M2EL7rVzAuGsiIA4uinkgcYLGHYoE9FFj0FPigULQjrEx5JTluu8hvT4ccyqYcOfXuJu2hjYHQ8/yGw5khzdfrS15mcvn09FMhebnJBbnmTZsX1Y3T49SFXAIrF4tCCiLKYgH/GkGKhcPvs5rwmXdFptNCrjctcoovt8l8xyNfNmIjnEK2ICgtZRSQUshle@/wSjagAVqleLj1w2g@@@p4@m8yuJA3Ek6nNPqXgJmvgQPkBRQXv2ceBAPmQYzCEMkQLUO0DJkRomUY4hLhEivgIHEuwjgM2MT7XXgpxyXGJQNzWKNIk5HhGsoI03SiHHhMO40RODbAMQLHCBwjcKyBo2CXauUF8aM77Sz00De7Q6GPQkQKIiMUSMZ6YQlSgYkqRDLVlmyBlK@AE0/vmKFdYBQ9XBJjjt4YmqcYFQNgvVUMJw3QhJ5wxho4NcVltrrQi0@R4ibVSKaGm@PCjDBEIXIZUqHZcYSJZOi9ixyrmkJ1KSYGzvAAmXHTIZskC1wSFBrnDI@eGW720pZj5/FqOn336f2HD6StyK@/vSPuR/EgyrHV6cs6@293uql7/5kG1FSk0v3qwNDpp5irmk71ErHIjipM0u8DtjrdgkheYVM6yKDnFts5ja1OT5CXYMMn0cu@tc@0nw72jTtOd8WlzYOTzDWwf1wYJkk/KqpNgl5VQ6drPyYNODETnFRwN5ABSIaqPh4yTHfNTQa6@Jc6exB2F3Mh/@/itwWGGeHxgy5WvAxFeE@YG8kz94QXIIkXhIfj3ouNEGe4l/5oF/9TqYYuftlc7eYOytVxHqoiJ@tNc@/i@5SOvzrwWnXh9XnTFH@KSn0dKyZp7@tq645UCs1rtHoQ9aKstqPxlUMeHfWWBbv5jNMrRZQXM/jyaEB4KbK6Q5l5yuVKrBrRAsDEm1hg2vjW2/uZnZ1xy9MaXtlt3xNGPEOCqGj049tFP7NL5pHzc@WVKor61JC@IpNUW6F6AJw00gzFUbcucNl8fk191LMz4ZNmnXFBMqmyKHm7ydqikoRnksiqJXcCvq6LNithe7nOE1GZIriJhTv6mcMnvxpN4KUAM2iPd0kjrf7YhQbbC3ZxqXf/C3Gx145rj2fF1U8y9SMrj/5gHumReIO/j3eVwW@sVZHnpYq9EacnE0AvBpLpHybzWHDhmwS3B704llEWHyTUMI65VJcLukR/@Nuzb9GMJtBjz@Do/rj2p@WphGBLWemIyEYWuZBtsSgE9DX0YcZbUY92oAce/MOorRiGQhw8RK/blBU1HCLtQjbpHA45PiVk28OPhbz3ZCwc22of1gLC@iyrrSSirqu6G6NmUtKxHnnq1bDKCumOlXVb/6F8bO@LUrj8bEa983O1MIyXz5aiVdtzsQBhWxySZBJiJieKoJTbxh11lYo5UMrGFbH51nAl5ro4tIMZ20MBBbiK3uOUIU2xlIf@KISO0/i4Y@xUVEzS43qMXnPQgpOLdEK60UNOvwSQArguAT2c58Nup09f1i9vYKN4NV5abWYnyjaAneyULbvrbrwO2nUFeRhD/4h2yMMnuEfoAfT89yzNQN1X1SPPoPpcfO7qC3olmiZbitu59rzQNWd4k6bNoe51mXzaZmtoDEHabUWyerlZQbM2cHh6wG6r@nMhl7o5atFuakk86I2np78A Try it online!]
| | Chart generator (current version) |
| <pre class="mw-collapsible">#define PROGRAM
| |
| #include <cstdio>
| |
| #include <cstring>
| |
| #define elif else if
| |
| // Input ends in newline
| |
| char c=0; //input
| |
| char iq[8]; //input queue
| |
| int iql=0; //input queue length
| |
| const int lev[256]={
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //16
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //32
| |
| 000040,000041,000042,000000, 000044,000000,000000,000047, 000050,000051,000052,000053, 000054,000055,000056,000057, //48
| |
| +57543,0xe09c,0xe097,0xe09a, 0xe066,0xe067,0xe096,0xe06a, 0xe099,+57503,000072,000073, 000074,000075,000076,000077, //64
| |
| 000000,0xe093,0xe06b,+57550, 0xe03b,0xe092,0xe069,+57546, 0xe03e,+57547,+57538,+57544, 0xe095,+57549,0xe03f,+57542, //80
| |
| +57537,+57545,+57540,+57548, 0xe098,+57539,0xe09b,+57536, +57502,0xe094,+57541,000000, 000000,000000,000000,000002, //96
| |
| 000003,0xe06f,0xe021,0xe06c, 0xe061,0xe091,0xe06d,0xe063, 0xe065,0xe09d,0xe035,0xe054, 0xe060,0xe033,0xe039,0xe090, //112
| |
| 0xe032,0xe036,0xe03d,0xe03c, 0xe062,0xe06e,0xe068,0xe034, 0xe037,0xe038,0xe03a,000000, 000000,000000,000007
| |
| };//ASCII to PUA (Level)
| |
| const int gra[256]={
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //16
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //32
| |
| 000000,0xe020,000000,000000, +57637,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //48
| |
| 000000,000000,000000,000000, 000000,+57590,+57636,000000, +57589,000000,000000,000000, 000000,000000,000000,000000, //64
| |
| 000000,000000,+57598,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, +57634,000000,+57595,+57597, //80
| |
| +57585,+57587,+57586,000000, 000000,000000,000000,+57639, 000000,+57593,000000,000000, 000000,000000,000000,000000, //96
| |
| 000000,+57594,000000,000000, 000000,000000,000000,+57632, 000000,000000,000000,+57588, 000000,+57591,+57640,000000, //112
| |
| +57635,+57599,+57584,+57551, 000000,000000,+57633,+57592, +57596,+57638
| |
| };//ASCII to PUA (Grave)
| |
| const int cen[256]={
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //16
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //32
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,0xe00c,000000, //48
| |
| 0xe00a,0xe001,0xe002,0xe003, 0xe004,0xe005,0xe006,0xe007, 0xe008,0xe009,000000,000000, 000000,000000,000000,000000, //64
| |
| 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, 000000,000000,000000,000000, //80
| |
| 000000,000000,000000,000000, 0xe00b
| |
| };
| |
|
| |
|
| void push(char c1){
| | <pre>import sys |
| if(iql>sizeof(iq)){
| | import os.path |
| throw("e001 queue overflow");
| | import pypinyin |
| }
| | import xdi8string # all the characters spaced out translated into shidinn |
| iq[iql]=c1;
| | f=open("wikifile.txt","w",encoding="utf-8") |
| iql+=1;
| |
| }
| |
|
| |
|
| void clear(char c1=0){
| | characters=[chr(i) for i in range(0x4e00,0xa000)] |
| memset(iq,0,sizeof(iq));
| | plaintext=' '.join(chr(n) for n in range(0x4e00,0xa000)) |
| iq[0]=c1;
| | ciphertext=xdi8string.output |
| iql=!!c1;
| |
| }
| |
|
| |
|
| void print(char c1=0){
| | b1i45=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| if(iql==0){
| | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| ;
| | 0,(0),0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
| } elif(iq[0]==-30 && iq[1]==-121 && iq[2]==-89){
| | 0,44,39,42,22,23,38,26,41,0,0,0,0,0,0,0, |
| if(iq[4]==96){
| | 0,35,27,0,11,34,25,0,14,0,0,0,37,0,15,0, |
| if(gra[iq[3]]<129){
| | 0,0,0,0,40,0,43,0,0,36,0,0,0,0,0,0, |
| throw("e002 space and punctuation can not be capitalized");
| | 0,31,1,28,17,33,29,19,21,45,5,20,16,3,9,32, |
| }
| | 2,6,13,12,18,30,24,4,7,8,10,0,0,0,0,0,0] |
| printf("%c%c%d;",38,35,gra[iq[3]]-16);
| | b1i90000=[(((i-1)%9+1) * (10**((i-1)//9))if i!=0 else 0) for i in b1i45] |
| }
| |
| if(iql==4){
| |
| if(lev[iq[3]]<129){
| |
| throw("e003 space and punctuation can not be capitalized");
| |
| }
| |
| printf("%c%c%d;",38,35,lev[iq[3]]-16);
| |
| }
| |
| } elif(iq[0]==126){
| |
| if(iq[2]==96){
| |
| if(gra[iq[1]]<129){
| |
| throw("e004 space and punctuation can not be made middle case");
| |
| }
| |
| printf("%c%c%d;",38,35,gra[iq[1]]+16);
| |
| }
| |
| if(iql==2){
| |
| if(lev[iq[1]]<129){
| |
| throw("e005 space and punctuation can not be made middle case");
| |
| }
| |
| printf("%c%c%d;",38,35,lev[iq[1]]+16);
| |
| }
| |
| } elif(iq[0]==37){
| |
| if(iq[2]==37){
| |
| printf("%c%c%d;",38,35,cen[iq[1]]);
| |
| } else {
| |
| printf("%s",iq);
| |
| }
| |
| } elif(iq[1]==96){
| |
| if(gra[iq[0]]<10){
| |
| throw("e006 unidentified character");
| |
| } elif(gra[iq[0]]<127){
| |
| printf("%s",iq);
| |
| } else {
| |
| printf("%c%c%d;",38,35,gra[iq[0]]);
| |
| }
| |
| } elif(iql==1){
| |
| if(lev[iq[0]]<10){
| |
| throw("e007 unidentified character");
| |
| } elif(lev[iq[0]]<127){
| |
| printf("%s",iq);
| |
| } else {
| |
| printf("%c%c%d;",38,35,lev[iq[0]]);
| |
| }
| |
| } else {
| |
| throw("e00f unknown error");
| |
| }
| |
| clear(c1);
| |
| }
| |
|
| |
|
| int main() {
| | def b1i45encode(word): |
| try{
| | return ' '.join((str(b1i45[ord(q)]) if len(str(b1i45[ord(q)]))>=2 else '0'+str(b1i45[ord(q)])) for q in word) |
| while(c!=10&&c!=13){
| | |
| c=getchar();
| | def b1i90000sum(word): |
| if(c==10){
| | return sum([b1i90000[ord(q)] for q in word]) |
| print(); | | |
| puts("");
| | plain=plaintext.split() |
| } elif(c==13){
| | cipher=ciphertext.split() |
| ;
| | |
| } elif(iql==0){
| | maxlength=0 |
| push(c);
| | maxlench=[] |
| } elif(c==-30){
| | |
| print(c); //Capital sign
| | f.write("Do not simply rely on this chart to translate, as this chart did not handle [[talk:希顶日本语#注意多音字|homograph]] properly. The calculation may be incorrect. If so, please fix it.") |
| } elif(iql==1&&c==-121){
| | |
| push(c);
| | f.write("{| class=\"wikitable sortable\"\n"); |
| } elif(iql==2&&c==-89){
| | f.write("! Character !! Unicode decimal !! Stroke count !! han4 yu3 pin1 yin1 !! xdi8 aho !! [[b1i45密码|b1i45]] !! xdi8 aho letter count !! [[希顶解经|Numeral sum]] !! Stress pattern !! Notes\n") |
| push(c);
| | for p in range(len(plain)): |
| } elif(31<c&&c<126&&c!=96){
| | if(plain[p]!=cipher[p]): |
| if(iq[0]==-30 && iq[1]==-121 && iq[2]==-89 && iql==3){
| | f.write("|-\n"); |
| push(c);
| | f.write("| "+plain[p]+" || ") |
| } elif(iq[0]==126 && iql==1){
| | f.write(str(ord(plain[p]))) |
| push(c);
| | f.write(" || || ") |
| } elif(iql>1&&iq[iql-1]==96){
| | f.write(pypinyin.pinyin(characters[p],style=pypinyin.Style.TONE3,neutral_tone_with_five=True)[0][0]) |
| print(c);
| | f.write(" || "+cipher[p]) |
| } elif(31<iq[iql-1]&&iq[iql-1]<126){
| | f.write(" || "+b1i45encode(cipher[p])) |
| print(c);
| | f.write(" || "+str(len(cipher[p]))) |
| } else {
| | f.write(" || "+str(b1i90000sum(cipher[p])) + "\n") |
| push(c);
| | if(maxlength<len(cipher[p])): |
| }
| | maxlench=[p] |
| } elif(c==96){
| | maxlength=len(cipher[p]) |
| push(c);
| | elif(maxlength<=len(cipher[p])): |
| } elif(c==126){
| | maxlench+=[p] |
| print(c);
| | f.write("|}") |
| } else {
| | print(maxlench,maxlength,len(maxlench)) |
| push(c);
| | |
| }
| | f.close(); |
| }
| | </pre> |
| print();
| |
| }catch(const char message[]){
| |
| fputs(message,stderr); //Swap the two arguments if not working
| |
| }
| |
| return 0;
| |
| }</pre>
| |
Chart generator (current version)
import sys
import os.path
import pypinyin
import xdi8string # all the characters spaced out translated into shidinn
f=open("wikifile.txt","w",encoding="utf-8")
characters=[chr(i) for i in range(0x4e00,0xa000)]
plaintext=' '.join(chr(n) for n in range(0x4e00,0xa000))
ciphertext=xdi8string.output
b1i45=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,(0),0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,44,39,42,22,23,38,26,41,0,0,0,0,0,0,0,
0,35,27,0,11,34,25,0,14,0,0,0,37,0,15,0,
0,0,0,0,40,0,43,0,0,36,0,0,0,0,0,0,
0,31,1,28,17,33,29,19,21,45,5,20,16,3,9,32,
2,6,13,12,18,30,24,4,7,8,10,0,0,0,0,0,0]
b1i90000=[(((i-1)%9+1) * (10**((i-1)//9))if i!=0 else 0) for i in b1i45]
def b1i45encode(word):
return ' '.join((str(b1i45[ord(q)]) if len(str(b1i45[ord(q)]))>=2 else '0'+str(b1i45[ord(q)])) for q in word)
def b1i90000sum(word):
return sum([b1i90000[ord(q)] for q in word])
plain=plaintext.split()
cipher=ciphertext.split()
maxlength=0
maxlench=[]
f.write("Do not simply rely on this chart to translate, as this chart did not handle [[talk:希顶日本语#注意多音字|homograph]] properly. The calculation may be incorrect. If so, please fix it.")
f.write("{| class=\"wikitable sortable\"\n");
f.write("! Character !! Unicode decimal !! Stroke count !! han4 yu3 pin1 yin1 !! xdi8 aho !! [[b1i45密码|b1i45]] !! xdi8 aho letter count !! [[希顶解经|Numeral sum]] !! Stress pattern !! Notes\n")
for p in range(len(plain)):
if(plain[p]!=cipher[p]):
f.write("|-\n");
f.write("| "+plain[p]+" || ")
f.write(str(ord(plain[p])))
f.write(" || || ")
f.write(pypinyin.pinyin(characters[p],style=pypinyin.Style.TONE3,neutral_tone_with_five=True)[0][0])
f.write(" || "+cipher[p])
f.write(" || "+b1i45encode(cipher[p]))
f.write(" || "+str(len(cipher[p])))
f.write(" || "+str(b1i90000sum(cipher[p])) + "\n")
if(maxlength<len(cipher[p])):
maxlench=[p]
maxlength=len(cipher[p])
elif(maxlength<=len(cipher[p])):
maxlench+=[p]
f.write("|}")
print(maxlench,maxlength,len(maxlench))
f.close();