ciphers.xor_cipher ================== .. py:module:: ciphers.xor_cipher .. autoapi-nested-parse:: author: Christian Bender date: 21.12.2017 class: XORCipher This class implements the XOR-cipher algorithm and provides some useful methods for encrypting and decrypting strings and files. Overview about methods - encrypt : list of char - decrypt : list of char - encrypt_string : str - decrypt_string : str - encrypt_file : boolean - decrypt_file : boolean Classes ------- .. autoapisummary:: ciphers.xor_cipher.XORCipher Module Contents --------------- .. py:class:: XORCipher(key: int = 0) .. py:method:: decrypt(content: str, key: int) -> list[str] input: 'content' of type list and 'key' of type int output: decrypted string 'content' as a list of chars if key not passed the method uses the key by the constructor. otherwise key = 1 Empty list >>> XORCipher().decrypt("", 5) [] One key >>> XORCipher().decrypt("hallo welt", 1) ['i', '`', 'm', 'm', 'n', '!', 'v', 'd', 'm', 'u'] Normal key >>> XORCipher().decrypt("HALLO WELT", 32) ['h', 'a', 'l', 'l', 'o', '\x00', 'w', 'e', 'l', 't'] Key greater than 255 >>> XORCipher().decrypt("hallo welt", 256) ['h', 'a', 'l', 'l', 'o', ' ', 'w', 'e', 'l', 't'] .. py:method:: decrypt_file(file: str, key: int) -> bool input: filename (str) and a key (int) output: returns true if decrypt process was successful otherwise false if key not passed the method uses the key by the constructor. otherwise key = 1 .. py:method:: decrypt_string(content: str, key: int = 0) -> str input: 'content' of type string and 'key' of type int output: decrypted string 'content' if key not passed the method uses the key by the constructor. otherwise key = 1 Empty list >>> XORCipher().decrypt_string("", 5) '' One key >>> XORCipher().decrypt_string("hallo welt", 1) 'i`mmn!vdmu' Normal key >>> XORCipher().decrypt_string("HALLO WELT", 32) 'hallo\x00welt' Key greater than 255 >>> XORCipher().decrypt_string("hallo welt", 256) 'hallo welt' .. py:method:: encrypt(content: str, key: int) -> list[str] input: 'content' of type string and 'key' of type int output: encrypted string 'content' as a list of chars if key not passed the method uses the key by the constructor. otherwise key = 1 Empty list >>> XORCipher().encrypt("", 5) [] One key >>> XORCipher().encrypt("hallo welt", 1) ['i', '`', 'm', 'm', 'n', '!', 'v', 'd', 'm', 'u'] Normal key >>> XORCipher().encrypt("HALLO WELT", 32) ['h', 'a', 'l', 'l', 'o', '\x00', 'w', 'e', 'l', 't'] Key greater than 255 >>> XORCipher().encrypt("hallo welt", 256) ['h', 'a', 'l', 'l', 'o', ' ', 'w', 'e', 'l', 't'] .. py:method:: encrypt_file(file: str, key: int = 0) -> bool input: filename (str) and a key (int) output: returns true if encrypt process was successful otherwise false if key not passed the method uses the key by the constructor. otherwise key = 1 .. py:method:: encrypt_string(content: str, key: int = 0) -> str input: 'content' of type string and 'key' of type int output: encrypted string 'content' if key not passed the method uses the key by the constructor. otherwise key = 1 Empty list >>> XORCipher().encrypt_string("", 5) '' One key >>> XORCipher().encrypt_string("hallo welt", 1) 'i`mmn!vdmu' Normal key >>> XORCipher().encrypt_string("HALLO WELT", 32) 'hallo\x00welt' Key greater than 255 >>> XORCipher().encrypt_string("hallo welt", 256) 'hallo welt' .. py:attribute:: __key :value: 0