While "True" ' exit <> "True"
strOut = ""
TextWindow.Write("[E]ncrypt | [D]ecrypt (else Quit) ?: ")
action = Text.ConvertToLowerCase(TextWindow.Read())
If action <> "e" And action <> "d" Then
Program.End()
EndIf
TextWindow.WriteLine(lf+ "Text to En-/Decrypt ?:")
strIn = Text.ConvertToLowerCase(TextWindow.Read())
If strIn = "" Then
Program.End()
EndIf
TextWindow.WriteLine("")
delta = 0
While delta < 1 Or delta > 25 Or delta <> Math.Floor(Math.Abs(delta))
TextWindow.Write("Characters offset [1,25] ?: ")
delta = TextWindow.ReadNumber()
EndWhile
len = Text.GetLength(strIn)
If action = "e" Then
TextWindow.WriteLine(lf+ "ENCRYPTED message:")
Encrypt()
Else
TextWindow.WriteLine(lf+ "DECRYPTED message:")
Decrypt()
EndIf
TextWindow.WriteLine(strOut)
TextWindow.WriteLine(sep +lf)
EndWhile
' ////////// SUBs \\\\\\\\\\
'' To ignore all chars outside of [65,90] and [97,122], comment out the 'Else' branches (2x) and all other chars will be removed.
'' so eg. C:\Program Files\Microsoft\Small Basic\
'' will become (after en- & decryption): cprogramfilesmicrosoftsmallbasic
'' At any rate, output will always be lower case.
Sub Encrypt
For n = 1 To len
char = Text.GetSubText(strIn, n, 1)
code = Text.GetCharacterCode(char)
'' Only letters a-z are encryped, rest remains unchanged
If code > 96 And code < 123 Then
strOut = strOut + Text.GetCharacter(97 + Math.Remainder(code+delta-97, 26))
Else '
strOut = strOut + char '
EndIf
EndFor
EndSub
Sub Decrypt
For n = 1 To len
char = Text.GetSubText(strIn, n, 1)
code = Text.GetCharacterCode(char)
'' Only letters a-z are decryped, rest remains unchanged
If code > 96 And code < 123 Then
strOut = strOut + Text.GetCharacter(97 + Math.Remainder(code-delta-71, 26)) ' 26 - 97 = -71
Else '
strOut = strOut + char '
EndIf
EndFor
EndSub