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

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

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