Results 1 to 2 of 2

Thread: help in caesar cipher coding

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    3

    help in caesar cipher coding

    hello there!!!
    I have been assign 2 do a simple Caesar Shift cipher in visual basic where the user input the text or sentences and encrypt it. i have been trying these coding below and it still shows errors! CAN ANYONE help me by telling me what wrong with the coding!
    ///////////////////
    'MAIN FORM
    Option Explicit
    Private Tcrypto As New Ecrypto

    Private Sub cmdEncode_Click()
    Dim tmpoutput As String

    AssignProperties
    txtEncode = Tcrypto.EncodeCeasar

    End Sub

    Private Sub AssignProperties()

    Tcrypto.lb1 = "kethieswaran" 'Val(txtMain.text)
    Tcrypto.lb2 = "d" 'Val(txtK1.text)

    End Sub

    Private Sub Form_Load()

    End Sub

    'Class Module
    Option Explicit

    Private Ttxtlb1 As String
    Private Ttxtlb2 As String

    Public Function EncodeCeasar() As String

    'encode
    Dim i As Long
    Dim plainC As Integer
    Dim codeC As Integer
    Dim shiftC As Integer

    'trim
    Ttxtlb1 = TrimText(Ttxtlb1, True, False, False, False)
    If Ttxtlb1 = "" Then MsgBox " **** me", vbCritical
    Exit Function

    shiftC = Asc(Ttxtlb2) - 65

    'encode2
    For i = 1 To Len(Ttxtlb1)
    plainC = Asc(Mid(Ttxtlb1, i, 12)) - 64
    If codeC > 26 Then codeC = codeC - 26
    EncodeCeasar = EncodeCeasar & Chr(codeC + 64)
    Next i

    End Function

    Public Function TrimText(TextIn As String, Letters As Boolean, Numbers As Boolean, Spaces As Boolean, Points As Boolean)
    'trim a strings letters, numbers, spaces or points
    Dim i As Long
    Dim tmp As Byte
    For i = 1 To Len(TextIn)
    tmp = Asc(UCase(Mid(TextIn, i, 1)))
    If Letters = True And (tmp > 64 And tmp < 123) Then
    TrimText = TrimText & Chr(tmp)
    ElseIf Numbers = True And (tmp > 47 And tmp < 58) Then
    TrimText = TrimText & Chr(tmp)
    ElseIf Spaces = True And tmp = 32 Then
    TrimText = TrimText & Chr(tmp)
    ElseIf Points = True And tmp = 46 Then
    TrimText = TrimText & Chr(tmp)
    End If
    Next
    End Function

    Public Property Get lb1() As String

    lb1 = Ttxtlb1
    ' Ttxtlb1 = lb1
    End Property

    Public Property Let lb1(ByVal strlb1 As String)

    Ttxtlb1 = strlb1
    'lb1 = Ttxtlb1
    End Property



    Public Property Get lb2() As String
    lb2 = Ttxtlb2
    'Ttxtlb2 = lb2
    End Property

    Public Property Let lb2(ByVal strlb2 As String)

    Ttxtlb2 = strlb2
    'lb2 = Ttxtlb2
    End Property


    ///////////////////
    !!!!the input from the form is not passed to the class module!!!!
    thank you

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: help in caesar cipher coding

    Look here at prophecy's tutorial. It's really a lot simpler than what you have.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width