LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > General
User Name
Password
General This forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!

Notices


Reply
  Search this Thread
Old 09-14-2009, 09:31 AM   #46
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556

Quote:
Originally Posted by estabroo View Post
GrapefruiTGirl - the problem your seeing is the subtract from space issue
Awesome!! THANK YOU!

Here's the corrected version, which does not substract from space (and also, likely NOT optimized to the max):

Code:
#!/bin/bash
data="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=0; leng=$(($(echo "$data" | awk '{ if (length($0) > len) len = length($0) } END { print len }')))
while ((i <= $leng)); do
output="$output$( [ "${data:$((i)):1}" = " " ] && echo -n " " || echo $(($(printf %d "'$(echo ${data:$((i)):1} | gawk '{ printf("%c",int($0)); } {print}')")-1)) | gawk '{ printf("%c",$0); }')${data:$((i+1)):1}"
i=$((i+2))
done
echo -e "$output"
 
Old 09-14-2009, 10:23 AM   #47
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
and lua

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/"

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
 
Old 09-14-2009, 03:20 PM   #48
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
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!

Code:
      CHARACTER DATA*205,DATA2*205,OUT
      CHARACTER DATARR(205),DATOUT(205)
      INTEGER*1 OUTVAL
      EQUIVALENCE (OUTVAL,OUT),(DATA2,DATARR(1))
      PARAMETER (DATA='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/')
      DATA2=DATA
      J=1
      DO 100 I=1,205,1
      OUT=DATARR(I)
      GOTO(10,20),J
10    OUTVAL=OUTVAL-1
      J=2
      GOTO 30
20    J=1
30    CONTINUE
      DATOUT(I) = OUT
100   CONTINUE
      PRINT 200, DATOUT
200   FORMAT(205A)
      END
edit: I was just looking at this, and my last compiled version in C is 6780 bytes. This fortran is 11320 bytes.

edit: Shortened version; all GOTOs are removed and more efficient storage utilization:
Code:
       CHARACTER DATA*205,DATA2*205
      INTEGER*1 OUTVAL(205)
      EQUIVALENCE (DATA2,OUTVAL(1))
      PARAMETER (DATA='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/')
      DATA2=DATA;
      DO 100 I=1,205,2
      IF(OUTVAL(I) .NE. Z'20') OUTVAL(I)=OUTVAL(I)-1
100   CONTINUE
      PRINT 200, DATA2
200   FORMAT(A)
      END

Last edited by jiml8; 09-14-2009 at 06:00 PM.
 
Old 09-14-2009, 05:34 PM   #49
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
Using GNU sed
Code:
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/'
chars='!"#$%&'\''()*+,-.\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'

echo "$text" |
sed 's/./&\n/g' | sed -n "1~2 y/$chars\a/ $chars/;H;$ {g;s/\n//g;p}"
'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.
Code:
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/'
chars='!"#$%&'\''()*+,-.\/0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'

echo "$text" |
grep -o '.' | sed "1~2 y/$chars\a/ $chars/" | tr -d '\n'
 
Old 09-14-2009, 06:18 PM   #50
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by estabroo View Post

or (this one doesn't handle that last pesky character)
But this one does:
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)
 
Old 09-14-2009, 06:46 PM   #51
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
What a bunch of clever cookies we have around here

Hmm.. Where's that Lisp script
 
Old 09-14-2009, 07:06 PM   #52
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Sasha, we're leaving the lisp to you
 
Old 09-14-2009, 08:46 PM   #53
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556


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.
 
Old 09-14-2009, 09:53 PM   #54
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Jiml8 - excellent, thanks for fixing that regex for me
 
Old 09-15-2009, 03:00 PM   #55
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
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

Last edited by estabroo; 09-15-2009 at 03:02 PM.
 
Old 09-15-2009, 04:14 PM   #56
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,298
Blog Entries: 61

Rep: Reputation: Disabled
OK, smartarses, what about Brainf**k?
Or LOLcode??
 
Old 09-15-2009, 04:38 PM   #57
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by brianL View Post
OK, smartarses, what about Brainf**k?
Or LOLcode??
You now have your assignment.
 
Old 09-15-2009, 05:01 PM   #58
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,298
Blog Entries: 61

Rep: Reputation: Disabled
Oh Noooooooooo!!! I know nothing about programming...I'm less than a newbie...I can't do it....HELP!!!
 
Old 09-15-2009, 07:20 PM   #59
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
I'm truly sorry but I just couldn't resist

LOLcode

Code:
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
 
Old 09-15-2009, 07:44 PM   #60
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware64 15; SlackwareARM-current (aarch64); Debian 12
Posts: 8,298
Blog Entries: 61

Rep: Reputation: Disabled
U r 1337!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A little instability in my Slackware, Need to decipher these errors BobNutfield Slackware 13 08-20-2008 10:02 AM
Can Someone help me to decipher this error? randell6564 Ubuntu 2 10-15-2006 04:20 PM
How to decipher this C declaration? CM019 Programming 6 05-28-2006 06:01 PM
Can anyone decipher my K3b error message? Trinity22 Linux - Software 3 04-21-2004 09:01 PM
Try to decipher this :) Whitehat General 42 06-29-2003 06:42 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > General

All times are GMT -5. The time now is 07:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration