Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

tinychallenge of /prague/: the UNIX way of sending SMS

Name: Anonymous 2017-11-15 16:32

so, instead of being all talk and no action, let's ram some progs.

Background:

at work, I once had to create an ancient 7-bit packed PDU from an ASCII string. in doing that, I've noticed that my solution is fairly verbose and inelegant despite the fact that the task itself is quite simple. this might be because I'm an idiot.

I've also noticed that creating PDUs and passing them to a function is not the way of UNIX (or the way of a mental midget, depending on whomst'd've you ask): my function operated on binary data! who needs that when you have stdin and stdout?

Your task:

ASCII might be a 7-bit encoding but GSM-7 is 7-bitter!

you have to create a complete program in your language of choice (it has to have a free as in beer implementation available, and it should preferably not be a meme language that stack overflow golfers like to invent to game the rules) that takes ASCII (no need to handle EASCII, UTF-8 etc.; actually being hillariously incompatible with them would be a plus) string as input and converts it to the GSM 7-bit packed alphabet, as defined here: http://holman.id.au/apps/ipsms/default_alphabet.html

you can use 'USSD Entry/Display' on this site for testing: http://smstools3.kekekasvi.com/topic.php?id=288

Additional rules:

1. input must be taken from stdin and output must be printed to stdout.
2. the actual format of your output doesn't matter much as long as it's unambigous: for HAX MY ANUS on stdin, C82016D4CC8282CEEA3404 is accepted but so is 0xc8 0x20 0x16 0xd4 0xcc 0x82 0x82 0xce 0xea 0x34 0x04, yCAW1MyCgs7qNAQ= and just fucking printing the raw bytes (if your output format is not obvious, clarify it).
3. don't create PDUs or anything like that, just convert between alphabets; imagine it as just one part of a UNIXy SMS pipeline
4. if the language your using is not obvious (due to either obscurity or similarity to other languages), make sure to mention which one it is: you don't want your Hy submission to be rejected because it looked like Clojure but didn't work like Clojure. feel free to brag about your program being a polyglot.
5. shortest code in bytes of either source code or machine code (whichever is better - so feel free to use assembly) wins
6. all submissions until 2017-11-22 16:30 UTC will be counted. good submissions past that deadline but before results are announced might get an honorable mention.

Name: Anonymous 2017-11-15 18:48

How is this useful tho

Name: Anonymous 2017-11-15 19:16

tl;dr lol

Name: Anonymous 2017-11-15 21:34

Nice!
bampu pantsu for more challenges, I will take a look when i'm not shitfaced as fuck

Name: Anonymous 2017-11-15 23:18

I request an extension of the deadline as I won't have winter vacations until the 2nd of December.

Name: Cudder !cXCudderUE 2017-11-16 3:42

Name: Anonymous 2017-11-16 4:34

>>1
The second link you provided gives C82016D4CC8282CEEA14 for "HAX MY ANUS". I think your last two bytes are incorrect, unless I misunderstood the problem. Anyways here's my entry.

All feedback is welcome!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CONVERT_LEN(n) (7*(n)/8+1)

char *convert(const char* ascii, int length) {
char *result = calloc(CONVERT_LEN(length), 1);
for(int i = 0; i < length; i++) {
result[7*i/8] |= (ascii[i] << (7*i%8)) & 0xFF;
result[7*i/8+1] |= ascii[i] >> (8-(7*i%8));
}
return result;
}

int main() {
char *s = "HAX MY ANUS";
char *p = convert(s, strlen(s));
for(int i = 0; i < CONVERT_LEN(strlen(s)); i++) {
printf("0x%hhx ", p[i]);
}
printf("\n");
free(p);
}

Name: Anonymous 2017-11-16 7:38

first times are hard! I'll have to give more thought to those challenges in the future but right now I'm going to error on the side of resolving difficulties in favor of challenge takers so that nobody gets screwed because of my incompetence

>>5
I'm sorry Anon, I can't do that. I know it seems to contradict what I said in the spoiler but this is an exception: by that time this thread will slide out of the front page and/or be turned into shitposting central. but I'll try figuring out more challenges by the time you have more free time!

>>6
I screwed up by giving 'storyline' for SMS packing but a testing tool which gives you USSD, so I say USSD is preferable for easier testing but SMS is fine too, I'll accept both.

thanks for spec, Cudder!
>>7
you're right, I provided ASCII for HAX MY ANUS and GSM-7 for HAX MY ANUS!. my bad.

as for your solution, you should take input from stdin instead of hardcoding it. also, you'd better golf this down to stay competitive!

Name: Anonymous 2017-11-16 8:45

