GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
#!/usr/bin/lua
text = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/"
for i = 1,text:len() do
if ((i % 2) == 1) then
if (text:byte(i) ~= 32) then
a = string.char(text:byte(i) - 1)
else
a = " "
end
else
a = string.sub(text, i, i)
end
io.write(a)
end
io.write("\n")
or (this one doesn't handle that last pesky character)
Code:
#!/usr/bin/lua
text = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/"
dec = string.gsub(text, '(.)(.)',
function(x,y)
a = string.char(x:byte(1)-1)
if (a < " ") then
a = " "
end
return a..y
end)
print (dec)
Last edited by estabroo; 09-14-2009 at 10:25 AM.
Reason: removed extraneous line
Here it is in Fortran. Just for fun, I decided to adhere to the conventions of FORTRAN 66, so this program doesn't use any structured progamming facilities, and everything is upper case. Note that it not only has GOTO statements, it uses one computed GOTO as well, which is in the logic where I decide whether or not to subtract from the character value.
And note that, Fortran being Fortran, I CANNOT subtract from the character value. I have to only subtract from an integer value. We don't do casts in Fortran, we do equivalences which specifies the exact same storage for two variable entities. So note how I use equivalences here to equate a char and an int. Also note how I use equivalence to handle a 205 char string as an array of 205 chars.
Of course, with Fortran, executable statements must begin in column 7 or greater and be finished by column 72, line labels must be in columns 1 through 5, and column 6 is reserved for line continuations. Note how I had to break up the input data to make all this work.
Ah, Fortran! Sure brings back memories of the good ol' days, when Men were Men and computers filled buildings!
's/./&\n/g'
Puts each character on a separate line.
'1~2 y/$chars\a/ $chars/'
Uses the 'y' command to translate the character on each odd numbered line, '1~2'.
The non-printing 'bel' character '\a' is used just to make both sides of the 'y' command have the same number of characters.
H
Appends each line into the hold space.
$ {g;s/\n//g;p}
At the last line the hold space replaces the pattern space, all the newlines are removed, and the result is printed.
This uses 'grep' to put in the newlines and 'tr' to take them out.
Yeek! I think you'll be waiting a while -- though I'm willing to give it a try. I haven't got my full install done yet (Slack13-64) as I'm still awaiting my new shiny DVD, so I don't knwo if I even *have* lisp here -- AND I haven't got a clue about anything lisp. Time to start reading
UPDATE: I've been looking at Emacs Lisp for this. It appears to be perfectly suited to the task, but despite my continued perusing of "Emacs Lisp Basics" tutorials, I have not yet figured out where to start. Still working on it.
Meanwhile, I'm gonna take a shot at either an awk script, or an elegantly simple sed process. Wish me luck.
Sasha
Last edited by GrapefruiTgirl; 09-15-2009 at 08:08 PM.
A cleaner version of the python one, its kind of funny I used that .? regex in the perl script but it never occurred to me to use it in the lua or python.
Code:
#!/usr/bin/python
import re
def decode(m):
a = m.group(1)
if (a != " "):
a = chr(ord(a)-1)
return a + m.group(2)
text = "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/";
var = re.sub("(.)(.?)", decode, text)
print var
HAI
CAN HAS STDIO?
I HAS A MESS ITZ "Doogsauumauipnt >)! Zov qatsfd!ovr!ieipt!fjlues >) Wiau brf zovr!tirfe!fbvprjtf uedhoidam copkt? Pmebsf jndlvdf bt!lfatt!ooe!spfuwbrf fnhioefrjnh copk- uhf ptiess!cbn!bf xhbtfvfr- j.f.- qhzsjct,!mbti,!euc/"
I HAS A NUM ITZ 0
I HAS A TMP
IM IN YR DECODE TIL NUM IZ 206
LOL TMP R NUM IN MAH MESS
BOTH SAEM TMP AN " ", O RLY?
NO WAI
NERFZ TMP!!
OIC
LOL NUM IN MAH MESS R TMP
UPZ NUM!!2
IM OUTTA YR DECODE
VISIBLE MESS
KTHXBYE
Last edited by estabroo; 09-16-2009 at 08:18 AM.
Reason: labeling
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.