EnCaSe and DeCaSe (hidden messages)

By raccoon on Sep 24, 2011

EncAse aND decaSE ARe TWO AliAs FUNCtiOnS THat AlLoW you to ENcOde ANd RevEAl MessagEs hiDDEN IN thE cAse cApITAlizaTION oF a stRing. sEnD messagES LiKe SpieS do! ;)

Read the code comments for detailed instructions and syntax.

Examples:
/encase Hello|The quick brown fox jumps over the lazy dog.
The QuicK BroWn FOX jUMps OVeR The LAzY DOG.
/decase The QuicK BroWn FOX jUMps OVeR The LAzY DOG.
Hello

They can also be used in scripts as $encase and $decase,
and there are a couple helper functions $encase_d and $encase_h
****to calculate the string length requirements for hiding messages.

****Enjoy.

****~ Raccoon (24-Sept-2011)

I wish I could find the aliases I wrote in 1998 or 1999 that did the same thing, but were like 50 lines of code each. :)

;# EnCaSe and DeCaSe by Raccoon 24-Sept-2011
;# These go in your Aliases.
;#
;# These functions allow you to encipher a string of text hidden inside another
;# string of text, as binary data encoded via capitalization.
;# 
;# For example:
;# 
;#   "The QuicK BroWn FOX jUMps OVeR The LAzY DOG."
;# 
;# contains the hidden message
;# 
;#   "Hello"
;# 
;# You can encode either 7-bit ASCII or 8-bit BINARY (eg, Unicode/UTF-8)
;# 
;# As a rule, each character of the hidden message you wish to encode must be
;# complimented by 7 or 8 letters from A-Z in the decoy output string.  The
;# decoy string may contain characters other than A-Z but they won't count
;# toward the required minimum length.
;# 
;# Syntax:
;# 
;# $encase(<Hidden Message>, <Decoy String>, [7 or 8])
;# $decase(<Encoded String>, [7 or 8])
;# 
;# You can also use them as /commands
;#
;# /encase Hidden Message|Decoy String|[7 or 8]
;# /decase Encoded String|[7 or 8]
;#
;# The last parameter '7' or '8' is optional and defaults to '7' bit ASCII.
;#
;# Remember, your decoy string must be at least 7 or 8 times as long as the
;# message you wish to hide, not counting spaces or punctuation.  I've
;# included some functions to help calculate these lengths.
;#
;# $encase_d(Decoy-String,[7|8])
;# Tells you how many characters a decoy string can hide.
;#
;# $encase_h(Hidden-Message,[7|8])
;# Tells you how many letters a hidden string requires from the decoy.
;# 
;# Written by Raccoon 24-Sept-2011

; Usage for EnCaSe.
; $encase(Hello,The quick brown fox jumps over the lazy dog.,[7|8])
; /encase Hello|The quick brown fox jumps over the lazy dog.
/encase {
  if !$isid { tokenize 124 $1- }
  var %hidden = $1
  var %shown = $lower($2)
  var %bitdepth = $iif($3 isnum 7-8,$3,7)
  var %bits = $regsubex(%hidden,/(.)/g,$right($base($asc(\1),10,2,%bitdepth),%bitdepth))
  var %output = $regsubex(%shown,/([a-z])/g,$iif($mid(%bits,\n,1),$upper(\1),\1))
  $iif($isid,return,editbox -a) %output
} ; by Raccoon 24-Sept-2011

; Usage for DeCaSe.
; $decase(The QuicK BroWn FOX jUMps OVeR The LAzY DOG.,[7|8])
; /decase The QuicK BroWn FOX jUMps OVeR The LAzY DOG.
/decase {
  if !$isid { tokenize 124 $1- }
  var %string = $regsubex($1,/([^a-zA-Z])/g,)
  var %bitdepth = $iif($2 isnum 7-8,$2,7)
  var %bits = $regsubex(%string,/([a-zA-Z])/g,$iif(\1 isupper,1,0))
  var %output = $regsubex(%bits,/([01]{ $+ %bitdepth $+ })/g,$chr($base(\1,2,10)))
  $iif($isid,return,editbox -a) %output
} ; by Raccoon 24-Sept-2011

; Tells you how many characters a decoy string can hide.
; $encase_d(Decoy-String,[7|8])
/encase_d {
  return $calc($regex($1,/[a-zA-Z]/g) / $iif($2 isnum 7-8,$2,7))
} ; by Raccoon 24-Sept-2011

; Tells you how many letters a hidden string requires from the decoy.
; $encase_h(Hidden-Message,[7|8])
/encase_h {
  return $calc($len($1) * $iif($2 isnum 7-8,$2,7))
} ; by Raccoon 24-Sept-2011

; end of snippet

Comments

Sign in to comment.
raccoon   -  Sep 25, 2011

Fixed a bug. Two instances of $!isid should have been !$isid.

 Respond  
raccoon   -  Sep 24, 2011

Indeed, thanks. Personally I've withdrawn from using the //i switch as a personal preference, as it can be easy to forget or accidentally tack-on at inopportune times. So I've disciplined myself to work with explicit case. Eg, you can see how I used $lower() in combination with /[a-z]/g, which reminds me that the entire string is already lowercase so I only need to use $upper in that $regsubex.

 Respond  
Jethro   -  Sep 24, 2011

Nice work again, raccoon. ^^

About thre regex:

/[a-zA-Z]/g

You can simply do it as

/[a-z]/ig

or

/(?i)[a-z]/g

the /i modifier will make them all case-insensitive.

Anyway, it doesn't affect the overall workability of your snippet. It's just a suggestion is all.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.