LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (https://www.linuxquestions.org/questions/general-10/)
-   -   Please help me decipher this. (https://www.linuxquestions.org/questions/general-10/please-help-me-decipher-this-754166/)

brianL 09-12-2009 05:32 AM

I thought it was an error message in Klingon:
You have moved the mouse. Windows will now shut down.

XavierP 09-12-2009 06:45 AM

Ah, I have so few words of wisdom that it's nice to have them noticed :)

estabroo 09-12-2009 08:30 AM

Jiml8 good point on the don't subtract from space. Made a few more compact versions just for you :)

Code:

#!/usr/bin/perl

$var = "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/";
@lets = ($var =~ m/(.)/g);

for ($i = 0; $i <= $#lets; $i += 2) {
    next if ($lets[$i] eq " ");
    $lets[$i] = pack('c', unpack('c', $lets[$i])-1);
}

$ans = join('', @lets);
print "$ans\n";

and

Code:

#!/usr/bin/perl

$var = "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 = 0; $i < length($var); $i += 2) {
        next if (substr($var,$i,1) eq " ");
        substr($var, $i, 1, pack('c', unpack('c', substr($var, $i, 1))-1));
}
print "$var\n";

and finally (though this one suffers from the last character not being translated, and won't work in all perls)

Code:

#!/usr/bin/perl

$var = "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 =~ s/(.)(?{ $n = pack('c', unpack('c', $^N)-1); $n = " " if ($n le " ") })(.)/$n$2/g;
print "$var\n";

edit - added this one (just cause that pack/unpack looks ugly)
Code:

#!/usr/bin/perl

$var = "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 =~ s/(.)(?{ $n = chr(ord($^N)-1); $n = " " if ($n le " ") })(.)/$n$2/g;
print "$var\n";


jiml8 09-12-2009 05:32 PM

Well, alright. I can compress mine too. Readability doesn't suffer too much. I do have to declare variables though; compiler won't do it for me on the fly.
Code:

#include <stdio.h>
#include <string.h>
void main()
{
        char 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/",*linestart = data,*lineptr;
        for(lineptr = linestart;lineptr <= linestart + strlen(data);lineptr+=2){if(*lineptr != 0x20) --*lineptr;}
        printf("%s\n",data);
}

Since C doesn't have sophisticated string handling, I don't think I can squeeze much more out of this. Want to run some timing exercises and see which is faster?

estabroo 09-12-2009 05:41 PM

lol, now we just need an erlanger to one-liner it for us :)

jiml8 09-12-2009 05:59 PM

Wow. You posted fast. I updated my code after you posted, without being aware you HAD posted. Shortened it a bit more.

estabroo 09-12-2009 06:28 PM

hehe, I'd bet the C is faster. All of this reminded me of a great programming challenge site, its solving math problems (some of them are even crypto), the basic idea is to write a program in any language that'll solve the problem with a bonus challenge of making it run in under a minute.

http://projecteuler.net/

Kenhelm 09-12-2009 11:02 PM

Using bash and tr
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/'

charset=$(echo -e "$(printf '\\x%x' {33..126})")
for ((n = 0; n < ${#text}; n += 2));do
  echo -n "${text:n:1}" | tr "$charset" " $charset"
  echo -n "${text:n+1:1}"
done

Congratulations =)  You passed our idiot filter =) What are your three favorite technical books? Please include at least one software engineering book, the others can be whatever, i.e., physics, math, etc.


estabroo 09-12-2009 11:18 PM

Got the regex one fixed now, shorter and handles that pesky last character.

Code:

#!/usr/bin/perl

$var = "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 =~ s/([^ ])(?{ $n = chr(ord($^N)-1); })(.?)|( .)(?{ $n = $^N })/$n$2/g;
print "$var\n";


estabroo 09-12-2009 11:24 PM

Wow Kenhelm, very nice, I wouldn't have given bash enough credit to be able to do it.

GrapefruiTgirl 09-13-2009 11:59 AM

Quote:

Originally Posted by Kenhelm (Post 3680627)
Using bash and tr
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/'

charset=$(echo -e "$(printf '\\x%x' {33..126})")
for ((n = 0; n < ${#text}; n += 2));do
  echo -n "${text:n:1}" | tr "$charset" " $charset"
  echo -n "${text:n+1:1}"
done

Congratulations =)  You passed our idiot filter =) What are your three favorite technical books? Please include at least one software engineering book, the others can be whatever, i.e., physics, math, etc.


Dang ;) you beat me to it! I was going to give it a shot in bash (and likely still will, so I'm not peeking at how you did it) but nice job! Bash is the language I'm currently most able with -- I'm not much for C, perl, python, etc..

I have a couple ideas to try out.. This kind of stuff keeps the brain fresh & juicy :p

I think it'd be cool to see this in Lisp too, if that can be done. Any takers?

Sasha

jiml8 09-13-2009 01:14 PM

And, in PHP:
Code:

#!/usr/bin/php
<?php
$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/";
for($ii=0;$ii<strlen($data);$ii+=2){if($data[$ii]<>" ")$data[$ii] = chr(ord($data[$ii]) - 1);}
echo $data."\n";
?>

You do need to have the command line php interpreter installed for this one. I could also make this one obscure by using regex's. Maybe I will.

edit: Here is the regexp version in PHP.
Code:

#!/usr/bin/php
<?php
$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/";
echo preg_replace("((.)(.)?)e" ,"(\"\\1\" != \" \")?chr(ord('\\1') - 1).'\\2':'\\1\\2'", $data)."\n";
?>

And this regexp does handle that pesky last character.

GrapefruiTgirl 09-13-2009 11:31 PM

bash + awk solution
 
Ok! While I'm semi-impressed with what I have come up with (because it's the first time I've ever used awk for anything), it has a bug.

Here's the code:

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$(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 "$output"

..and here's the output (note the two ÿ characters which I have no clue why they are appearing -- but I'm working on it.) :scratch:

Code:

bash-3.1$ sh decode
Congratulations =)  You passed our idiot filter =)ÿWhat are your three favorite technical books?ÿPlease include at least one software engineering book, the others can be whatever, i.e., physics, math, etc.
bash-3.1$


jiml8 09-14-2009 01:51 AM

Anyone want to do it in Fortran? I might try; I used to program a LOT of Fortran, but the last time I did was in about 1990 and I have never programmed for the gnu fortran compiler. Might be awhile before it is running.

We also need someone to step up and do it in python. And there was a request for lisp.

While we're at it, is Modula still in use? Pascal? Forth?

estabroo 09-14-2009 08:47 AM

Here is a python one (far from optimal)

Code:

#!/usr/bin/python

import re

def decode(m):
        a = m.group(0)
        if (len(a) == 2):
                a = m.group(1)
                b = m.group(2)
        else:
                b = ""
        if (a != " "):
                a = chr(ord(a)-1)
        return a + b


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

GrapefruiTGirl - the problem your seeing is the subtract from space issue


All times are GMT -5. The time now is 01:16 AM.