-
-
Notifications
You must be signed in to change notification settings - Fork 0
page 3
with the Custom_vr.py script The code imports the necessary modules for creating a graphical user interface (GUI) using the Tkinter library, encrypting and decrypting data using the AES algorithm from the PyCryptodome library, and compressing and decompressing data using the zlib library.
The key for encrypting and decrypting data is defined as "KEY" with a byte string value of "mysecretpassword". Note that in a real-world scenario, you should never hardcode your encryption key in your code. but for this instance the key does not matter as the format will probably be signed like the .NBS counterparts
There are two functions defined in the code: "save_file()" and "load_file()".
The "save_file()" function retrieves the text entered into an input field, compresses it using the zlib library, encrypts the compressed data using the AES algorithm, and then writes the encrypted data to a file selected by the user using the file dialog box. The file is saved with a ".vr" extension to indicate that it contains encrypted data.
The "load_file()" function prompts the user to select a file with the ".vr" extension, reads the encrypted data from the file, and then decrypts and decompresses the data using the AES and zlib libraries, respectively. The decrypted and decompressed data is then displayed in a text field.
Finally, the code creates a Tkinter window with an input field, two Buttons to save and load files, and an output text field to display the decrypted data.
you can modify this script to work with anything you want so long as you keep the encryption key the same and have it work with the same header data
with the saveloadd.py script
The code imports the necessary modules for packing and unpacking binary data using the struct library, generating hash digests using the hashlib library, encoding and decoding data using the base64 library, and encrypting and decrypting data using the AES algorithm from the PyCryptodome library.
The code defines four functions: "pad()", "unpad()", "encrypt()", and "decrypt()".
The "pad()" function pads the input data with bytes to ensure that it is a multiple of the AES block size. The padding is calculated by subtracting the length of the input data from the block size, and then appending that number of bytes with the same value as the padding to the end of the data.
The "unpad()" function removes the padding added by the "pad()" function. It first checks the value of the last byte of the input data to determine the number of padding bytes, and then removes that number of bytes from the end of the data.
The "encrypt()" function encrypts the input data using the AES algorithm in Cipher Block Chaining (CBC) mode. The data is padded using the "pad()" function, and an initialization vector (IV) is generated by taking the SHA-256 hash digest of the encryption key and selecting the first 16 bytes. The encrypted data is returned in Base64-encoded format, with the IV appended to the beginning.
The "decrypt()" function decrypts the Base64-encoded input data using the AES algorithm in CBC mode. The IV is extracted from the first 16 bytes of the input data, and the remaining data is decrypted using the specified encryption key and IV. The padding is then removed using the "unpad()" function, and the decrypted data is returned as a byte string.
The code also defines two additional functions: "save_data()" and "load_data()".
The "save_data()" function takes a filename, data, and key as input. It encrypts the data using the "encrypt()" function, writes the length of the encrypted data to the beginning of the file in little-endian byte order, and then writes the encrypted data to the file.
The "load_data()" function takes a filename and key as input. It reads the length of the encrypted data from the beginning of the file, reads the encrypted data from the file, decrypts the data using the "decrypt()" function, and returns the decrypted data as a string.
you can modify this script to work with anything you want so long as you keep the encryption key the same and have it work with the same header data
this script is licenced under the MIT License
Copyright (c) 2023 charlie-sans
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.