MCPcopy Create free account
hub / github.com/geekcomputers/Python / decrypt_string

Method decrypt_string

XORcipher/XOR_cipher.py:106–129  ·  view source on GitHub ↗

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

(self, content, key=0)

Source from the content-addressed store, hash-verified

104 return ans
105
106 def decrypt_string(self, content, key=0):
107 """
108 input: 'content' of type string and 'key' of type int
109 output: decrypted string 'content'
110 if key not passed the method uses the key by the constructor.
111 otherwise key = 1
112 """
113
114 # precondition
115 assert isinstance(key, int) and isinstance(content, str)
116
117 key = key or self.__key or 1
118
119 # make sure key can be any size
120 while key > 255:
121 key -= 255
122
123 # This will be returned
124 ans = ""
125
126 for ch in content:
127 ans += chr(ord(ch) ^ key)
128
129 return ans
130
131 def encrypt_file(self, file, key=0):
132 """

Callers 3

decrypt_fileMethod · 0.95
test_decrypt_stringMethod · 0.80
test_decrypt_fileMethod · 0.80

Calls

no outgoing calls

Tested by 2

test_decrypt_stringMethod · 0.64
test_decrypt_fileMethod · 0.64