alias encrypt {
;%t is set with the text to be encrypted, replacing spaces with a plus sign:
var %t = $replace($1-,$chr(32),$chr(43))
;%x is set with the length of the text to be encrypted:
var %x = $len(%t)
;A while loop is used to loop all the encrypted letters into a variable:
while (%x) {
;;%spcr is set with 1-3 random, non-numeric, characters.
;;This acts as a seperator for the ASCII values:
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 ASCII value is the divided by 2.5 and the decimal points are replaced with apostrophes:
var %char = $replace($calc($asc($mid(%t,%x,1)) / 2.5),$chr(46),$chr(39))
;;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:
var %string = $+(%string,%spcr,%char,$iif(%x == 1,%spcr,$null))
;;%x is decreased by 1 and the loop continues
dec %x 1
}
;The last line returns the answer:
return %string
}
alias decrypt {
;%x is set with the length of the text to be decrypted.
var %x = $len($1-)
;A while loop is used 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(39)) {
;;;If so, it adds the number to the variable %string, replacing the apostrophes with decimal points.
;;;The $iif checks if the next character is not a number or an apostrophe.
;;;If it isn't a number, then a space is added to the variable:
var %string = $+($iif(%z !isnum && %z != $chr(39),$chr(32),$null),$replace(%y,$chr(39),$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 values into text:
while (%x) {
;;%fstring is set with the %x'th token, multiplied by two, and converted from ASCII to text.
;;This is done backwards to make it readable:
var %fstring = $+(%fstring,$chr($calc($gettok(%string,%x,32) * 2.5)))
;;%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:
return $replace(%fstring,$chr(43),$chr(32))
}