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

Method encrypt

XORcipher/XOR_cipher.py:31–54  ·  view source on GitHub ↗

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

(self, content, key)

Source from the content-addressed store, hash-verified

29 self.__key = key
30
31 def encrypt(self, content, key):
32 """
33 input: 'content' of type string and 'key' of type int
34 output: encrypted string 'content' as a list of chars
35 if key not passed the method uses the key by the constructor.
36 otherwise key = 1
37 """
38
39 # precondition
40 assert isinstance(key, int) and isinstance(content, str)
41
42 key = key or self.__key or 1
43
44 # make sure key can be any size
45 while key > 255:
46 key -= 255
47
48 # This will be returned
49 ans = []
50
51 for ch in content:
52 ans.append(chr(ord(ch) ^ key))
53
54 return ans
55
56 def decrypt(self, content, key):
57 """

Callers 1

test_encryptMethod · 0.80

Calls 1

appendMethod · 0.45

Tested by 1

test_encryptMethod · 0.64