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.)
Bookmarks