Base34 编码器/解码器指南
有没有人有 Guid to Base34 编码器/解码器的好代码片段,我之前用谷歌搜索过它,但从未真正找到任何好的来源。
Does anyone have a nice code snippet for a Guid to Base34 encoder/decoder, I've googled around for it previously and never really found any good sources.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个 C# 中的数字基数转换类 可以相当容易地扩展为执行 base34 (或其他,如果你认为人们会混淆 S 和 5 或 b 和 6 或 i 和 j 或 B 和 8 或 9 和 g 或其他)
This Number base conversion class in C# could be fairly easily extended to do base34 (or others if you think people will confuse S and 5 or b and 6 or i and j or B and 8 or 9 and g or whatever)
这是一个简化版本...它基本上需要一个字符串,计算 MD5 哈希值,提取前四个字节作为无符号长整型(有效地将字符串映射到 4 字节数字),将其转换为 base36,然后交换出“ “X”和“Y”的“哦”和“零”字符。然后,它确保最终字符串只有六个字符,如果需要则用“Z”字符填充。
Here's a simplified version... It basically takes a string, calculates the MD5 hash, extracts the first four bytes as an unsigned long (effective mapping the string to a 4-byte number), converts that to base36 and then swaps out the "oh" and "zero" chars for "X" and "Y". Then, it ensures the final string is only six chars, padding with "Z" chars if needed.
这里的关键方法是 ToByteArray 和 这个特定的构造函数。
编码:
解码:
The key methods here are ToByteArray and this particular constructor.
Encode:
Decode: