English 中文(简体)
每一次XOR脱硫
原标题:Python byte per byte XOR decryption

我有一份由VB编辑的文件。 利用这一功能实施的净方案可产生以下影响:

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

并节省了这种方式:

Dim Crypter As New Cryptic(Key)
 open destination file
Dim objWriter As New StreamWriter(fileName)
 write crypted content
objWriter.Write(Crypter.Crypt(data))

现在,我不得不重开卷宗,但我有麻烦,要到single bytes,这是XOR在座的:

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))

我不得不增加256 %,因为有时x是“ &”;256,即:不是“灵丹”的单一产品。

两条经母体通过后,不会打破加密,因为钥匙将“搁置”与以下数据相连接。

The problem is some decrypted character in the conversion is wrong. These chars are all accented letters like à, è, ì but just a few of the overall accented letters. The others are all correctly restored.

我猜测,这可能是由于256次暴动造成的,但我当然没有例外。

感谢您的支持

最佳回答

事实上,以下几行是错误的:

Return Encoding.Default.GetString(Crypt(Encoding.Default.GetBytes(Data)))

没有任何一般性保障,即从Crypt中转回的 by,可作为体码。 你们最好利用Convert。 ToBase64String, 并随后通过 string to世袭代码(显然,你需要能够将斜体编码为基-64。

正如其他人指出的,安全观所提供的水平足以保护你的数据,使之免受你很少的姐妹的影响。

问题回答

你的编码数据似乎含有价值超过256的单编码特性。 载于。 只能处理256岁以下数值。 http://docs.python.org/library/Functions.html#unichr”rel=“nofollow noreferer”>unichr,而不是chr

return   .join(unichr((ord(x) ^ ord(y))) 
    for (x, y) in izip(data.decode( utf-8 ), cycle(self.key))

is it correct to save scrambled data as string (i.e. re-encoded with default encoding) with StreamWriter? Wouldn t be correct to save bytes directly? Or is it the same thing?

Dim objWriter As New StreamWriter(fileName)
objWriter.Write(Crypter.Crypt(data))

哪一个水泥厂。 页: 1 书写

......

Public Function Crypt(ByVal Data() As Byte) As Byte()

还是这样?

Public Function Crypt(ByVal Data As String) As String

I m 不与Vb.net......


我这样做是为了了解右翼/强型“2”转换所涉及的果园。

for (x, y) in izip(data.decode( utf-8 ), cycle(self.key.decode( utf-8 ))):
    if (ord(x) ^ ord(y)) > 255 or chr(ord(x) ^ ord(y)) ==  xb2 :
        print (x, y, chr((ord(x) ^ ord(y)) % 256),
               unichr(ord(x) ^ ord(y)), ord(x), ord(y))

我这样做:

ù K ² ² 249 75
 p ² ² 194 112
Æ t ² ² 198 116
‚ 0 * ‪ 8218 48

最后一点是错误的,因为使用双轨制......但如果仅仅通过一条,则加密的其余部分将产生-th of phase

如果你以文字方式重新打开档案,可以将其解释为统法协会编码文本。 以双轨方式打开,使所有特性都成为 by。 这应避免使用<代码>chr的问题。 如果你重新使用3.x,你确实记得,当以双轨方式工作时,你应当使用字面字,而不是打上字面,后者是统法协会通过设计划定的字面。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...