Maroonbells (talk | contribs) (Add'l content and examples) |
Maroonbells (talk | contribs) m |
||
Line 79: | Line 79: | ||
; sends only to channel mask, allows not-encrypted if input is $inpaste or $ctrlenter or begins with / | ; sends only to channel mask, allows not-encrypted if input is $inpaste or $ctrlenter or begins with / | ||
; min length 1 flag + 8 salt + 8-byte-block * 4/3 = 21 | ; min length 1 flag + 8 salt + 8-byte-block * 4/3 = 21 | ||
− | + | ON *:text:=*:#: { if (($2 != $null) || ($len($1) < 21)) return | secret_chat $1 } | |
− | ON &*:INPUT:#channel1,#channel2:{ if (($ctrlenter) || ($inpaste) || ( | + | ON &*:INPUT:#channel1,#channel2:{ if (($ctrlenter) || ($inpaste) || ($left($1,1))) return | secret_chat $1- | halt } |
alias secret_chat { | alias secret_chat { |
Revision as of 03:17, 8 December 2017
The $encode identifier allows you to encode literal text, or text in %vars or &binvars. The $encode identifier uses either Uuencode or MIME or Base32 to encode. Additionally $encode is capable of utilizing Blowfish for encryption.
Synopsis
; encoding $encode(text/%var/&binvar [, btuma] [, N] ) ; encryption $encode(text/%var/&binvar, celsirznp, key[, salt/iv if s|i|r used] [,N] )
Parameters
Encoding
text/%var/&binvar The target to be encoded
b Target is a &binvar
t Target is text (this is default target type)
u Target should be encoded using Uuencode (this is default encode type)
m Target should be encoded using Mime (base64)
a Target should be encoded using Base32
N Integer Reference index for the Nth chunk (can't use without at least 1 switch)
- 'b' prevents target handled as if it's text beginning with '&'
- 'm' and 'u' encode 3 bytes into 4 printable characters, with u also prepending a length byte before each chunk of 60 encoded characters. 'a' encodes 5 bytes into 8 printable characters.
- If N is present, 0 returns number of chunks in the output, N=1+ returns the Nth encoded chunk of the output or $null if N is greater than the N=0 value. N allows handling encoded output output of &binary strings too long to fit into %variables.
- Chunks for 'u' are length 61 including the length byte. 'a' chunks contain 7.5 groups of 5-into-8, so $decode chunks created by 'a' in pairs to prevent corrupted data. Total output length is padded to be multiples of those groups of 4 or 8 printable characters plus the 'u' chunk length byte.
Encryption
c CBC encryption mode (either c or e)
e ECB encryption mode (either c or e)
l Literal key, a 56-byte key
s user defined 8-byte salt - Adds 16-byte header: RandomIV $+ Parameter#4
i user defined 8-byte (IV) initialization vector (used only by 'c')
r random IV (used only by 'c')
z zero padding
n ones and zeros
p spaces padding
Notes:
- 'N' parameter uses same rules as non-encryption. Optional last parameter after those required by presence of other switches ('ec' require <key>, 'si' require <salt|iv>)
- 'e' ignores 'sir', same key always encrypts identical groups of 8 plaintext bytes into the same 8 ciphertext bytes.
- 'c' default random salt allows same key to create different session-key each time salt differs.
- Salt/IV parameter *must* be 8 characters
- Default encryption has 16-byte header: Salted__ $+ 8-random-bytes
- any of s|i|r disables default salt, and s|i require presence of 4th parameter
- 's' changes header to: Salted__ $+ Parameter#4 that's used in place of default
- 'r' changes header to: RandomIV $+ 8-random-bytes
- 'ir' changes header to: RandomIV $+ Parameter#4
- 'i' removes header without including IV in message
- Even with fixed IV and no salt, same key creates identical ciphertext only to the point where 2 inputs differ.
Padding ensures encryption sees message length as exact multiple of 8 and is removed by $decode:
- default if 'npz' not used: Append N=1-8 of $chr(N) i.e. 1 $chr(1) thru 8 $chr(8)'s
- 'n' Appends 1-8 bytes: $chr(128) followed by 0-7 $chr(0)'s
- 'p' Appends 1-7 $chr(32) spaces
- 'z' Appends 1-7 $chr(0)
- Don't use 'z' or 'p' if target plaintext can end with $chr(0)'s or spaces. $decode assumes all padding characters in last 8-byte block are padding characters, potentially shortening the target.
Bugs: 1) 'l' enforces 56 length 'key' but encryption uses $utfencode(key) instead. 2) 'e' doesn't enforce max allowed $utfencode(key) length of 56. 3) 'b' generates false "line too long" error for several short 'target' lengths ('bu' = 1-6,8-10,16 'bu'=1-4,8-10,16 'ba'=1-20,24-28,32-36,40,48.
Example
Echo to the active screen the following encode text, using the Mime type:
//echo -a $encode(Hello there! This will be encoded using Mime.,m)
$encode encrypts the file then applies u/m/a coding to change binary output to text. Decoding with matching u/m/a displays the header and cipher binary hidden beneath //var %a $encode(text,csm,key,ParmSalt) | echo -a %a -> $decode(%a,m)
; Simple encrypted channel chat: ; 100% of security comes from %key because everyone knows %salt and $me and $chan ; message format: 1 flag + 8 salt + * message ; reacts only to channel messages containing only 1 word beginning with = ; sends only to channel mask, allows not-encrypted if input is $inpaste or $ctrlenter or begins with / ; min length 1 flag + 8 salt + 8-byte-block * 4/3 = 21 ON *:text:=*:#: { if (($2 != $null) || ($len($1) < 21)) return | secret_chat $1 } ON &*:INPUT:#channel1,#channel2:{ if (($ctrlenter) || ($inpaste) || ($left($1,1))) return | secret_chat $1- | halt } alias secret_chat { var %key Change this Shared Secret var %session_key $sha1($iif($event == text,$nick,$me) %key $chan) if ($event == text) { var %salt $mid($1,2,8) | var %text $decode($mid($1,10),cim,%session_key,%salt) echo -tcg normal # Decoded $+(<,$nick,>,:) %text } else { var %salt $regsubex($str(x,8),/x/g,$r(!,~)) | var %text $encode($1-,cim,%session_key,%salt) var %msg $+(=,%salt,%text) | msg # %msg | echo 3 -tg # Channel sees Encryption of: $1- } }
Compatibility
Added: mIRC v5.8
Added on: 05 Sep 2000
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.