[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Compression, encryption, encoding and the reverse ...
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Compression, encryption, encoding and the reverse ...

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,321 posts)  [Biography] 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
[Go to top] 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.


2,659 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]