SMALL BASIC: How to create simple encryption and decryption program
SMALL BASIC: Creating simple encryption and decryption program.
Here is the code:
GraphicsWindow.Show()
Controls.ButtonClicked = gettext
'Placing the controls
desctext = Shapes.AddText("Message:")
Shapes.Move(desctext,0,0)
mtb = Controls.AddMultiLineTextBox(0,20)
desctext2 = Shapes.AddText("Key: ")
Shapes.Move(desctext2,0,120)
key = Controls.AddTextBox(0,140)
desctext3 = Shapes.AddText("Encryted Message: ")
Shapes.Move(desctext3,0,160)
mtb2 = Controls.AddMultiLineTextBox(0,180)
Controls.AddButton("Proceed",0,280)
Sub gettext
mtbt = Controls.GetTextBoxText(mtb)
keyt = Controls.gettextboxtext(key)
TextWindow.WriteLine("Original message: ")
TextWindow.Writeline(mtbt)
TextWindow.WriteLine("")
for i = 1 to Text.GetLength(mtbt)
mtbtp[i] = Text.GetSubText(mtbt,i,1)
Textwindow.Write("Character:" + mtbtp[i])
gc = Text.GetCharacterCode(mtbtp[i])
gcwk = gc + keyt
gce[i] = Text.GetCharacter(gcwk)
textwindow.Write(", Ascii code: " + gc)
TextWindow.Writeline(", Encrypted character: " + gce[i])
EndFor
TextWindow.WriteLine("")
TextWindow.ForegroundColor="yellow"
TextWindow.WriteLine("Encrypted message: ")
'Uniting encrypted characters as a string from array
enctext = ""
For i = 0 to Text.GetLength(mtbt)
TextWindow.Write(gce[i])
enctext = enctext + gce[i]
EndFor
Controls.SetTextBoxText(mtb2,enctext)
enctext=""
EndSub