> For the complete documentation index, see [llms.txt](https://low-caps-hub.gitbook.io/lowcapshubterminal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://low-caps-hub.gitbook.io/lowcapshubterminal/encryption-section/encryption-converter.md).

# Encryption converter

User can change state of wallet encryption in any moment. We have built-in converter from .dat to .txt and opposite. The mechanism doesn't requier special skills. Program opens "C:\Low Caps Hub Terminal" and adjustes searching for .dat or .txt files, according to your choice.

<figure><img src="/files/0g9VsXDMqgWtXKErMFTD" alt=""><figcaption></figcaption></figure>

**.txt to .dat**

If you decide to encrypt your wallet, you need to set the encryption key. Just after that, your .txt file will be replaced by .dat.

```python
def encrypt_txt_to_dat(self):
    directory = "C:\\Low Caps Hub Terminal"
    if os.path.exists(directory):
        filepath = filedialog.askopenfilename(
            title="Select .txt Wallet File",
            filetypes=[("Text Files", "*.txt")],
            initialdir=directory
        )
    else:
        self.show_message("Create/Import wallet first.", "Error")
        return

    if not filepath:
        return
    with open(filepath, 'r') as file:
        wallet_data = file.read()
    passphrase, dont_encrypt = self.prompt_for_passphrase("Encrypt Wallet", allow_no_encrypt=True)
    if dont_encrypt:
        self.show_message("Encryption canceled. Wallet remains unencrypted.", "Info")
        return
    if not passphrase:
        self.show_message("Passphrase is required to encrypt the wallet.", "Error")
        return
    encrypted_data = encrypt_data(wallet_data.encode('utf-8'), passphrase)
    encrypted_filepath = filepath.replace('.txt', '.dat')
    with open(encrypted_filepath, 'wb') as file:
        file.write(encrypted_data)
    self.show_message(f"Encrypted wallet saved to {encrypted_filepath}", "Encryption Successful")
    os.remove(filepath)
```

\
\&#xNAN;**.dat to .txt**

If you would like do decrypt your wallet, you can do it. Of course during it, you need to enter your key/password as well.

```python
def decrypt_dat_to_txt(self):
    directory = "C:\\Low Caps Hub Terminal"
    if os.path.exists(directory):
        filepath = filedialog.askopenfilename(
            title="Select .dat Wallet File",
            filetypes=[("DAT Files", "*.dat")],
            initialdir=directory
        )
    else:
        self.show_message("Create/Import wallet first.", "Error")
        return

    if not filepath:
        return
    passphrase, _ = self.prompt_for_passphrase("Decrypt Wallet", allow_no_encrypt=False)
    if not passphrase:
        self.show_message("Passphrase is required to decrypt the wallet.", "Error")
        return
    with open(filepath, 'rb') as file:
        encrypted_data = file.read()
    decrypted_data = decrypt_data(encrypted_data, passphrase)
    if decrypted_data is None:
        self.show_message("Failed to decrypt the wallet. Incorrect passphrase or corrupted file.", "Error")
        return
    decrypted_filepath = filepath.replace('.dat', '.txt')
    with open(decrypted_filepath, 'w') as file:
        file.write(decrypted_data.decode('utf-8'))
    self.show_message(f"Decrypted wallet saved to {decrypted_filepath}", "Decryption Successful")
    os.remove(filepath)
```
