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-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])

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