重新排列字母表 (VB)
当我正在做一个简单的替换密码时,我基本上想用前面的关键字重新排列字母表。我已经弄清楚了这样做的逻辑,但我有点卡在编码方面。
我想要的是这样的:
Dim key = "keyword"
For i = 0 to 26
'insert keyword and put in A to Z after without duplicating characters
Next
'output: keywordabcfghijlmnpqstuvxz
I wanted to basically rearrange the alphabet with a keyword infront as I am doing a simple substitutional cipher. I have kind of worked out the logic of doing that but I am a bit stuck on the coding side.
What I wanted was something like:
Dim key = "keyword"
For i = 0 to 26
'insert keyword and put in A to Z after without duplicating characters
Next
'output: keywordabcfghijlmnpqstuvxz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为循环遍历密钥比循环遍历字母表更干净:
或者稍微更有效地更改替换行,如下所示,以避免在每次迭代时扫描字母表的所有 26 个字母:
I think looping through the key is cleaner than looping through the alphabet:
or slightly more efficient change the replace line as follows to avoid scanning all 26 letters of the alphabet on each iteration:
这是 vb 中的解决方案:
如果您想检查键的唯一字符,那么您可以只对键的字符运行 for 循环,并删除当前字符(如果已经存在)。如果删除该字符,请记住将 for 循环移回一个字符。
Here is the solution in vb:
If you want to check for unique char for the key, then you can just run a for loop through the characters of the key and remove the current char if already exist. Remember to move the for loop one char back if you delete the char.