Merge pull request #5 from AnkitApurv/master

Added VB.NET implementation
This commit is contained in:
Kyle Banks 2016-03-16 15:39:44 -04:00
commit ee46f563d3
2 changed files with 32 additions and 1 deletions

View File

@ -9,10 +9,11 @@ Simple implementation of XOR Encryption/Decrypting in various languages, includi
- [Dart](Dart/xorencryption.dart)
- [F#](F%23/Program.fs) by [pawelizycki](https://github.com/pawelizycki)
- [Groovy](Groovy/XOREncryption.groovy)
- [Java \(Android Compatible\)](Java \(Android compatible\)/XOREncryption.java)
- [Java \(Android Compatible\)](Java \(Android compatible\)/XOREncryption.java)
- [JavaScript \(Node.js Compatible\)](JavaScript/XOREncryption.js)
- [Objective-C](Objective-C/main.m)
- [Python](Python/XOREncryption.py)
- [Visual Basic.NET](VB.NET/XORCrypto.vb)
This implementation goes beyond the basic single-key model to use multiple keys in a particular sequence, making it that much more difficult to brute-force.

30
VB.NET/XORCrypto.vb Normal file
View File

@ -0,0 +1,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