I have an XOR encypted file by VB.net using this function to scramble:
Public Class Crypter
...
'This Will convert String to bytes, then call the other function.
Public Function Crypt(ByVal Data As String) As String
Return Encoding.Default.GetString(Crypt(Encoding.Default.GetBytes(Data)))
End Function
'This calls XorCrypt giving Key converted to bytes
Public Function Crypt(ByVal Data() As Byte) As Byte()
Return XorCrypt(Data, Encoding.Default.GetBytes(Me.Key))
End Function
'Xor Encryption.
Private Function XorCrypt(ByVal Data() As Byte, ByVal Key() As Byte) As Byte()
Dim i As Integer
If Key.Length <> 0 Then
For i = 0 To Data.Length - 1
Data(i) = Data(i) Xor Key(i Mod Key.Length)
Next
End If
Return Data
End Function
End Class
and saved this way:
Dim Crypter As New Cryptic(Key)
'open destination file
Dim objWriter As New StreamWriter(fileName)
'write crypted content
objWriter.Write(Crypter.Crypt(data))
Now I need to open the file again using Python, but I'm having trouble getting single bytes , this is the XOR function in python:
def crypto(self, data):
'crypto(self, data) -> str'
return ''.join(chr((ord(x) ^ ord(y)) % 256) \
for (x, y) in izip(data.decode('utf-8'), cycle(self.key))
I had to add% 256, because sometimes x is> 256 ie not one byte .
This thing of two bytes transmitted does not violate decryption , because the key saves "paired" with the following data.
.
- , à, è, ì . .
, 256, , , chr...