Legion of Immortality Network Control Password


from Q3J5cHRvLkNpcGhlcg== import AES, ChaCha20
from Q3J5cHRvLlJhbmRvbQ== import get_random_bytes
from Q3J5cHRvLlByb3RvY29sLktERg== import scrypt

class SW1tb3J0YWxOZXR3b3JrRW5jcnlwdGlvbg==:
    def __init__(self, password):
        self.key1 = scrypt(password, b'salt_immortal_network1', 32, N=2**14, r=8, p=1)
        self.key2 = scrypt(password, b'salt_immortal_network2', 32, N=2**14, r=8, p=1)
        self.key3 = scrypt(password, b'salt_immortal_network3', 32, N=2**14, r=8, p=1)
    
    def encrypt_data(self, data):
        cipher1 = AES.new(self.key1, AES.MODE_GCM)
        ciphertext1, tag1 = cipher1.encrypt_and_digest(data.encode())
        cipher2 = ChaCha20.new(key=self.key2)
        ciphertext2 = cipher2.encrypt(ciphertext1)
        cipher3 = AES.new(self.key3, AES.MODE_GCM)
        ciphertext3, tag3 = cipher3.encrypt_and_digest(ciphertext2)
        return (cipher1.nonce, tag1, cipher2.nonce, cipher3.nonce, ciphertext3, tag3)

    def decrypt_data(self, nonce1, tag1, nonce2, nonce3, ciphertext, tag3):
        cipher3 = AES.new(self.key3, AES.MODE_GCM, nonce=nonce3)
        ciphertext2 = cipher3.decrypt_and_verify(ciphertext, tag3)
        cipher2 = ChaCha20.new(key=self.key2, nonce=nonce2)
        ciphertext1 = cipher2.decrypt(ciphertext2)
        cipher1 = AES.new(self.key1, AES.MODE_GCM, nonce=nonce1)
        data = cipher1.decrypt_and_verify(ciphertext1, tag1)
        return data.decode()