Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I was given a task in python to write a 7 bit PDU encoder that accepts a plaintext ascii string and returns a tuple (x,y)
where x is the encoded plaintext formatted as a binary sting with each byte separated with 5 hashes
‘#####’, and y is the hexadecimal representation of the string.

Am just confused about this question,


[EDIT: Moved up here from code below]
I don't know how to make the code to be separated with 5 hashes (#####) and how to make it display both ascii and binary. I appreciate any help from you.

What I have tried:

Python
# -*- coding: utf8 -*-
import binascii
pdu = ("@£$¥èéùìòÇ\nØø\rÅåΔ_ΦΓΛΩΠΨΣΘΞ\x1bÆæßÉ !\"#¤%&'()*+,-./0123456789:;<=>?"
       "¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà")
ext = ("````````````````````^```````````````````{}`````\\````````````[~]`"
       "|````````````````````````````````````€``````````````````````````")

def pdu_encode(m):
    res = ""
    for i in m:
        idx = pdu.find(i);
        if idx != -1:
            res += chr(idx)
            continue
        idx = ext.find(i)
        if idx != -1:
            res += chr(27) + chr(idx)
    return binascii.b2a_hex(res.encode('utf-8'))

print(pdu_encode("Cryptomasses on groove"))
Posted
Updated 27-Mar-22 5:56am
v3
Comments
OriginalGriff 26-Mar-22 11:05am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.
Member 15579881 26-Mar-22 12:09pm    
PLease read the question again, I have provided everything inclusive of the code that I have written. what I am trying to do is to write a 7 bit pdu program that can accept plaintext and produce a hexer and a binary value of it. Am just learning to program. if you can help me thanks but, if you can't help thanks for your response.
OriginalGriff 26-Mar-22 12:31pm    
What you haven't done is tell us what help you need: you have copy'n'pasted your task, copy'n'pasted a chunk of code which doesn;t at first glance appear to have a lot to do with iot, and that's it.

What we don't know is what you expect us to do to help you!
Dave Kreskowiak 26-Mar-22 16:12pm    
"Read the question again?" You never posted a question.

You never described what problem you're having, nor what the code is doing compared to what you expect it to do, ... nothing.

Just posting your homework assignment and a code snippet is not asking a question.
Member 15579881 27-Mar-22 6:34am    
what is your problem? if you want to help please do else, just stop this unnecessary stress because you are pissing me off already. what's that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900