Last active
November 30, 2024 17:13
-
-
Save lastforkbender/fb37bc86e831b0f7848eedc3501e14ae to your computer and use it in GitHub Desktop.
XORT4 Alien Encryption/Decryption
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
| # "xort4.py" encryption/decryption for QOPAS24 signed blocks or as other; as needed | |
| import os | |
| import math | |
| class XORT4: | |
| slots = ("_xor_t4") | |
| def __init__(self): | |
| pass | |
| #_________________________________________________________________________________ | |
| class XORT4_QPAVGT(XORT4): | |
| slots = ('_key1', '_key2', '_kl1', '_txt') | |
| def __init__(self, key1, key2, txt): | |
| self._txt = txt | |
| self._key1 = key1 | |
| self._key2 = key2 | |
| self._kl1 = len(key1) | |
| #_________________________________________________________________________________ | |
| def xort4_pads(self, message, block_size): | |
| padding_length = block_size-(len(message)%block_size) | |
| padding = bytes([padding_length]*padding_length) | |
| return message+padding | |
| #_________________________________________________________________________________ | |
| def xort4_bytes(self, b1, b2) -> list: | |
| rtrn = None | |
| cnt = 0 | |
| while 1: | |
| rtrn = self.xort4_renown(b1, b2) | |
| if rtrn[0]: | |
| break | |
| cnt+=1 | |
| if cnt > 3: | |
| return [False] | |
| return rtrn | |
| #_________________________________________________________________________________ | |
| def xort4_renown(self, b1, b2) -> list: | |
| rslt = None | |
| rtrn = [True] | |
| try: | |
| rslt = bytes((r1^r2+int(math.cos(self._key2*2)))^(r3^r2+int(math.atan(self._key2))^(int(math.sqrt(r4^r1^r3^r2)))) for r1, r2, r3, r4 in zip(b1, b2, b2, b1)) | |
| except Exception as xort4_err_lhl_operand_or_err_bdr_256: | |
| print(xort4_err_lhl_operand_or_err_bdr_256) | |
| rtrn[0] = False | |
| if rtrn[0]: | |
| rtrn.append(rslt) | |
| return rtrn | |
| #_________________________________________________________________________________ | |
| def xort4_encrypt(self, f: int) -> bytes: | |
| i = None | |
| block = None | |
| encrypted_block = None | |
| while 1: | |
| iv = os.urandom(self._kl1) | |
| encrypted = iv | |
| previous_block = iv | |
| padded_message = self.xort4_pads(self._txt.encode('UTF-8'), int(self._kl1/f)) | |
| pml = len(padded_message) | |
| for i in range(0, pml, self._kl1): | |
| block = padded_message[i:i+int(self._kl1/f)] | |
| encrypted_block = self.xort4_bytes(self.xort4_bytes(block, previous_block), self._key1.encode('utf-8')) | |
| if encrypted_block[0]: | |
| encrypted += encrypted_block[1] | |
| previous_block = encrypted_block[1] | |
| else: | |
| break | |
| if i == self._kl1: | |
| break | |
| return encrypted | |
| #_________________________________________________________________________________ | |
| def xort4_decrypt(self, f: int) -> str: | |
| # No friends at dawn. | |
| i = None | |
| block = None | |
| decrypted_block = None | |
| iv = self._txt[:self._kl1] | |
| encrypted_message = self._txt[self._kl1:] | |
| eml = len(encrypted_message) | |
| while 1: | |
| previous_block = iv | |
| decrypted = bytearray() | |
| for i in range(0, eml, self._kl1): | |
| block = encrypted_message[i:i+self._kl1] | |
| decrypted_block = self.xort4_bytes(self.xort4_bytes(block, self._key1.encode('UTF-8')), previous_block) | |
| if decrypted_block[0]: | |
| decrypted.extend(decrypted_block[1]) | |
| previous_block = block | |
| else: | |
| break | |
| if i == self._kl1: | |
| break | |
| else: | |
| print(i) | |
| padding_length = decrypted[-1] | |
| return decrypted[:-padding_length].decode('UTF-8') | |
| #_________________________________________________________________________________ | |
| #_________________________________________________________________________________ | |
| def encrypt(key1: str, key2: int, f: int, plain_text: str) -> str: | |
| xpqx4 = XORT4_QPAVGT(key1, key2, plain_text) | |
| return xpqx4.xort4_encrypt(f) | |
| #_________________________________________________________________________________ | |
| #_________________________________________________________________________________ | |
| def decrypt(key1: str, key2: int, encrypted_text: bytes) -> str: | |
| xpqx4 = XORT4_QPAVGT(key1, key2, encrypted_text) | |
| return xpqx4.xort4_decrypt(f) | |
| #_________________________________________________________________________________ | |
| #_________________________________________________________________________________ | |
| #_________________________________________________________________________________ | |
| # EXAMPLE XOR-T4 ENCRYPTION | |
| #_________________________________________________________________________________ | |
| key1 = ['z4#X%55*2f5#42&T@Z56k7.G8s*3999&5v@38211%9852618Ma449T#32uQ%692832%418E', | |
| '5%389*38265*173S&4#2.7.8&S6195Y#2.9.bmX7I925R#2nN6119%3P67299Z291H*5195', | |
| 'E72B6*592?8419482639&3W5295.5#C432j&9438541#965&2kfsqi6&34#9275t@527&V3', | |
| 's7&38*48%3R28E319F42*72919483U%4.L5924418G.493eqnpd45?83.6DI8#319&5274C', | |
| '&8f38111?5X5628&r2mZ76c5f9*84D%'] | |
| key2 = 9376543010870294619043078396220838510858623730920061840735529635 | |
| mssg = ['Fear not a wise man, let him see your code of attention & kindness.', | |
| ' And if he become angered in blindness so shall it be their Wh0r3.', | |
| ' Let the Wall Street Babylon Wh0r3 sabotage herself a thousand', | |
| ' times more with crypto until all know she is the ugly Wh0r3.', | |
| ' BE NOT THE CORPORATE COWARD. LOVE NOT THIS WORLD. DISOBEY.'] | |
| xort4_encrypted_text = encrypt("".join(key1), key2, 4, ''.join(mssg)) | |
| print('\nXOR-T4 ENCRYPTED(bytes):\n') | |
| print(xort4_encrypted_text) | |
| #xort4_decrypted_text = decrypt("".join(key1), key2, 4, xort4_encrypted_text) | |
| #print('\nXOR-T4 DECRYPTED(string):\n') | |
| #print(xort4_decrypted_text) | |
| #_________________________________________________________________________________ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment