Thursday, 15 July 2010

python - Cipher program losing accuracy -


I have a program in Python that takes two strings is a plain text string, the second is a cipher key. Goes on each character and gives bits with cipher characters, but when going back and forth then some letters do not change properly. Bin string length 8DEP bitstrings (N): bin_string = bin (n) [2:] bin_string = ("0" * (8 - bin_string)) + bin_string returns bin_string // xors bits bit bit (x, B1, B1): Nb = "" x for the border (minimum), lane (b1)): nb + = "0" if b 0 [x] == b1 [x] and "1 "Return takes NB / 2 2 characters, turns them into bin string, does excerpts, then returns the new Charge Def Cipher Cher (C, C1): return chr (bit (bitstrings (ord (c0)) , BitString (ord (c1))), 2)) // takes s0 (plain text) and cipher Angy (S1) encrypts it using the Def cipher string (S, S1): Border (Lane (s)) in x for NS = "": ns + = cybercari (s [x], S1 [x% lanon (s1)] back ns

For example, sometimes in a long string, the word 'test' will be written back to 'east', and Content

I checked the code twelve times and I do not know whether to change the character, is it possible that some letters are amazing Behave in a manner?

Edit:

Example:

  This is an exam because of some of the symbols in the previous exam:! @ # $% ^ & Amp; * () Does not change correctly I'm using EED  

Cipher key: 'cipher key'

to return the translation:

  This is a test because some signs in the previous mold:! @ # $% ^ & Amp; * () I am retestiig at the end I have not changed properly  

Sorry, It's a bit messy, I keep it real quick together

, sis import def bit_string (string) from version_info unhexlify: if version_info & gt; = (3, 0): Return bin (Intkfrom_bytes (Stringkencode (), "large")) and return bin (integer (Hexlify (string), 16)) bitXOR_encrypt (plain_text, key) def: Encrypted_list = [] range J (2, lane (Plain_text)) for: encrypted_list.append (integer (Plain_text [j]) ^ et (key [j]) # key and decrypt string back Ankripted_link Diiarti of the same length (Sifr_tekst, Key) are: decrypted_list = [] range in Jammu (2, lane (cipher_text)): #or xrange decrypted_list.append (integer (cipher_text [j]) ^ integer (quad [J])) str to #Again value keys taken [decrypted_list I (i)] string is the same length as decrypted_list = add_binary = "0b" + "" .join (decrypted_list) decrypted_string = int (add_binary, 2) If version_info & gt; = (3, 0): message = decrypted_string.to_bytes ((decrypted_string.bit_length () + 7) // 8, 'large') .decode () and message = unhexlify ( '% x '% decrypted_string) return message def main (): plain_text = "hello" plain_text_to_bits bit_string = (plain_text) key_to_bits = bit_string ( "candy") #Encrypt cipher_text = bitXOR_encrypt (strings Sifr_teks_string = "". Add (for i in Sigfr_tekst [str (i)) key_string = "" .join ([str (i) #Decrypt decrypted_string =]) for key_to_bits I decrypt ( "0B", cipher_text_string key_string) print ( "plain text :% S "+% plain_text" print ("plain text bits:% s"% plain_text_to_bits) print (("decrypted string:% s"% decrypted_string) main ()

"% S "For more details or example codes, you can go to your repository or even on github

In addition to this, I know that in this example the key is similar to the string If you want to use less string than string, try wrapping it in vigenere cipher (/ Vigenère_cipher)


No comments:

Post a Comment