Urbit语音名称是如何编码的?

时间:2016-07-01 07:24:41

标签: urbit

Urbit点(网络地址)由32位整数标识,但它们的编号通常不会引用它们。相反,我通常看到它们以人类可发音的形式表示,其中每个字节都被转换为三个字母的音节。例如:

  8 bits  galaxy  ~lyt
 16 bits  star    ~diglyt
 32 bits  planet  ~picder-ragsyt
 64 bits  moon    ~diglyt-diglyt-picder-ragsyt
128 bits  comet   ~racmus-mollen-fallyt-linpex--watres-sibbur-modlux-rinmex

我最初假设每个字节都有一个文本表示,但是已经看到行星名称通常不包括它们的星名,所以它必须比这更复杂。

Urbit的语音名称编码系统(@p - 名称)如何运作?

1 个答案:

答案 0 :(得分:8)

Urbit的语音命名系统将无符号整数编码为人类可读的字符串。这些无符号整数有时表示它们以big-endian编码的字节串(尽管该表示不能跟踪前导零,因此如果需要,字节长度必须在带外传送)。语音命名方案对这些大端字节进行操作。

语音命名系统有两种变体。对于一般用途,有@q - 编码,它适用于任何长度的值,并且经常用于表示Hoon代码中的二进制数据或与Dojo REPL交互时。对于Urbit点名称,有@p - 编码,它基于@q - 编码,但会修改某些情况。

@q - 编码:成对的音节

Urbit语音名称由3个字母的音节组成,每个音节由两个256个音节组成。每个音节由辅音,元音,然后是另一个辅音组成。 "前缀"音节列表使用元音aio以及"后缀"音节列表使用元音euy,但有一个例外:zod,后缀列表中的第一个条目。完整的音节列表包括在下面。

0x000xFF的一个字节中拟合的值通过从后缀列表中取相应的音节进行编码。示例:0x00变为~zod0x01变为~nec

0x01000xFFFF的两个字节中拟合的值通过查找与前缀列表中的高字节对应的音节并连接与后缀中的低字节对应的音节来编码名单。示例:0x0100变为~marzod0x0101变为~marnec

通过将它们按大端顺序分成两个字节对来对较大的值进行编码,如上所述对每个值进行编码以适应两个字节的值,并将结果与​​-连字符/减号字符连接起来。如果该值是奇数个字节,则第一个字节对用前导零填充。示例:0x01_0000变为~doznec-dozzod0x0101_0101变为~marnec-marnec

@p - 编码:加扰行星

对于大多数值,@p - 编码方案与@q相同。但是,17到64位之间的值不同,它们对应于行星和卫星的ID。

行星旨在与Urbit网络上的真实个人相对应。每颗行星都是由一颗恒星产生的,而这颗行星ID的16个低位是其母星的ID。在@q - 编码系统下,这也意味着每个星球名称的最后两个音节都是它的星名。 Urbit的开发人员并不希望网络上每个人的名字都包括最初产生他们星球的星星的名字:即使他们可以立即转移,也会人为地将他们与星星永久地联系起来他们的星球是另一颗恒星。

他们的解决方案是随机扰乱所有行星名称,以混淆行星名称与其母星名称之间的关系。这是在可能的行星ID空间上实现的自定义(显然是非安全的)密码。因为每颗恒星有2个 16 - 1个行星,所以行星的数量不是2的幂,因此传统的分组密码不会直接工作。相反,他们使用Ciphers with Arbitrary Finite Domains (Black and Rockway 2002)中描述的结构而不是针对速度优化的自定义Feistel样式分组密码(and compatibility)。

此加扰应用于行星ID,以及月球ID的低32位(对应于其父行星的ID)。在@p - 编码下,ID为0x01_0101的行星变为~ralnyt-botdyt,与其父星~marnec没有任何关联。星球关系是唯一被混淆的关系。如果你看一下行星卫星的名字,它们会直接包含行星的名称:例如,~ralnyt-botdyt的月亮0x01_0001_0101变为~doznec-ralnyt-botdyt0x02_0001_0101成为~dozbud-ralnyt-botdyt

实现

在编写Hoon代码时,例如在Dojo REPL中,您可以直接使用标准@p@q函数将值编码为相应的语音名称。在Hoon中,@p编码的值用前缀~标识,@q编码的值用前缀.~标识,并且可以用@u函数。 Hoon还使用.句点字符作为整数文字中的(强制)千位分隔符。

> `@p`1.529.729.032
~diglyt-diglyt
> `@q`1.529.729.032
.~fonbyn-mopful      
> `@u`~diglyt-diglyt
1.529.729.032
> `@u`.~diglyt-diglyt
3.246.440.832

