Note that there are some explanatory texts on larger screens.

plurals
  1. POPython byte per byte XOR decryption
    primarykey
    data
    text
    <p>I have an XOR encypted file by a VB.net program using this function to scramble:</p> <pre><code>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 &lt;&gt; 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 </code></pre> <p>and saved this way:</p> <pre><code>Dim Crypter As New Cryptic(Key) 'open destination file Dim objWriter As New StreamWriter(fileName) 'write crypted content objWriter.Write(Crypter.Crypt(data)) </code></pre> <p>Now I have to reopen the file with Python but I have troubles getting <b>single bytes</b>, this is the XOR function in python:</p> <pre><code>def crypto(self, data): 'crypto(self, data) -&gt; str' return ''.join(chr((ord(x) ^ ord(y)) % 256) \ for (x, y) in izip(data.decode('utf-8'), cycle(self.key)) </code></pre> <p>I had to add the % 256 since sometimes x is > 256 i.e. <b>not a single byte</b>.</p> <p>This thing of two bytes being passed <b>does not break the decryption</b> because the key keeps "paired" with the following data.</p> <p>The problem is some decrypted character in the conversion is wrong. These chars are all accented letters like à, è, ì but <b>just a few of the overall accented letters</b>. The others are all correctly restored.</p> <p>I guess it could be due to the 256 mod but without it I of course get a chr exception...</p> <p>Thanks for your support</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload