How to use XOR Encryption (XOR Cipher) to encryption a string in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function XOREncryption(ByVal s As String, ByVal key As String) As String
        Dim slen As Integer = s.Length, keylen As Integer = key.Length
        Dim result As Char() = New Char(slen - 1) {}

        For i As Integer = 0 To slen - 1
            result(i) = ChrW(Asc(S(i)) Xor Asc(key(i Mod keyLen)))
        Next

        Return New String(result)
    End Function

    Public Shared Sub Main()
        Dim s As String = "VB.NET is a multi-paradigm object-oriented programming language"
        Dim key As String = "secretkey"
	
        Dim cipher As String = XOREncryption(s, key)
        Console.WriteLine(cipher)
	
        Dim noncipher As String = XOREncryption(cipher, key)
        Console.WriteLine(noncipher)
    End Sub
End Class




' run:
'
' %'M<  K
' SCTY	
' 
' KS	
' 
' VB.NET is a multi-paradigm object-oriented programming language
' 

 



answered Dec 31, 2021 by avibootz
...