Results 1 to 7 of 7

Faulty Code

Threaded View

  1. #1
    Registered User
    Join Date
    02-10-2008
    Posts
    8

    Exclamation Faulty Code

    I have a project for my Cryptology class and I can't find a fault in my code. I even asked my classmate to see if anything was wrong and he said my code was essentially the same as his. I'm looked over it several times and I was hoping someone here could help me spot my mistake. For background information, this code is supposed to decrypt (bits to text) and encrypt (text to bits). If you see nothing wrong here, could you please check out the file I attached? It contains my entire code. Thanks to anyone who tries!

    Here's the code:

    'Encrypts input text to bits and then outputs it
    Private Sub cmdEncrypt_Click()
        Dim Loop1 As Integer
        Dim RegSize As Integer
        Dim TapLength As Integer
        Dim NumTaps As Integer
        Dim TapLocation As Integer
        Dim TapNum As Integer
        Dim tempBin As String
        
       
        ASCLength = Len(txtPlain)
        
        'Converts each plaintext character into a binary code string
        For Loop1 = 1 To ASCLength
            tempBin = tempBin & ASCIIToBin(Mid(txtPlain, Loop1, 1))
        Next Loop1
        
        
        Binlength = Len(tempBin)
            
        '***Checks the size of the register***
        RegSize = Len(txtBit)
        
        '***Copies register to an array***
        ReDim Bits(RegSize - 1)
        For Loop1 = 0 To (RegSize - 1)
            Bits(Loop1) = Mid(txtBit, Loop1 + 1, 1)
        Next Loop1
        
        '***Stores taps in an array***
        'Calculates the number of taps
        TapLength = Len(txtTaps)
        NumTaps = 1
        For Loop1 = 1 To TapLength
            If Mid(txtTaps, Loop1, 1) = "," Then NumTaps = NumTaps + 1
        Next Loop1
        ReDim Taps(NumTaps - 1)
        'Stores taps to an array
        TapNum = 0
        TapLocation = 1
        For Loop1 = 2 To TapLength
            If Mid(txtTaps, Loop1, 1) = "," Then
                Taps(TapNum) = Mid(txtTaps, TapLocation, Loop1 - TapLocation)
                TapNum = TapNum + 1
                TapLocation = Loop1 + 1
            End If
        Next Loop1
        'Stores last tap
        Taps(NumTaps - 1) = Mid(txtTaps, TapLocation, TapLength - TapLocation + 1)
        
        '***Generate the random bits***
        For Loop1 = 1 To Binlength
            'Calculate the new input bit
            TempBit = New_bit(NumTaps - 1)
            'Output a bit
            Output = Output & Bits(RegSize - 1)
            'Shift over the register
            For Loop2 = RegSize - 1 To 1 Step -1
                Bits(Loop2) = Bits(Loop2 - 1)
            Next Loop2
            Bits(0) = TempBit
        Next Loop1
    
        'Xors & outputs the cipherbits
        For Loop1 = 1 To Binlength
            txtCipher = txtCipher & ((Mid(tempBin, Loop1, 1)) Xor (Mid(Output, Loop1, 1)))
        Next Loop1
    End Sub
    (Btw, in my txt file, I know the decryption program doesn't work, but I'm positive that has nothing to do with the error.)
    Attached Files Attached Files
    Last edited by gizoku00; 04-07-2008 at 09:32 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1