recipient = recipient[2:]
return leng + type + swap
+
+# GSM uses a 7-bit code that is not the same as ASCII...
+# -*- coding: utf8 -*-
+gsm = (u"@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?"
+ u"¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑÜ`¿abcdefghijklmnopqrstuvwxyzäöñüà")
+ext = (u"````````````````````^```````````````````{}`````\\````````````[~]`"
+ u"|````````````````````````````````````€``````````````````````````")
+
+# Take a unicode string and produce a byte string for GSM
+def gsm_encode(plaintext):
+ res = ""
+ for c in plaintext:
+ idx = gsm.find(c);
+ if idx != -1:
+ res += chr(idx)
+ continue
+ idx = ext.find(c)
+ if idx != -1:
+ res += chr(27)
+ res += chr(idx)
+ return res
+
def code7(pad, mesg):
# Encode the message as 8 chars in 7 bytes.
# pad with 'pad' 0 bits at the start (low in the byte)
phone_num = encode_number(recipient)
proto = '00' # don't know what this means
encode = '00' # 7 bit ascii
+mesg = gsm_encode(mesg)
if len(mesg) <= 160:
# single SMS mesg
m1 = code7(0,mesg)