Android Question how to make an application like in web www.rot13.com with b4a?

if in vb.net I've managed to create as in www.rot13.com with coding as follows.

Public Class Form1
'variable untuk menampung faktor sandi
Dim intFactor As Integer = 0

'variable untuk menampung hasil penyandian
Dim intChiper As Integer = 0

'variable untuk menampung sumber
Dim intSource As Integer = 0

'Ambil nilai faktor sandi dari combobox
Private Sub AmbilNilaiFaktor()
Dim strROT As String = cbxROT.Text

'bila ROTx, ambil hanya 1 karakter paling kanan
If strROT.Length = 4 Then
intFactor = Int32.Parse(strROT.Substring(3, 1))

Else
'bila ROTxx, ambil 2 karakter paling kanan
intFactor = Int32.Parse(strROT.Substring(3, 2))
End If
End Sub
'Lakukan proses penyandian (cipher)
Private Sub ProsesROT()

' kosongkan textbox txtOutput
txtOutput.Text = ""

' proses hanya bila txtInput mengandung text
If txtInput.Text.Trim.Length > 0 Then

' looping setiap karakter dari string text txtInput
For Each c As Char In txtInput.Text

'konversi ke Integer
intSource = Convert.ToInt32(c)

' bila karakter bukan A-Z dan a-z
' tidak disandi
If intSource < 65 OrElse (intSource > 90 And intSource < 97) OrElse intSource > 122 Then
txtOutput.Text += c.ToString
Continue For
End If

'hitung nilai penyandian
intChiper = intSource + intFactor
If intChiper > 90 AndAlso (intSource >= 65 And intSource <= 90) Then
' bila hasil penyandian lebih besar dari 90 (Z)
' dan sumber penyandian adalah A-Z
' 65 (A) + (hasil penyandian - 91 [Z+1])
' konversikan hasil perhitungan menjadi CHAR

c = Chr(65 + (intChiper - 91))
ElseIf intChiper > 122 AndAlso (intSource >= 97 And intSource <= 122) Then
' bila hasil penyandian lebih besar dari 122 (z)
' dan sumber penyandian adalah a-z
' 97 (a) + (hasil penyandian - 123 [z+1])
' konversikan hasil perhitungan menjadi CHAR

c = Chr(97 + (intChiper - 123))
Else
' bila hasil penyandian selain 2 kondisi di atas
' konversikan hasil penyandian menjadi CHAR
c = Convert.ToChar(intChiper)
End If

' tambahkan hasil penyandian ke text txtOutput
' dengan konversi ke STRING
txtOutput.Text += c.ToString
Next
End If

End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

cbxROT.SelectedIndex = 0
txtInput.Select()

End Sub

Private Sub cbxROT_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbxROT.SelectedIndexChanged
AmbilNilaiFaktor()
ProsesROT()

End Sub

Private Sub txtInput_TextChanged(sender As Object, e As EventArgs) Handles txtInput.TextChanged
ProsesROT()

End Sub
End Class
 
Last edited by a moderator:

Peter Simpson

Expert
Licensed User
Longtime User
I advise you to start by downloading the B4A PDF tutorial and manuals by Klaus.

To insert blocks of code you need to encapsulate 'code' and '/code' in between square brackets [], or you can just do the following.
Untitled-2.png
 
Last edited:
Upvote 0
Top