Hill cipher in VB.NET ?? RRS feed

All replies

  • Hi,

    see the following link:

    Implementation of Encryption of Hill Cipher 

    Imports System
    Imports System.Collections.Generic
    Imports System.Linq
    Imports System.Text
    Namespace Hill_Cipher
        Class Program
            Private Shared Sub Main(ByVal args As String())
                Dim i, j As Integer, sum As Integer = 0, [end] As Integer = 0
                Dim mtrx As Integer(,) = New Integer(24, 24) {}
                Dim ans As Integer(,) = New Integer(24, 0) {}
                Dim text As String = ""
                Console.WriteLine("Enter your Plaintext")
                text = Console.ReadLine()
                Dim txt As Char() = text.ToCharArray()
                [end] = txt.Length
                For i = 0 To [end] - 1
                    txt(i) = Convert.ToChar(txt(i) - "a"c)
                Dim rnd As Random = New Random()
                For i = 0 To [end] - 1
                    For j = 0 To [end] - 1
                        mtrx(i, j) = rnd.[Next]()
                For i = 0 To [end] - 1
                    sum = 0
                    For j = 0 To [end] - 1
                        sum += mtrx(i, j) * CInt(txt(j))
                    ans(i, 0) = sum
                Console.Write("Your CipherText is:")
                For i = 0 To [end] - 1
                    Dim cipher As Char = ChrW((((ans(i, 0)) Mod 26) + 97))
                    Console.Write(vbTab & cipher)
            End Sub
        End Class
    End Namespace

    Best Regards,


    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    • Edited by Alex Li-MSFT Wednesday, January 23, 2019 6:33 AM
    Wednesday, January 23, 2019 6:18 AM