All pastes #71496 Raw Edit

Unnamed

public text v1 · immutable
#71496 ·published 2006-06-25 20:51 UTC
rendered paste body
alias encrypt {

  ;%x is set with the length of the text to be encrypted:
  var %x $len($1-)

  ;I used a while statement to loop all the encrypted letters into a variable:
  while (%x) {

    ;;The following is how I encrypted the letters:

    ;;%spcr is set with 1-3 random, non-numeric, characters:
    var %spcr $($str($!chr($r(58,126)) $!+ $chr(32),$r(1,3)),2)

    ;;%char is set with the %x'th letter and converted into ASCII.
    ;;This value is the divided by two and the decimal points are replaced with astericks:
    var %char = $replace($calc($asc($mid($1-,%x,1)) / 2),$chr(46),$chr(42))

    ;;This line combines everything above backwards, and adds it the the variable. 
    ;;The $iif adds a %spcr to the string on the last parse of the while statement:
    set %string $+(%string,%spcr,%char,$iif(%x == 1,%spcr,$null))

    ;;%x is decreased by 1 and the loop continues
    dec %x 1

  }

  ;The last two lines return the answer and unset the %string variable:
  echo -a %string
  unset %string

}

alias decrypt {

  ;%x is set with the length of the text to be decrypted.
  var %x $len($1-)

  ;I used a while loop to isolate the ASCII values:
  while (%x) {

    ;;%y and %z are set with the character and the next character for quick use below:
    var %y = $mid($1-,%x,1)
    var %z = $mid($1-,$calc(%x - 1),1)

    ;;An if statement checks if the current letter is a number or an asterick:
    if (%y isnum) || (%y == $chr(42))  { 

      ;;;If so, it adds the number to the variable %string, replacing the astericks with decimal points.
      ;;;The $iif checks if the next character is not a number.
      ;;;If it isn't a number, then a space is added to the variable:
      set %string $+($iif(%z !isnum && %z != $chr(42),$chr(32),$null),$replace(%y,$chr(42),$chr(46)),%string)

    }

    ;;%x is decreased by 1 and the loop continues:
    dec %x 1

  }

  ;%x is set with the number of tokens in %string
  var %x $numtok(%string,32)

  ;A final while statement is used to convert the ASCII numbers into text:
  while (%x) {

    ;;%fstring is set with the %x'th token converted from ASCII to plain text.
    ;;This is done backwards to make it readable:
    set %fstring $+(%fstring,$chr($calc($gettok(%string,%x,32) * 2)))

    ;;%x is decreased by 1 and the loop continues:
    dec %x 1

  }

  ;The last two lines return the answer and unset the %string and %fstring variables:
  echo -a %fstring
  unset %string 
  unset %fstring

}