-
Notifications
You must be signed in to change notification settings - Fork 83
/
XORCrypto.vb
30 lines (27 loc) · 1.26 KB
/
XORCrypto.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Module XORCrypto
Sub Main()
Dim input As String = Console.ReadLine()
Dim output As String = encryptDecrypt(input)
Console.WriteLine("Input : " & input)
Console.WriteLine("Output : " & output)
Dim rett As String = encryptDecrypt(output)
Console.WriteLine("RoundAbout : " & rett)
Console.ReadLine()
End Sub
''' <summary>
''' Encrypts and Decrypts string via XOR Operation
''' </summary>
''' <param name="input">String to be encrypted/decrypted</param>
''' <returns>Encrypted/Decrypted output string</returns>
Private Function encryptDecrypt(input As String) As String
Dim key As Char() = {"K"c, "C"c, "Q"c}
'Any chars will work, in an array of any size
Dim output As Char() = New Char(input.Length - 1) {}
For i As Integer = 0 To input.Length - 1
output(i) = ChrW(AscW(input(i)) Xor AscW(key(i Mod key.Length)))
'ChrW(CharCode As Integer) As Char (Unicode) : Returns the character associated with the specified character code
'AscW([String] As Char) As Integer (Unicode) : Returns an integer value representing the character code corresponding to a character
Next
Return New String(output)
End Function
End Module