title: XOR Encryption Gives Different Result When Encrypting and Decrypting
body: <p>I want to encrypt a file. I use XOR to Encrypt it. But, the problem is, i can encrypt it, but when i want to decrypt it, it gives me different result (not the original file)</p>
  
  <p>Here is the code that i use</p>
  
  <pre><code>Public Function Encrypt(ByVal txt As String, ByVal pass As String) As String
  Dim mem() As Byte
  mem = StrConv(txt, vbFromUnicode)
  For i = 0 To UBound(mem)
      mem(i) = Asc(mem(i)) Xor Asc(Mid(pass, (i Mod Len(pass)) + 1, 1))
  Next i
  Encrypt = StrConv(mem, vbUnicode)
  Erase mem
  End Function
  
  Public Function Decrypt(ByVal txt As String, ByVal pass As String) As String
  Dim mem() As Byte
  mem = StrConv(txt, vbFromUnicode)
  For i = 0 To UBound(mem)
      mem(i) = Asc(mem(i)) Xor Asc(Mid(pass, (i Mod Len(pass)) + 1, 1))
  Next i
  Decrypt = StrConv(mem, vbUnicode)
  Erase mem
  End Function
  
  Private Sub Form_Load()
  Enkrip = Encrypt(txt.LoadFile("C:\mom.txt"), "FROM YOUR SON")
  dekrip = Decrypt(Enkrip, "FROM YOUR SON")
  
  MsgBox Enkrip &amp; vbCrLf &amp; dekrip
  End Sub
  </code></pre>
  
  <p>The value of dekrip should be the original content of C:\mom.txt, but it returns different result</p>
  
  <hr>
  
  <p>I also tried this code, and it works well</p>
  
  <pre><code>Private Sub Form_Load()
  Data = "A"
  pass = "B"
  
  enkrip = Chr(Asc(Data) Xor Asc(pass))
  dekrip = Chr(Asc(enkrip) Xor Asc(pass))
  
  MsgBox enkrip &amp; vbCrLf &amp; dekrip
  End Sub
  </code></pre>
  
  <hr>
  
  <p>What should I do to fix my code? </p>
  
  <p>Thanks</p>