Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ Compression, encryption, encoding and the reverse ...
Compression, encryption, encoding and the reverse ...
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Thu 09 Dec 2004 03:40 AM (UTC) Amended on Thu 09 Dec 2004 03:47 AM (UTC) by Nick Gammon
|
Message
| Putting it all together now, we can make a simple function that is handy for sending encrypted messages to friends.
function compress_encrypt_encode (s, k)
return utils.base64encode (aes.encrypt (utils.compress (s), k), true)
end -- compress_encrypt_encode
function decode_decrypt_decompress (s, k)
return utils.decompress (aes.decrypt (utils.base64decode (s), k))
end -- decode_decrypt_decompress
The function compress_encrypt_encode:
- Compresses the text you supply
- Encrypts it with the supplied key
- Base-64 encodes it, suitable for putting in an email or "tell" or similar (change "true" to "false" if you want a single-line rather than breaking every 76 columns)
Example:
print (compress_encrypt_encode (
[[
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
]], "swordfish"))
Output
D4TNSdaDQhfnozmTc8bm9atmofRB+sxmJTUnThGMAvPnKjAPYX+jCJ08cB+uAynt5kX97hHiDma5
EQm14twOsY4hIylmQYtcquZjgCWCu2/sN/lumDYa6IDJiVr+7OI3ajsqR5TPK1BPHe4SrdTt1ntj
XnkDA6GmAI6DJQ7tprRfRZKqO8czeC1dju/dktvlHFZSrmj06HfIsaXyVwwMxFGMMR/RcjyC9Zwq
x3qRLx/vOt1rIbApY4CyNRP+AmfU346sOkG90Yh5OO9DnUU6M+gliRlplQ6+DGdoLe61+tQwaXQj
YOm9v2Qw+PnYLGiyv/ElrKo1n9+tGuD8fCDHMJOHizUrGCBloQMVoVG3h9hlgWJPMBHmxSwn3Go2
wjgFV9SWpznXkngXSt1F5YPgkA==
The function decode_decrypt_decompress:
- Decodes the base-64 encoded text
- Decrypts it with the supplied key
- Decompresses it
Example (using above results as input):
/print (decode_decrypt_decompress ([[
D4TNSdaDQhfnozmTc8bm9atmofRB+sxmJTUnThGMAvPnKjAPYX+jCJ08cB+uAynt5kX97hHiDma5
EQm14twOsY4hIylmQYtcquZjgCWCu2/sN/lumDYa6IDJiVr+7OI3ajsqR5TPK1BPHe4SrdTt1ntj
XnkDA6GmAI6DJQ7tprRfRZKqO8czeC1dju/dktvlHFZSrmj06HfIsaXyVwwMxFGMMR/RcjyC9Zwq
x3qRLx/vOt1rIbApY4CyNRP+AmfU346sOkG90Yh5OO9DnUU6M+gliRlplQ6+DGdoLe61+tQwaXQj
YOm9v2Qw+PnYLGiyv/ElrKo1n9+tGuD8fCDHMJOHizUrGCBloQMVoVG3h9hlgWJPMBHmxSwn3Go2
wjgFV9SWpznXkngXSt1F5YPgkA==
]], "swordfish"))
Output
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #1 on Thu 09 Dec 2004 03:42 AM (UTC) |
Message
| This is where Lua's multi-line quotes [[ and ]] come into handy. You can just use those and copy and paste swags of text inbetween them. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
8,128 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top