MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / decrypt_string

Method decrypt_string

ciphers/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
132 def encrypt_file(self, file, key = 0):

Callers 1

decrypt_fileMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected