RosettaCodeData/Task/Caesar-cipher/FreeBASIC/caesar-cipher.freebasic

42 lines
858 B
Plaintext

' FB 1.05.0 Win64
Sub Encrypt(s As String, key As Integer)
Dim c As Integer
For i As Integer = 0 To Len(s)
Select Case As Const s[i]
Case 65 To 90
c = s[i] + key
If c > 90 Then c -= 26
s[i] = c
Case 97 To 122
c = s[i] + key
If c > 122 Then c -= 26
s[i] = c
End Select
Next
End Sub
Sub Decrypt(s As String, key As Integer)
Dim c As Integer
For i As Integer = 0 To Len(s)
Select Case As Const s[i]
Case 65 To 90
c = s[i] - key
If c < 65 Then c += 26
s[i] = c
Case 97 To 122
c = s[i] - key
If c < 97 Then c += 26
s[i] = c
End Select
Next
End Sub
Dim As String s = "Bright vixens jump; dozy fowl quack."
Print "Plain text : "; s
Encrypt s, 8
Print "Encrypted : "; s
Decrypt s, 8
Print "Decrypted : "; s
Sleep