首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >小型基本编码阵列

小型基本编码阵列
EN

Stack Overflow用户
提问于 2022-10-16 15:29:42
回答 1查看 22关注 0票数 -1

我在Smallbasic中遇到了一个问题,我需要将字母转换为数字,然后向它们添加一个“shift”(使用来自用户的数字),然后应用shift并将其转换回加密消息。有人知道如何解决这个问题吗?因为我不太擅长数组和编码。

EN

回答 1

Stack Overflow用户

发布于 2022-10-16 15:36:19

执行循环的一种方法是使用For循环,并遍历消息的每个字母。对于每个字母,您将调用将该信函移动适当数量的函数。

代码语言:javascript
复制
Here is some example code that would do what you are describing:

alphabet = "abcdefghijklmnopqrstuvwxyz"

message = "this is a test message"

shift = 3

For i = 1 to Len(message)

letter = Mid(message, i, 1)

shiftedLetter = ShiftLetter(letter, shift)

Print(shiftedLetter)

EndFor

Function ShiftLetter(letter, shift)

letterIndex = InStr(alphabet, letter)

shiftedIndex = letterIndex + shift

If shiftedIndex > Len(alphabet) Then

shiftedIndex = shiftedIndex - Len(alphabet)

EndIf

shiftedLetter = Mid(alphabet, shiftedIndex, 1)

Return shiftedLetter

EndFunction
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74088363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档