chr encoder

By Patatje-oorlog on Jul 30, 2009

This snippet turns the input in a $chr string

example:
if the input is 'Hi Sam!'
the output will be: $+($chr(72),$chr(105),$chr(32),$chr(83),$chr(97),$chr(109),$chr(33))

if you wan't to get it in normal text again: //echo -at

Enjoy it

menu channel,status {
  - 
  CHR encoder:dialog -m chr chr
}
dialog chr {
  title "Text Encoder"
  size -1 -1 150 173
  option dbu
  tab "Encoder",1,1 0 149 172
  box "Input:", 2, 8 15 133 38,tab 1
  edit "",3,12 24 125 25,tab 1 center multi
  box "Output:", 4, 8 53 133 98,tab 1
  edit "",5,12 62 125 85,tab 1 center multi read
  button "Generate code!",6, 97 153 45 18,tab 1 disabled
  text "©Patatje-oorlog Designs" 100, 8 158 62 11,disabled
}
on *:dialog:chr:*:*:{
  if ($devent == init) {
    did -h $dname 5
  }
  if ($devent == edit) { 
    if ($did == 3) { if ($did(3) == $null) { did -b $dname 6 } | else { did -e $dname 6 } } 
  }
  if ($devent == sclick) {
    if ($did == 6) {
      did -r $dname 5
      did -v $dname 5
      set %i 1
      :start
      if (%i > $len($did(3))) { unset %i | goto end }
      if (%i == 1) { var %chr-encoder $+($chr(36),+,$chr(40),$chr(36),chr,$chr(40),$asc($left($mid($did(3),%i),1)),$chr(41)) | inc %i 1 | goto start }
      else { var %chr-encoder $+(%chr-encoder,$chr(44),$chr(36),chr,$chr(40),$asc($left($mid($did(3),%i),1)),$chr(41),$iif(%i == $len($did(3)),$chr(41))) | inc %i 1 | goto start }
      :end
      did -i $dname 5 1 %chr-encoder
      halt
    }
  }
}

Comments

Sign in to comment.
MaSOuD   -  Aug 04, 2009

As you wish dear... that was just a suggestion to make your code shorter and better.
And it never bothering you, because you just need to copy/paste the code that i wrote to your code. (If you won't be lazy, lol)

 Respond  
Jonesy44   -  Aug 03, 2009

You could always use regex..

; set string to %str
var %str = 
; convert each character to its ASCII value & add $chr() tags either side
return $regsubex(%str,/(.)/g,$+($,chr,$chr(40),$asc(\1),$chr(41),$chr(32),$iif(\n != \0,$!+),$chr(32)))

You could expand its usage further..

 Respond  
Patatje-oorlog   -  Aug 03, 2009

@ Atr:
I am still looking for a solution for that. I will update this script when i have the decode part done :P

@ MaSOuD:
Thx, i will add that later on (goto worked fine so i didn't bother to remake it with a while :P)

@ aitor1976]
I don't understand you lol, but i have a encoder that, if you type a number in the input field, the binairy code of this number will be outputted, i can post this script also if you wan't? xD

 Respond  
aitor1976   -  Jul 31, 2009

hy sorry,He(She) excuses podrias to put in binary code 001001110011 please
thank.

 Respond  
MaSOuD   -  Jul 30, 2009

Good work, but i suggesting you to use Loop instead of GOTO like this:

while (%i <= $len($did(3))) {
  if (%i == 1) { var %chr-encoder $+($chr(36),+,$chr(40),$chr(36),chr,$chr(40),$asc($left($mid($did(3),%i),1)),$chr(41)) }
  else { var %chr-encoder $+(%chr-encoder,$chr(44),$chr(36),chr,$chr(40),$asc($left($mid($did(3),%i),1)),$chr(41),$iif(%i == $len($did(3)),$chr(41))) }
  inc %i
}
 Respond  
Atr   -  Jul 30, 2009

That is a nice piece of work (now I can easily find out the chr codes, which is a hell of a lot easier!)

Thanks for this, good job.

Suggestion; maybe make something inside the dialog that turns it back? Rather than typing //echo -at

 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.