我在Smallbasic中遇到了一个问题,我需要将字母转换为数字,然后向它们添加一个“shift”(使用来自用户的数字),然后应用shift并将其转换回加密消息。有人知道如何解决这个问题吗?因为我不太擅长数组和编码。
发布于 2022-10-16 15:36:19
执行循环的一种方法是使用For循环,并遍历消息的每个字母。对于每个字母,您将调用将该信函移动适当数量的函数。
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
EndFunctionhttps://stackoverflow.com/questions/74088363
复制相似问题