在JavaScript中,the official urbit-ob package提供了类似的功能。

import ob from "urbit-ob";
ob.patp(1529729032);           // ~diglyt-diglyt
ob.patq(1529729032);           // ~fonbyn-mopful
ob.patp2dec("~diglyt-diglyt"); // 1529729032
ob.patq2dec("~diglyt-diglyt"); // 3246440832

完整音节列表

prefixes = ["doz","mar","bin","wan","sam","lit","sig","hid","fid","lis","sog",
"dir","wac","sab","wis","sib","rig","sol","dop","mod","fog","lid","hop","dar",
"dor","lor","hod","fol","rin","tog","sil","mir","hol","pas","lac","rov","liv",
"dal","sat","lib","tab","han","tic","pid","tor","bol","fos","dot","los","dil",
"for","pil","ram","tir","win","tad","bic","dif","roc","wid","bis","das","mid",
"lop","ril","nar","dap","mol","san","loc","nov","sit","nid","tip","sic","rop",
"wit","nat","pan","min","rit","pod","mot","tam","tol","sav","pos","nap","nop",
"som","fin","fon","ban","mor","wor","sip","ron","nor","bot","wic","soc","wat",
"dol","mag","pic","dav","bid","bal","tim","tas","mal","lig","siv","tag","pad",
"sal","div","dac","tan","sid","fab","tar","mon","ran","nis","wol","mis","pal",
"las","dis","map","rab","tob","rol","lat","lon","nod","nav","fig","nom","nib",
"pag","sop","ral","bil","had","doc","rid","moc","pac","rav","rip","fal","tod",
"til","tin","hap","mic","fan","pat","tac","lab","mog","sim","son","pin","lom",
"ric","tap","fir","has","bos","bat","poc","hac","tid","hav","sap","lin","dib",
"hos","dab","bit","bar","rac","par","lod","dos","bor","toc","hil","mac","tom",
"dig","fil","fas","mit","hob","har","mig","hin","rad","mas","hal","rag","lag",
"fad","top","mop","hab","nil","nos","mil","fop","fam","dat","nol","din","hat",
"nac","ris","fot","rib","hoc","nim","lar","fit","wal","rap","sar","nal","mos",
"lan","don","dan","lad","dov","riv","bac","pol","lap","tal","pit","nam","bon",
"ros","ton","fod","pon","sov","noc","sor","lav","mat","mip","fip"]
suffixes = ["zod","nec","bud","wes","sev","per","sut","let","ful","pen","syt",
"dur","wep","ser","wyl","sun","ryp","syx","dyr","nup","heb","peg","lup","dep",
"dys","put","lug","hec","ryt","tyv","syd","nex","lun","mep","lut","sep","pes",
"del","sul","ped","tem","led","tul","met","wen","byn","hex","feb","pyl","dul",
"het","mev","rut","tyl","wyd","tep","bes","dex","sef","wyc","bur","der","nep",
"pur","rys","reb","den","nut","sub","pet","rul","syn","reg","tyd","sup","sem",
"wyn","rec","meg","net","sec","mul","nym","tev","web","sum","mut","nyx","rex",
"teb","fus","hep","ben","mus","wyx","sym","sel","ruc","dec","wex","syr","wet",
"dyl","myn","mes","det","bet","bel","tux","tug","myr","pel","syp","ter","meb",
"set","dut","deg","tex","sur","fel","tud","nux","rux","ren","wyt","nub","med",
"lyt","dus","neb","rum","tyn","seg","lyx","pun","res","red","fun","rev","ref",
"mec","ted","rus","bex","leb","dux","ryn","num","pyx","ryg","ryx","fep","tyr",
"tus","tyc","leg","nem","fer","mer","ten","lus","nus","syl","tec","mex","pub",
"rym","tuc","fyl","lep","deb","ber","mug","hut","tun","byl","sud","pem","dev",
"lur","def","bus","bep","run","mel","pex","dyt","byt","typ","lev","myl","wed",
"duc","fur","fex","nul","luc","len","ner","lex","rup","ned","lec","ryd","lyd",
"fen","wel","nyd","hus","rel","rud","nes","hes","fet","des","ret","dun","ler",
"nyr","seb","hul","ryl","lud","rem","lys","fyn","wer","ryc","sug","nys","nyl",
"lyn","dyn","dem","lux","fed","sed","bec","mun","lyr","tes","mud","nyt","byr",
"sen","weg","fyr","mur","tel","rep","teg","pec","nel","nev","fes"]