FIOC3 solution (based on >>7-kun's), prints out a list (in brackets) of bytes (formatted as decimals, not hexes):

a=input();b=len(a);c=range;d=lambda x:7*x//8;e=[0 for x in c(d(b)+1)]
for i in c(b):
e[d(i)]|=(ord(a[i])<<(7*i%8))&0xff
e[d(i+1)]|=(ord(a[i]))>>(8-(7*i%8))
print(e)


thought it might be shorter in FIOC2 but raw_input() fucks it up (default input() starts misbehaving when it encounters valid ASCII chars with special meaning in the language - like backslashes, quotes etc.}.

also thought it might be shorter in Hy but having to use (get) and (assoc) for accessing list at index fuck it up (might be doable in a Lispier way but I haven't figured it out yet).

Name: Anonymous 2017-11-16 9:19

>>9
Replace 0xff with 255 to save one byte:
a=input();b=len(a);c=range;d=lambda x:7*x//8;e=[0 for x in c(d(b)+1)]
for i in c(b):
e[d(i)]|=(ord(a[i])<<(7*i%8))&255
e[d(i+1)]|=(ord(a[i]))>>(8-(7*i%8))
print(e)

Name: Anonymous 2017-11-16 9:34

>>9,10
with the power of those dubs, I think this is the hardest I can golf it:

a=input();b=len(a);c=range;d=lambda x:7*x//8;e=[0 for x in c(d(b)+1)]
for i in c(b):
e[d(i)]|=ord(a[i])<<7*i%8&255
e[d(i+1)]|=ord(a[i])>>8-7*i%8
print(e)


lel /prog/ thinks I'm referring to posts in the code

Name: Cudder !cXCudderUE 2017-11-16 12:08

All the entries so far fail to encode all of the printable ASCII range.

Expected: @[\]^_`{|}~
Observed: ¡ÄÖÑܧ¿äöñü

Also, none of them do correct CR-padding either.

Name: Anonymous 2017-11-16 15:38

>Observed
What shitty encoding are you using?

Name: Anonymous 2017-11-16 15:38

Observed: ¡ÄÖÑܧ¿äöñü
What shitty encoding are you using?

Please ignore my previous post.

Name: Anonymous 2017-11-16 20:22

>Cudder literally obsessed with ÄÑܧ

color me surprised

Name: Anonymous 2017-11-16 20:23

>>15
Whom are you quoting?

Name: Anonymous 2017-11-16 20:27

>>16
>he thinks ">" is a quote
go back to reddit newfag

Name: Anonymous 2017-11-16 22:06

>>17
https://en.wikipedia.org/w/index.php?title=Greater-than_sign&oldid=810629328#Hyphen-minus_with_greater-than_sign
Electronic mail
The greater-than sign is used to denote quotations in the e-mail and newsgroup formats, and this has been taken into use also in forums.

$fag

Back to 4chan, please.

Name: Anonymous 2017-11-16 22:58

>>18
plonk

Name: Anonymous 2017-11-16 23:05

>>18
allo dog, it's tinychan here not usenet
same chan culture

Name: Anonymous 2017-11-16 23:36

>>18
And whom might you be quoting, sir?

Name: Anonymous 2017-11-16 23:48

>>21
He clearly quoted from the linked article.

Name: Anonymous 2017-11-16 23:56

>>22
Most certainly, but whom is he quoting?

Name: Anonymous 2017-11-16 23:59

>>23
A quotable source.

Name: Anonymous 2017-11-17 0:01

>>24
And what makes a source quotable? Do you have any references? I don't see any quotes in your post.

Name: Anonymous 2017-11-17 0:16

>>26
No I need him to tell me whom he is quoting. I'm not going to find out myself.

Name: Cudder !cXCudderUE 2017-11-17 2:54

>>13,14
RTFS - section 6.2.1.

Name: Anonymous 2017-11-17 8:30

>>12
while you're right, I've also noticed that you failed to provide a solution that does encode the whole ASCII range. thus, I must conclude: Cudder is all talk and no action!

Name: Cudder !cXCudderUE 2017-11-17 12:30

>>29
It's coming.

Name: Anonymous 2017-11-18 0:10

I once had to create an ancient 7-bit packed PDU from an ASCII string.
Why did you have to create it?

Name: Anonymous 2017-11-18 0:27

Text standards are sometimes pretty bad.

Name: Anonymous 2017-11-18 3:43

>>30
I'm coming too Cudder

Name: Anonymous 2017-11-20 2:32

Almost 3 days left!

Name: Anonymous 2017-11-20 3:25

I need to come inside the Cudder

Name: Anonymous 2017-11-20 7:37

>>32
I do offensive security/vulnerability assesment/hacking shit on phones. draw your own conclusions

Name: Anonymous 2017-11-21 8:11

Cudder is all talk and no action!

Name: Anonymous 2017-11-21 9:12

WHERES YOUR APP CUDDER????
EEEEEEEEH EEEEEEEEEH EEEEEEEEEEH EEEEEEEEEH!!

Name: Anonymous 2017-11-21 9:31

where is your game Nikita?
where is your game FrozenAnus?
where is your browser Cudder?

russians=lazy bydlos

Name: Cudder !cXCudderUE 2017-11-21 10:07

>>39
Right here.
#include <stdio.h>
#include <string.h>
int a,i=0;char x[]="$\x2@\x1[\xac<\xaf]\xbe^\x94_\x11{\xa8|\xc0}\xa9~\xbd",c;
e(int c){if(i){putchar(a|=c<<i--);a>>=8;}else{a=c;i=7;}}
main(){while((c=getchar())!=EOF){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);
e(*p&127);}else{e(c);}}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}

Name: Anonymous 2017-11-21 10:31

>>41
looks good

Name: Anonymous 2017-11-21 22:02

>>41
main()
ya ain't read da standard

Name: Anonymous 2017-11-22 7:11

>>43
code golf challenges aren't about da standard, they often exploit implementation-specific shit, undefined behavior and my dubs

Name: Anonymous 2017-11-22 7:16

>>43
That's C89.

Name: Anonymous 2017-11-22 10:14

py3, significantly longer than >>11 (and slightly shorter than >>41, but it's a given with py vs C) but it should handle all ASCII. might be possible to reduce size further but I'm out of ideas. output is binary digits, divided by newlines into octets

a=0x1b;b={'@':0,'$':2,'\n':10,'_':17};c={'\f':[a,10],'^':[a,20],'{':[a,40],'}':[a,41],'\\':[a,47],'[':[a,60],'~':[a,61],']':[a,62],'|':[a,64]};d="";e=[y for x in input() for y in (c[x] if x in c else [b[x]] if x in b else [ord(x)])]
for x in e:d+=format(x,'07b')[::-1]
for i in range(0,len(d),8):print(d[i:i+8][::-1])

Name: Cudder !cXCudderUE 2017-11-22 12:05

>>46
output is binary digits, divided by newlines into octets
That follows the rules, but still lame because the output isn't actually directly usable.

but it's a given with py vs C

...but I beat it anyway. Yours is 317 bytes, mine is 247 bytes:

int a,i;char x[]="$[¼\¯]¾^”_{¨|À}©~½`{@",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}

Name: Anonymous 2017-11-22 12:17

>>47
as for the solution you posted goes, I'm not sure it really works:

$ gcc cudder_sms.c
cudder_sms.c:1:18: warning: unknown escape sequence: '\302' [enabled by default]
int a,i;char x[]="$[¼\¯]¾^”_{¨|À}©~½`{@",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}
^
cudder_sms.c: In function ‘main’:
cudder_sms.c:1:149: warning: incompatible implicit declaration of built-in function ‘strchr’ [enabled by default]
int a,i;char x[]="$[¼\¯]¾^”_{¨|À}©~½`{@",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}

$ ./a.out > lel
[$ xxd lel
0000000: 1b21 .!

correct me if I'm wrong but shouldn't the output for a single open bracket be 1b1e instead of 1b21?

Name: Cudder !cXCudderUE 2017-11-22 12:24

>>48
The encoding should be CP1252, which got fucked up somewhere along the way from the file to that post. The characters of the string constant in the source should be

24 02 5B BC 5C 5C AF 5D BE 5E 94 5F 11 7B A8 7C C0 7D A9 7E BD 60 7B 40

Name: Anonymous 2017-11-22 12:34

>>49
$ gcc cudder_sms.c
cudder_sms.c: In function ‘main’:
cudder_sms.c:1:214: warning: incompatible implicit declaration of built-in function ‘strchr’ [enabled by default]
int a,i;char x[]="\x24\x02\x5b\xbc\x5c\x5c\xaf\x5d\xbe\x5e\x94\x5f\x11\x7b\xa8\x7c\xc0\x7d\xa9\x7e\xbd\x60\x7b\x40",c;e(int c){if(i)putchar(a|=c<<i--),a>>=8;else a=c,i=7;}main(){while((c=getchar())>0){char*p;if(p=strchr(x,c)){if(*++p&128)e(27);e(*p&127);}else e(c);}if(i==1)a|=26;putchar(a);if(!i&&a/2==13)putchar(13);}
^
$ ./a.out > lel
[$ xxd lel
0000000: 1b1e ..

looks good now

Name: Anonymous 2017-11-22 16:40

OFFICIAL RESULTS:

the winner is... Cudder! >>47

Congratulations on not being all talk an no action!

second place: >>46

third place: nobody because only Cudder and >>46-kun posted something that fits the requirements

Name: Anonymous 2017-11-22 19:45

I printed mine but the stupid paper doesn't want to weld together properly, so I couldn't send it.

Name: Anonymous 2017-11-22 22:12

Good job Cudder-kun!

Name: Anonymous 2017-11-23 7:43

it was fun. if anyone (Cudder? >>46-kun? >>9-kun? >>7-kun?) is interested, I'm going to make a new tinychallenge soon (maybe during the weekend?). this time the task would be a bit more complex so I'd give a bit longer submission period - but still nothing you won't be able to write in an hour or two.

Name: Anonymous 2017-11-23 14:20

>>54
it was fun
No it wasn't
This was a project euler tier problem that has no real life use

Name: Anonymous 2017-11-23 14:43

>>55
watch out, we have an ENTERPRISE programmer here!

Don't change these.
Name: Email:
Entire Thread Thread List