加密有点乱

时间:2016-04-11 21:00:03

标签: vb.net

    Dim A As String
    Dim B As String
    Dim C As String
    Dim D As String
    Dim EE As String
    Dim F As String
    Dim G As String
    Dim H As String
    Dim I As String
    Dim J As String
    Dim K As String
    Dim L As String
    Dim M As String
    Dim N As String
    Dim O As String
    Dim P As String
    Dim Q As String
    Dim R As String
    Dim S As String
    Dim T As String
    Dim U As String
    Dim V As String
    Dim W As String
    Dim X As String
    Dim Y As String
    Dim Z As String

    Dim la As String
    Dim lb As String
    Dim lc As String
    Dim ld As String
    Dim le As String
    Dim lf As String
    Dim lg As String
    Dim lh As String
    Dim li As String
    Dim lj As String
    Dim lk As String
    Dim ll As String
    Dim lm As String
    Dim ln As String
    Dim lo As String
    Dim lp As String
    Dim lq As String
    Dim lr As String
    Dim ls As String
    Dim lt As String
    Dim lu As String
    Dim lv As String
    Dim lw As String
    Dim lx As String
    Dim ly As String
    Dim lz As String

    Private Sub btnGen_Click(sender As Object, e As EventArgs) Handles btnGen.Click
        If txtMessage.Text = String.Empty Then
            MessageBox.Show("Text Box 'Message' is empty")
            Ok = False
        End If
        If txtKey.Text = String.Empty Then
            MessageBox.Show("Text Box 'Key' is empty")
            Ok = False
        End If
        If txtShuffle.Text = String.Empty Then
            MessageBox.Show("Text Box 'Shuffle' is empty")
            Ok = False
        End If
        OkNum = IsNumeric(txtShuffle.Text)
        If OkNum = False Then
            MessageBox.Show("Text Box 'Shuffle' is not numeric")
            Ok = False
        End If

        If Ok = True Then
            Message = txtMessage.Text
            Key = txtKey.Text
            Shuffle = txtShuffle.Text
            ShufCount = 0
            A = Key.Chars(ShufCount)
            ShufCount += 1
            B = Key.Chars(ShufCount)
            ShufCount += 1
            C = Key.Chars(ShufCount)
            ShufCount += 1
            D = Key.Chars(ShufCount)
            ShufCount += 1
            EE = Key.Chars(ShufCount)
            ShufCount += 1
            F = Key.Chars(ShufCount)
            ShufCount += 1
            G = Key.Chars(ShufCount)
            ShufCount += 1
            H = Key.Chars(ShufCount)
            ShufCount += 1
            I = Key.Chars(ShufCount)
            ShufCount += 1
            J = Key.Chars(ShufCount)
            ShufCount += 1
            K = Key.Chars(ShufCount)
            ShufCount += 1
            L = Key.Chars(ShufCount)
            ShufCount += 1
            M = Key.Chars(ShufCount)
            ShufCount += 1
            N = Key.Chars(ShufCount)
            ShufCount += 1
            O = Key.Chars(ShufCount)
            ShufCount += 1
            P = Key.Chars(ShufCount)
            ShufCount += 1
            Q = Key.Chars(ShufCount)
            ShufCount += 1
            R = Key.Chars(ShufCount)
            ShufCount += 1
            S = Key.Chars(ShufCount)
            ShufCount += 1
            T = Key.Chars(ShufCount)
            ShufCount += 1
            U = Key.Chars(ShufCount)
            ShufCount += 1
            V = Key.Chars(ShufCount)
            ShufCount += 1
            W = Key.Chars(ShufCount)
            ShufCount += 1
            X = Key.Chars(ShufCount)
            ShufCount += 1
            Y = Key.Chars(ShufCount)
            ShufCount += 1
            Z = Key.Chars(ShufCount)
            ShufCount += 1

            la = Key.Chars(ShufCount)
            ShufCount += 1
            lb = Key.Chars(ShufCount)
            ShufCount += 1
            lc = Key.Chars(ShufCount)
            ShufCount += 1
            ld = Key.Chars(ShufCount)
            ShufCount += 1
            le = Key.Chars(ShufCount)
            ShufCount += 1
            lf = Key.Chars(ShufCount)
            ShufCount += 1
            lg = Key.Chars(ShufCount)
            ShufCount += 1
            lh = Key.Chars(ShufCount)
            ShufCount += 1
            li = Key.Chars(ShufCount)
            ShufCount += 1
            lj = Key.Chars(ShufCount)
            ShufCount += 1
            lk = Key.Chars(ShufCount)
            ShufCount += 1
            ll = Key.Chars(ShufCount)
            ShufCount += 1
            lm = Key.Chars(ShufCount)
            ShufCount += 1
            ln = Key.Chars(ShufCount)
            ShufCount += 1
            lo = Key.Chars(ShufCount)
            ShufCount += 1
            lp = Key.Chars(ShufCount)
            ShufCount += 1
            lq = Key.Chars(ShufCount)
            ShufCount += 1
            lr = Key.Chars(ShufCount)
            ShufCount += 1
            ls = Key.Chars(ShufCount)
            ShufCount += 1
            lt = Key.Chars(ShufCount)
            ShufCount += 1
            lu = Key.Chars(ShufCount)
            ShufCount += 1
            lv = Key.Chars(ShufCount)
            'MessageBox.Show(lv)
            ShufCount += 1
            lw = Key.Chars(ShufCount)
            ShufCount += 1
            lx = Key.Chars(ShufCount)
            ShufCount += 1
            ly = Key.Chars(ShufCount)
            ShufCount += 1
            lz = Key.Chars(ShufCount)

            Dim dict As New Dictionary(Of Integer, String)
            dict.Add(0, A)
            dict.Add(1, B)
            dict.Add(2, C)
            dict.Add(3, D)
            dict.Add(4, EE)
            dict.Add(5, F)
            dict.Add(6, G)
            dict.Add(7, H)
            dict.Add(8, I)
            dict.Add(9, J)
            dict.Add(10, K)
            dict.Add(11, L)
            dict.Add(12, M)
            dict.Add(13, N)
            dict.Add(14, O)
            dict.Add(15, P)
            dict.Add(16, Q)
            dict.Add(17, R)
            dict.Add(18, S)
            dict.Add(19, T)
            dict.Add(20, U)
            dict.Add(21, V)
            dict.Add(22, W)
            dict.Add(23, X)
            dict.Add(24, Y)
            dict.Add(25, Z)

            dict.Add(26, la)
            dict.Add(27, lb)
            dict.Add(28, lc)
            dict.Add(29, ld)
            dict.Add(30, le)
            dict.Add(31, lf)
            dict.Add(32, lg)
            dict.Add(33, lh)
            dict.Add(34, li)
            dict.Add(35, lj)
            dict.Add(36, lk)
            dict.Add(37, ll)
            dict.Add(38, lm)
            dict.Add(39, ln)
            dict.Add(40, lo)
            dict.Add(41, lp)
            dict.Add(42, lq)
            dict.Add(43, lr)
            dict.Add(44, ls)
            dict.Add(45, lt)
            dict.Add(46, lu)
            dict.Add(47, lv)
            dict.Add(48, lw)
            dict.Add(49, lx)
            dict.Add(50, ly)
            dict.Add(51, lz)

            If radEn.Checked = True Then
                MessageBox.Show("Running radEn")
                Dim Encrypted As String = ""
                Dim MessLength As Integer = Message.Length()
                Dim WhileCounter As Integer = 0

                While WhileCounter < MessLength
                    If Message.Chars(WhileCounter) = "A" Then
                        Encrypted = Encrypted + dict(0)
                    End If
                    If Message.Chars(WhileCounter) = "B" Then
                        Encrypted = Encrypted + dict(1)
                    End If
                    If Message.Chars(WhileCounter) = "C" Then
                        Encrypted = Encrypted + dict(2)
                    End If
                    If Message.Chars(WhileCounter) = "D" Then
                        Encrypted = Encrypted + dict(3)
                    End If
                    If Message.Chars(WhileCounter) = "E" Then
                        Encrypted = Encrypted + dict(4)
                    End If
                    If Message.Chars(WhileCounter) = "F" Then
                        Encrypted = Encrypted + dict(5)
                    End If
                    If Message.Chars(WhileCounter) = "G" Then
                        Encrypted = Encrypted + dict(6)
                    End If
                    If Message.Chars(WhileCounter) = "H" Then
                        Encrypted = Encrypted + dict(7)
                    End If
                    If Message.Chars(WhileCounter) = "I" Then
                        Encrypted = Encrypted + dict(8)
                    End If
                    If Message.Chars(WhileCounter) = "J" Then
                        Encrypted = Encrypted + dict(9)
                    End If
                    If Message.Chars(WhileCounter) = "K" Then
                        Encrypted = Encrypted + dict(10)
                    End If
                    If Message.Chars(WhileCounter) = "L" Then
                        Encrypted = Encrypted + dict(11)
                    End If
                    If Message.Chars(WhileCounter) = "M" Then
                        Encrypted = Encrypted + dict(12)
                    End If
                    If Message.Chars(WhileCounter) = "N" Then
                        Encrypted = Encrypted + dict(13)
                    End If
                    If Message.Chars(WhileCounter) = "O" Then
                        Encrypted = Encrypted + dict(14)
                    End If
                    If Message.Chars(WhileCounter) = "P" Then
                        Encrypted = Encrypted + dict(15)
                    End If
                    If Message.Chars(WhileCounter) = "Q" Then
                        Encrypted = Encrypted + dict(16)
                    End If
                    If Message.Chars(WhileCounter) = "R" Then
                        Encrypted = Encrypted + dict(17)
                    End If
                    If Message.Chars(WhileCounter) = "S" Then
                        Encrypted = Encrypted + dict(18)
                    End If
                    If Message.Chars(WhileCounter) = "T" Then
                        Encrypted = Encrypted + dict(19)
                    End If
                    If Message.Chars(WhileCounter) = "U" Then
                        Encrypted = Encrypted + dict(20)
                    End If
                    If Message.Chars(WhileCounter) = "V" Then
                        Encrypted = Encrypted + dict(21)
                    End If
                    If Message.Chars(WhileCounter) = "W" Then
                        Encrypted = Encrypted + dict(22)
                    End If
                    If Message.Chars(WhileCounter) = "X" Then
                        Encrypted = Encrypted + dict(23)
                    End If
                    If Message.Chars(WhileCounter) = "Y" Then
                        Encrypted = Encrypted + dict(24)
                    End If
                    If Message.Chars(WhileCounter) = "Z" Then
                        Encrypted = Encrypted + dict(25)
                    End If
                    If Message.Chars(WhileCounter) = "a" Then
                        Encrypted = Encrypted + dict(26)
                    End If
                    If Message.Chars(WhileCounter) = "b" Then
                        Encrypted = Encrypted + dict(27)
                    End If
                    If Message.Chars(WhileCounter) = "c" Then
                        Encrypted = Encrypted + dict(28)
                    End If
                    If Message.Chars(WhileCounter) = "d" Then
                        Encrypted = Encrypted + dict(29)
                    End If
                    If Message.Chars(WhileCounter) = "e" Then
                        Encrypted = Encrypted + dict(30)
                    End If
                    If Message.Chars(WhileCounter) = "f" Then
                        Encrypted = Encrypted + dict(31)
                    End If
                    If Message.Chars(WhileCounter) = "g" Then
                        Encrypted = Encrypted + dict(32)
                    End If
                    If Message.Chars(WhileCounter) = "h" Then
                        Encrypted = Encrypted + dict(33)
                    End If
                    If Message.Chars(WhileCounter) = "i" Then
                        Encrypted = Encrypted + dict(34)
                    End If
                    If Message.Chars(WhileCounter) = "j" Then
                        Encrypted = Encrypted + dict(35)
                    End If
                    If Message.Chars(WhileCounter) = "k" Then
                        Encrypted = Encrypted + dict(36)
                    End If
                    If Message.Chars(WhileCounter) = "l" Then
                        Encrypted = Encrypted + dict(37)
                    End If
                    If Message.Chars(WhileCounter) = "m" Then
                        Encrypted = Encrypted + dict(38)
                    End If
                    If Message.Chars(WhileCounter) = "n" Then
                        Encrypted = Encrypted + dict(39)
                    End If
                    If Message.Chars(WhileCounter) = "o" Then
                        Encrypted = Encrypted + dict(40)
                    End If
                    If Message.Chars(WhileCounter) = "p" Then
                        Encrypted = Encrypted + dict(41)
                    End If
                    If Message.Chars(WhileCounter) = "q" Then
                        Encrypted = Encrypted + dict(42)
                    End If
                    If Message.Chars(WhileCounter) = "r" Then
                        Encrypted = Encrypted + dict(43)
                    End If
                    If Message.Chars(WhileCounter) = "s" Then
                        Encrypted = Encrypted + dict(44)
                    End If
                    If Message.Chars(WhileCounter) = "t" Then
                        Encrypted = Encrypted + dict(45)
                    End If
                    If Message.Chars(WhileCounter) = "u" Then
                        Encrypted = Encrypted + dict(46)
                    End If
                    If Message.Chars(WhileCounter) = "v" Then
                        Encrypted = Encrypted + dict(47)
                    End If
                    If Message.Chars(WhileCounter) = "w" Then
                        Encrypted = Encrypted + dict(48)
                    End If
                    If Message.Chars(WhileCounter) = "x" Then
                        Encrypted = Encrypted + dict(49)
                    End If
                    If Message.Chars(WhileCounter) = "y" Then
                        Encrypted = Encrypted + dict(50)
                    End If
                    If Message.Chars(WhileCounter) = "z" Then
                        Encrypted = Encrypted + dict(51)
                    End If
                    If Message.Chars(WhileCounter) = " " Then
                        Encrypted = Encrypted + " "
                    End If

                    WhileCounter += 1
                End While



                FinalMessage = Encrypted
                Editor.Show()
                Editor.txtEdit.Clear()
                Editor.txtEdit.ReadOnly = True
                Editor.txtEdit.Text = FinalMessage
            ElseIf radDe.Checked = True Then
                Dim Decrypted As String = ""
                Dim MessLength As Integer = Message.Length()
                Dim WhileCounter As Integer = 0
                Dim LazyCounter As Integer = 0

                While WhileCounter < MessLength
                    LazyCounter = 0
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "A"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "B"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "C"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "D"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "E"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "F"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "G"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "H"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "I"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "J"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "K"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "L"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "M"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "N"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "O"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "Q"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "R"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "S"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "T"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "U"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "V"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "W"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "X"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "Y"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "Z"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "a"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "b"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "c"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "d"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "e"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "f"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "g"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "h"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "i"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "j"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "k"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "l"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "m"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "n"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "o"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "p"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "q"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "r"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "s"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "t"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "u"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "v"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "w"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "x"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "y"
                    End If
                    LazyCounter += 1
                    If Message.Chars(WhileCounter) = dict(LazyCounter) Then
                        Decrypted = Decrypted + "z"
                    End If
                    If Message.Chars(WhileCounter) = " " Then
                        Decrypted = Decrypted + " "
                    End If

                    LazyCounter = 0
                    WhileCounter += 1
                End While

                FinalMessage = Decrypted



                Editor.Show()
                Editor.txtEdit.Clear()
                Editor.txtEdit.ReadOnly = True
                Editor.txtEdit.Text = FinalMessage
            End If
            ShufCount = 0
            While dict.Count > ShufCount
                dict.Remove(ShufCount)
                ShufCount += 1
            End While
        End If
    End Sub
End Class

我很接近这项工作。但是,有时解密消息会导致一些问题。如果我将我的消息和密钥相同,那么现在我只使用&#34; QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm&#34;。解密它结果是&#34; ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef ...&#34;这应该是它应该做的并且工作正常。

但如果我把'#34;我的名字是BOB&#34;对于消息并使用相同的密钥。在解密之后,事实证明是&#34; MZ NAME IT BOB&#34;。另外&#34;吉姆斯猫是丑陋的&#34;加密然后解密变成&#34; Jjnt Cbu jt Vhmz&#34;我试过寻找我可能做出的简单错误,例如当它应该是2时分配C = 3.有时候,就像第一个一样,只有1或2个字母。其他人,如第二个,并且不可读。任何人都有任何见解或任何想法,为什么这不起作用?

0 个答案:

没有答案