Created
May 14, 2023 15:58
-
-
Save MS-Jahan/d497b63c07f0cb7537b59428f31fbe26 to your computer and use it in GitHub Desktop.
StringFog decrypt using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
class StringFogImpl: | |
CHARSET_NAME_UTF_8 = "UTF-8" | |
@staticmethod | |
def decrypt(string): | |
return StringFogImpl().decrypt(string, StringFogImpl.CHARSET_NAME_UTF_8) | |
def encrypt(self, string, key): | |
try: | |
return base64.b64encode(self.xor(string.encode(StringFogImpl.CHARSET_NAME_UTF_8), key)).decode() | |
except UnicodeEncodeError: | |
return base64.b64encode(self.xor(string.encode(), key)).decode() | |
def decrypt(self, string, key): | |
try: | |
return self.xor(base64.b64decode(string), key).decode(StringFogImpl.CHARSET_NAME_UTF_8) | |
except UnicodeDecodeError: | |
return self.xor(base64.b64decode(string), key).decode() | |
@staticmethod | |
def overflow(string, key): | |
return string is not None and (len(string) * 4) / 3 >= 65535 | |
@staticmethod | |
def xor(byte_array, key): | |
length = len(byte_array) | |
key_length = len(key) | |
result = bytearray(length) | |
for i in range(length): | |
result[i] = byte_array[i] ^ ord(key[i % key_length]) | |
return bytes(result) | |
string_fog = StringFogImpl() | |
encrypted_string = string_fog.encrypt("Hello, World!", "encryption_key") | |
print("Encrypted:", encrypted_string) | |
decrypted_string = string_fog.decrypt(encrypted_string, "encryption_key") | |
print("Decrypted:", decrypted_string) | |
decrypted_string = string_fog.decrypt(encrypted_string, "UTF-8") | |
print("Decrypted:", decrypted_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment